]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/objectstore/FileStoreTracker.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / objectstore / FileStoreTracker.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2
3 #ifndef FILESTORE_TRACKER_H
4 #define FILESTORE_TRACKER_H
5 #include "test/common/ObjectContents.h"
6 #include "os/filestore/FileStore.h"
7 #include "kv/KeyValueDB.h"
8 #include <boost/scoped_ptr.hpp>
9 #include <list>
10 #include <map>
11 #include "common/Mutex.h"
12
13 class FileStoreTracker {
14 const static uint64_t SIZE = 4 * 1024;
15 ObjectStore *store;
16 KeyValueDB *db;
17 Mutex lock;
18 uint64_t restart_seq;
19
20 struct OutTransaction {
21 list<pair<pair<coll_t, string>, uint64_t> > *in_flight;
22 ObjectStore::Transaction *t;
23 };
24 public:
25 FileStoreTracker(ObjectStore *store, KeyValueDB *db)
26 : store(store), db(db),
27 lock("Tracker Lock"), restart_seq(0) {}
28
29 class Transaction {
30 class Op {
31 public:
32 virtual void operator()(FileStoreTracker *harness,
33 OutTransaction *out) = 0;
34 virtual ~Op() {};
35 };
36 list<Op*> ops;
37 class Write : public Op {
38 public:
39 coll_t coll;
40 string oid;
41 Write(const coll_t &coll,
42 const string &oid)
43 : coll(coll), oid(oid) {}
44 void operator()(FileStoreTracker *harness,
45 OutTransaction *out) override {
46 harness->write(make_pair(coll, oid), out);
47 }
48 };
49 class CloneRange : public Op {
50 public:
51 coll_t coll;
52 string from;
53 string to;
54 CloneRange(const coll_t &coll,
55 const string &from,
56 const string &to)
57 : coll(coll), from(from), to(to) {}
58 void operator()(FileStoreTracker *harness,
59 OutTransaction *out) override {
60 harness->clone_range(make_pair(coll, from), make_pair(coll, to),
61 out);
62 }
63 };
64 class Clone : public Op {
65 public:
66 coll_t coll;
67 string from;
68 string to;
69 Clone(const coll_t &coll,
70 const string &from,
71 const string &to)
72 : coll(coll), from(from), to(to) {}
73 void operator()(FileStoreTracker *harness,
74 OutTransaction *out) override {
75 harness->clone(make_pair(coll, from), make_pair(coll, to),
76 out);
77 }
78 };
79 class Remove: public Op {
80 public:
81 coll_t coll;
82 string obj;
83 Remove(const coll_t &coll,
84 const string &obj)
85 : coll(coll), obj(obj) {}
86 void operator()(FileStoreTracker *harness,
87 OutTransaction *out) override {
88 harness->remove(make_pair(coll, obj),
89 out);
90 }
91 };
92 public:
93 void write(const coll_t &coll, const string &oid) {
94 ops.push_back(new Write(coll, oid));
95 }
96 void clone_range(const coll_t &coll, const string &from,
97 const string &to) {
98 ops.push_back(new CloneRange(coll, from, to));
99 }
100 void clone(const coll_t &coll, const string &from,
101 const string &to) {
102 ops.push_back(new Clone(coll, from, to));
103 }
104 void remove(const coll_t &coll, const string &oid) {
105 ops.push_back(new Remove(coll, oid));
106 }
107 friend class FileStoreTracker;
108 };
109
110 int init();
111 void submit_transaction(Transaction &t);
112 void verify(const coll_t &coll,
113 const string &from,
114 bool on_start = false);
115
116 private:
117 ObjectContents get_current_content(const pair<coll_t, string> &obj);
118 pair<uint64_t, uint64_t> get_valid_reads(const pair<coll_t, string> &obj);
119 ObjectContents get_content(const pair<coll_t, string> &obj, uint64_t version);
120
121 void committed(const pair<coll_t, string> &obj, uint64_t seq);
122 void applied(const pair<coll_t, string> &obj, uint64_t seq);
123 uint64_t set_content(const pair<coll_t, string> &obj, ObjectContents &content);
124
125 // ObjectContents Operations
126 void write(const pair<coll_t, string> &obj, OutTransaction *out);
127 void remove(const pair<coll_t, string> &obj, OutTransaction *out);
128 void clone_range(const pair<coll_t, string> &from,
129 const pair<coll_t, string> &to,
130 OutTransaction *out);
131 void clone(const pair<coll_t, string> &from,
132 const pair<coll_t, string> &to,
133 OutTransaction *out);
134 friend class OnApplied;
135 friend class OnCommitted;
136 };
137
138 #endif