]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
11fdf7f2 | 3 | |
7c673cae FG |
4 | #ifndef CEPH_RGW_SYNC_MODULE_H |
5 | #define CEPH_RGW_SYNC_MODULE_H | |
6 | ||
7 | #include "rgw_common.h" | |
8 | #include "rgw_coroutine.h" | |
9 | ||
10 | class RGWBucketInfo; | |
11 | class RGWRemoteDataLog; | |
9f95a23c | 12 | struct RGWDataSyncCtx; |
7c673cae FG |
13 | struct RGWDataSyncEnv; |
14 | struct rgw_bucket_entry_owner; | |
15 | struct rgw_obj_key; | |
9f95a23c | 16 | struct rgw_bucket_sync_pipe; |
7c673cae FG |
17 | |
18 | ||
19 | class RGWDataSyncModule { | |
20 | public: | |
21 | RGWDataSyncModule() {} | |
22 | virtual ~RGWDataSyncModule() {} | |
23 | ||
9f95a23c | 24 | virtual void init(RGWDataSyncCtx *sync_env, uint64_t instance_id) {} |
31f18b77 | 25 | |
20effc67 | 26 | virtual RGWCoroutine *init_sync(const DoutPrefixProvider *dpp, RGWDataSyncCtx *sc) { |
31f18b77 FG |
27 | return nullptr; |
28 | } | |
29 | ||
20effc67 | 30 | virtual RGWCoroutine *start_sync(const DoutPrefixProvider *dpp, RGWDataSyncCtx *sc) { |
11fdf7f2 TL |
31 | return nullptr; |
32 | } | |
20effc67 TL |
33 | virtual RGWCoroutine *sync_object(const DoutPrefixProvider *dpp, RGWDataSyncCtx *sc, rgw_bucket_sync_pipe& sync_pipe, rgw_obj_key& key, std::optional<uint64_t> versioned_epoch, rgw_zone_set *zones_trace) = 0; |
34 | virtual RGWCoroutine *remove_object(const DoutPrefixProvider *dpp, RGWDataSyncCtx *sc, rgw_bucket_sync_pipe& bucket_info, rgw_obj_key& key, real_time& mtime, | |
31f18b77 | 35 | bool versioned, uint64_t versioned_epoch, rgw_zone_set *zones_trace) = 0; |
20effc67 | 36 | virtual RGWCoroutine *create_delete_marker(const DoutPrefixProvider *dpp, RGWDataSyncCtx *sc, rgw_bucket_sync_pipe& bucket_info, rgw_obj_key& key, real_time& mtime, |
31f18b77 | 37 | rgw_bucket_entry_owner& owner, bool versioned, uint64_t versioned_epoch, rgw_zone_set *zones_trace) = 0; |
7c673cae FG |
38 | }; |
39 | ||
31f18b77 | 40 | class RGWRESTMgr; |
11fdf7f2 | 41 | class RGWMetadataHandler; |
9f95a23c | 42 | class RGWBucketInstanceMetadataHandlerBase; |
31f18b77 | 43 | |
7c673cae FG |
44 | class RGWSyncModuleInstance { |
45 | public: | |
46 | RGWSyncModuleInstance() {} | |
47 | virtual ~RGWSyncModuleInstance() {} | |
48 | virtual RGWDataSyncModule *get_data_handler() = 0; | |
31f18b77 FG |
49 | virtual RGWRESTMgr *get_rest_filter(int dialect, RGWRESTMgr *orig) { |
50 | return orig; | |
51 | } | |
11fdf7f2 TL |
52 | virtual bool supports_user_writes() { |
53 | return false; | |
54 | } | |
55 | virtual RGWMetadataHandler *alloc_bucket_meta_handler(); | |
9f95a23c | 56 | virtual RGWBucketInstanceMetadataHandlerBase *alloc_bucket_instance_meta_handler(); |
eafe8130 TL |
57 | |
58 | // indication whether the sync module start with full sync (default behavior) | |
59 | // incremental sync would follow anyway | |
60 | virtual bool should_full_sync() const { | |
61 | return true; | |
62 | } | |
7c673cae FG |
63 | }; |
64 | ||
65 | typedef std::shared_ptr<RGWSyncModuleInstance> RGWSyncModuleInstanceRef; | |
66 | ||
11fdf7f2 TL |
67 | class JSONFormattable; |
68 | ||
7c673cae FG |
69 | class RGWSyncModule { |
70 | ||
71 | public: | |
72 | RGWSyncModule() {} | |
73 | virtual ~RGWSyncModule() {} | |
74 | ||
11fdf7f2 TL |
75 | virtual bool supports_writes() { |
76 | return false; | |
77 | } | |
7c673cae | 78 | virtual bool supports_data_export() = 0; |
20effc67 | 79 | virtual int create_instance(const DoutPrefixProvider *dpp, CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) = 0; |
7c673cae FG |
80 | }; |
81 | ||
82 | typedef std::shared_ptr<RGWSyncModule> RGWSyncModuleRef; | |
83 | ||
84 | ||
85 | class RGWSyncModulesManager { | |
9f95a23c | 86 | ceph::mutex lock = ceph::make_mutex("RGWSyncModulesManager"); |
7c673cae | 87 | |
20effc67 | 88 | std::map<std::string, RGWSyncModuleRef> modules; |
7c673cae | 89 | public: |
9f95a23c | 90 | RGWSyncModulesManager() = default; |
7c673cae | 91 | |
20effc67 | 92 | void register_module(const std::string& name, RGWSyncModuleRef& module, bool is_default = false) { |
9f95a23c | 93 | std::lock_guard l{lock}; |
7c673cae FG |
94 | modules[name] = module; |
95 | if (is_default) { | |
20effc67 | 96 | modules[std::string()] = module; |
7c673cae FG |
97 | } |
98 | } | |
99 | ||
20effc67 | 100 | bool get_module(const std::string& name, RGWSyncModuleRef *module) { |
9f95a23c | 101 | std::lock_guard l{lock}; |
7c673cae FG |
102 | auto iter = modules.find(name); |
103 | if (iter == modules.end()) { | |
104 | return false; | |
105 | } | |
11fdf7f2 TL |
106 | if (module != nullptr) { |
107 | *module = iter->second; | |
108 | } | |
7c673cae FG |
109 | return true; |
110 | } | |
111 | ||
112 | ||
20effc67 | 113 | bool supports_data_export(const std::string& name) { |
7c673cae FG |
114 | RGWSyncModuleRef module; |
115 | if (!get_module(name, &module)) { | |
9f95a23c | 116 | return false; |
7c673cae FG |
117 | } |
118 | ||
9f95a23c | 119 | return module->supports_data_export(); |
7c673cae FG |
120 | } |
121 | ||
20effc67 | 122 | int create_instance(const DoutPrefixProvider *dpp, CephContext *cct, const std::string& name, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) { |
7c673cae FG |
123 | RGWSyncModuleRef module; |
124 | if (!get_module(name, &module)) { | |
125 | return -ENOENT; | |
126 | } | |
127 | ||
20effc67 | 128 | return module.get()->create_instance(dpp, cct, config, instance); |
7c673cae | 129 | } |
11fdf7f2 | 130 | |
20effc67 TL |
131 | std::vector<std::string> get_registered_module_names() const { |
132 | std::vector<std::string> names; | |
11fdf7f2 TL |
133 | for (auto& i: modules) { |
134 | if (!i.first.empty()) { | |
135 | names.push_back(i.first); | |
136 | } | |
137 | } | |
138 | return names; | |
139 | } | |
7c673cae FG |
140 | }; |
141 | ||
142 | class RGWStatRemoteObjCBCR : public RGWCoroutine { | |
143 | protected: | |
9f95a23c | 144 | RGWDataSyncCtx *sc; |
7c673cae FG |
145 | RGWDataSyncEnv *sync_env; |
146 | ||
9f95a23c | 147 | rgw_bucket src_bucket; |
7c673cae FG |
148 | rgw_obj_key key; |
149 | ||
150 | ceph::real_time mtime; | |
11fdf7f2 | 151 | uint64_t size = 0; |
20effc67 TL |
152 | std::string etag; |
153 | std::map<std::string, bufferlist> attrs; | |
154 | std::map<std::string, std::string> headers; | |
7c673cae | 155 | public: |
9f95a23c TL |
156 | RGWStatRemoteObjCBCR(RGWDataSyncCtx *_sc, |
157 | rgw_bucket& _src_bucket, rgw_obj_key& _key); | |
7c673cae FG |
158 | ~RGWStatRemoteObjCBCR() override {} |
159 | ||
160 | void set_result(ceph::real_time& _mtime, | |
161 | uint64_t _size, | |
20effc67 TL |
162 | const std::string& _etag, |
163 | std::map<std::string, bufferlist>&& _attrs, | |
164 | std::map<std::string, std::string>&& _headers) { | |
7c673cae FG |
165 | mtime = _mtime; |
166 | size = _size; | |
11fdf7f2 | 167 | etag = _etag; |
7c673cae | 168 | attrs = std::move(_attrs); |
11fdf7f2 | 169 | headers = std::move(_headers); |
7c673cae FG |
170 | } |
171 | }; | |
172 | ||
173 | class RGWCallStatRemoteObjCR : public RGWCoroutine { | |
174 | ceph::real_time mtime; | |
175 | uint64_t size{0}; | |
20effc67 TL |
176 | std::string etag; |
177 | std::map<std::string, bufferlist> attrs; | |
178 | std::map<std::string, std::string> headers; | |
7c673cae FG |
179 | |
180 | protected: | |
9f95a23c | 181 | RGWDataSyncCtx *sc; |
7c673cae FG |
182 | RGWDataSyncEnv *sync_env; |
183 | ||
9f95a23c | 184 | rgw_bucket src_bucket; |
7c673cae FG |
185 | rgw_obj_key key; |
186 | ||
187 | public: | |
9f95a23c TL |
188 | RGWCallStatRemoteObjCR(RGWDataSyncCtx *_sc, |
189 | rgw_bucket& _src_bucket, rgw_obj_key& _key); | |
7c673cae FG |
190 | |
191 | ~RGWCallStatRemoteObjCR() override {} | |
192 | ||
b3b6e05e | 193 | int operate(const DoutPrefixProvider *dpp) override; |
7c673cae FG |
194 | |
195 | virtual RGWStatRemoteObjCBCR *allocate_callback() { | |
196 | return nullptr; | |
197 | } | |
198 | }; | |
199 | ||
200 | void rgw_register_sync_modules(RGWSyncModulesManager *modules_manager); | |
201 | ||
202 | #endif |