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