]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_sync_module.h
import ceph 14.2.5
[ceph.git] / ceph / src / rgw / rgw_sync_module.h
CommitLineData
11fdf7f2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
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
10class RGWBucketInfo;
11class RGWRemoteDataLog;
12struct RGWDataSyncEnv;
13struct rgw_bucket_entry_owner;
14struct rgw_obj_key;
15
16
17class RGWDataSyncModule {
18public:
19 RGWDataSyncModule() {}
20 virtual ~RGWDataSyncModule() {}
21
31f18b77
FG
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
11fdf7f2
TL
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;
7c673cae 32 virtual RGWCoroutine *remove_object(RGWDataSyncEnv *sync_env, RGWBucketInfo& bucket_info, rgw_obj_key& key, real_time& mtime,
31f18b77 33 bool versioned, uint64_t versioned_epoch, rgw_zone_set *zones_trace) = 0;
7c673cae 34 virtual RGWCoroutine *create_delete_marker(RGWDataSyncEnv *sync_env, RGWBucketInfo& bucket_info, rgw_obj_key& key, real_time& mtime,
31f18b77 35 rgw_bucket_entry_owner& owner, bool versioned, uint64_t versioned_epoch, rgw_zone_set *zones_trace) = 0;
7c673cae
FG
36};
37
31f18b77 38class RGWRESTMgr;
11fdf7f2 39class RGWMetadataHandler;
31f18b77 40
7c673cae
FG
41class RGWSyncModuleInstance {
42public:
43 RGWSyncModuleInstance() {}
44 virtual ~RGWSyncModuleInstance() {}
45 virtual RGWDataSyncModule *get_data_handler() = 0;
31f18b77
FG
46 virtual RGWRESTMgr *get_rest_filter(int dialect, RGWRESTMgr *orig) {
47 return orig;
48 }
11fdf7f2
TL
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();
eafe8130
TL
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 }
7c673cae
FG
60};
61
62typedef std::shared_ptr<RGWSyncModuleInstance> RGWSyncModuleInstanceRef;
63
11fdf7f2
TL
64class JSONFormattable;
65
7c673cae
FG
66class RGWSyncModule {
67
68public:
69 RGWSyncModule() {}
70 virtual ~RGWSyncModule() {}
71
11fdf7f2
TL
72 virtual bool supports_writes() {
73 return false;
74 }
7c673cae 75 virtual bool supports_data_export() = 0;
11fdf7f2 76 virtual int create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) = 0;
7c673cae
FG
77};
78
79typedef std::shared_ptr<RGWSyncModule> RGWSyncModuleRef;
80
81
82class RGWSyncModulesManager {
83 Mutex lock;
84
85 map<string, RGWSyncModuleRef> modules;
86public:
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 }
11fdf7f2
TL
103 if (module != nullptr) {
104 *module = iter->second;
105 }
7c673cae
FG
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
11fdf7f2 119 int create_instance(CephContext *cct, const string& name, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) {
7c673cae
FG
120 RGWSyncModuleRef module;
121 if (!get_module(name, &module)) {
122 return -ENOENT;
123 }
124
125 return module.get()->create_instance(cct, config, instance);
126 }
11fdf7f2
TL
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 }
7c673cae
FG
137};
138
139class RGWStatRemoteObjCBCR : public RGWCoroutine {
140protected:
141 RGWDataSyncEnv *sync_env;
142
143 RGWBucketInfo bucket_info;
144 rgw_obj_key key;
145
146 ceph::real_time mtime;
11fdf7f2
TL
147 uint64_t size = 0;
148 string etag;
7c673cae 149 map<string, bufferlist> attrs;
11fdf7f2 150 map<string, string> headers;
7c673cae
FG
151public:
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,
11fdf7f2
TL
158 const string& _etag,
159 map<string, bufferlist>&& _attrs,
160 map<string, string>&& _headers) {
7c673cae
FG
161 mtime = _mtime;
162 size = _size;
11fdf7f2 163 etag = _etag;
7c673cae 164 attrs = std::move(_attrs);
11fdf7f2 165 headers = std::move(_headers);
7c673cae
FG
166 }
167};
168
169class RGWCallStatRemoteObjCR : public RGWCoroutine {
170 ceph::real_time mtime;
171 uint64_t size{0};
11fdf7f2 172 string etag;
7c673cae 173 map<string, bufferlist> attrs;
11fdf7f2 174 map<string, string> headers;
7c673cae
FG
175
176protected:
177 RGWDataSyncEnv *sync_env;
178
179 RGWBucketInfo bucket_info;
180 rgw_obj_key key;
181
182public:
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
195void rgw_register_sync_modules(RGWSyncModulesManager *modules_manager);
196
197#endif