]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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> | |
9f95a23c | 11 | #include "common/ceph_mutex.h" |
7c673cae FG |
12 | |
13 | class FileStoreTracker { | |
14 | const static uint64_t SIZE = 4 * 1024; | |
15 | ObjectStore *store; | |
16 | KeyValueDB *db; | |
9f95a23c | 17 | ceph::mutex lock = ceph::make_mutex("Tracker Lock"); |
7c673cae FG |
18 | uint64_t restart_seq; |
19 | ||
20 | struct OutTransaction { | |
20effc67 | 21 | std::list<std::pair<std::pair<coll_t, std::string>, uint64_t> > *in_flight; |
7c673cae FG |
22 | ObjectStore::Transaction *t; |
23 | }; | |
24 | public: | |
25 | FileStoreTracker(ObjectStore *store, KeyValueDB *db) | |
26 | : store(store), db(db), | |
9f95a23c | 27 | restart_seq(0) {} |
7c673cae FG |
28 | |
29 | class Transaction { | |
30 | class Op { | |
31 | public: | |
32 | virtual void operator()(FileStoreTracker *harness, | |
33 | OutTransaction *out) = 0; | |
34 | virtual ~Op() {}; | |
35 | }; | |
20effc67 | 36 | std::list<Op*> ops; |
7c673cae FG |
37 | class Write : public Op { |
38 | public: | |
39 | coll_t coll; | |
20effc67 | 40 | std::string oid; |
7c673cae | 41 | Write(const coll_t &coll, |
20effc67 | 42 | const std::string &oid) |
7c673cae FG |
43 | : coll(coll), oid(oid) {} |
44 | void operator()(FileStoreTracker *harness, | |
45 | OutTransaction *out) override { | |
20effc67 | 46 | harness->write(std::make_pair(coll, oid), out); |
7c673cae FG |
47 | } |
48 | }; | |
49 | class CloneRange : public Op { | |
50 | public: | |
51 | coll_t coll; | |
20effc67 TL |
52 | std::string from; |
53 | std::string to; | |
7c673cae | 54 | CloneRange(const coll_t &coll, |
20effc67 TL |
55 | const std::string &from, |
56 | const std::string &to) | |
7c673cae FG |
57 | : coll(coll), from(from), to(to) {} |
58 | void operator()(FileStoreTracker *harness, | |
59 | OutTransaction *out) override { | |
20effc67 TL |
60 | harness->clone_range(std::make_pair(coll, from), |
61 | std::make_pair(coll, to), | |
7c673cae FG |
62 | out); |
63 | } | |
64 | }; | |
65 | class Clone : public Op { | |
66 | public: | |
67 | coll_t coll; | |
20effc67 TL |
68 | std::string from; |
69 | std::string to; | |
7c673cae | 70 | Clone(const coll_t &coll, |
20effc67 TL |
71 | const std::string &from, |
72 | const std::string &to) | |
7c673cae FG |
73 | : coll(coll), from(from), to(to) {} |
74 | void operator()(FileStoreTracker *harness, | |
75 | OutTransaction *out) override { | |
20effc67 TL |
76 | harness->clone(std::make_pair(coll, from), |
77 | std::make_pair(coll, to), | |
78 | out); | |
7c673cae FG |
79 | } |
80 | }; | |
81 | class Remove: public Op { | |
82 | public: | |
83 | coll_t coll; | |
20effc67 | 84 | std::string obj; |
7c673cae | 85 | Remove(const coll_t &coll, |
20effc67 | 86 | const std::string &obj) |
7c673cae FG |
87 | : coll(coll), obj(obj) {} |
88 | void operator()(FileStoreTracker *harness, | |
89 | OutTransaction *out) override { | |
20effc67 | 90 | harness->remove(std::make_pair(coll, obj), |
7c673cae FG |
91 | out); |
92 | } | |
93 | }; | |
94 | public: | |
20effc67 | 95 | void write(const coll_t &coll, const std::string &oid) { |
7c673cae FG |
96 | ops.push_back(new Write(coll, oid)); |
97 | } | |
20effc67 TL |
98 | void clone_range(const coll_t &coll, const std::string &from, |
99 | const std::string &to) { | |
7c673cae FG |
100 | ops.push_back(new CloneRange(coll, from, to)); |
101 | } | |
20effc67 TL |
102 | void clone(const coll_t &coll, const std::string &from, |
103 | const std::string &to) { | |
7c673cae FG |
104 | ops.push_back(new Clone(coll, from, to)); |
105 | } | |
20effc67 | 106 | void remove(const coll_t &coll, const std::string &oid) { |
7c673cae FG |
107 | ops.push_back(new Remove(coll, oid)); |
108 | } | |
109 | friend class FileStoreTracker; | |
110 | }; | |
111 | ||
112 | int init(); | |
113 | void submit_transaction(Transaction &t); | |
114 | void verify(const coll_t &coll, | |
20effc67 | 115 | const std::string &from, |
7c673cae FG |
116 | bool on_start = false); |
117 | ||
118 | private: | |
20effc67 TL |
119 | ObjectContents get_current_content(const std::pair<coll_t, std::string> &obj); |
120 | std::pair<uint64_t, uint64_t> get_valid_reads(const std::pair<coll_t, std::string> &obj); | |
121 | ObjectContents get_content(const std::pair<coll_t, std::string> &obj, uint64_t version); | |
7c673cae | 122 | |
20effc67 TL |
123 | void committed(const std::pair<coll_t, std::string> &obj, uint64_t seq); |
124 | void applied(const std::pair<coll_t, std::string> &obj, uint64_t seq); | |
125 | uint64_t set_content(const std::pair<coll_t, std::string> &obj, ObjectContents &content); | |
7c673cae FG |
126 | |
127 | // ObjectContents Operations | |
20effc67 TL |
128 | void write(const std::pair<coll_t, std::string> &obj, OutTransaction *out); |
129 | void remove(const std::pair<coll_t, std::string> &obj, OutTransaction *out); | |
130 | void clone_range(const std::pair<coll_t, std::string> &from, | |
131 | const std::pair<coll_t, std::string> &to, | |
7c673cae | 132 | OutTransaction *out); |
20effc67 TL |
133 | void clone(const std::pair<coll_t, std::string> &from, |
134 | const std::pair<coll_t, std::string> &to, | |
7c673cae FG |
135 | OutTransaction *out); |
136 | friend class OnApplied; | |
137 | friend class OnCommitted; | |
138 | }; | |
139 | ||
140 | #endif |