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