1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_RGW_SYNC_MODULE_H
5 #define CEPH_RGW_SYNC_MODULE_H
7 #include "rgw_common.h"
8 #include "rgw_coroutine.h"
11 class RGWRemoteDataLog
;
12 struct RGWDataSyncEnv
;
13 struct rgw_bucket_entry_owner
;
17 class RGWDataSyncModule
{
19 RGWDataSyncModule() {}
20 virtual ~RGWDataSyncModule() {}
22 virtual void init(RGWDataSyncEnv
*sync_env
, uint64_t instance_id
) {}
24 virtual RGWCoroutine
*init_sync(RGWDataSyncEnv
*sync_env
) {
28 virtual RGWCoroutine
*start_sync(RGWDataSyncEnv
*sync_env
) {
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;
39 class RGWMetadataHandler
;
41 class RGWSyncModuleInstance
{
43 RGWSyncModuleInstance() {}
44 virtual ~RGWSyncModuleInstance() {}
45 virtual RGWDataSyncModule
*get_data_handler() = 0;
46 virtual RGWRESTMgr
*get_rest_filter(int dialect
, RGWRESTMgr
*orig
) {
49 virtual bool supports_user_writes() {
52 virtual RGWMetadataHandler
*alloc_bucket_meta_handler();
53 virtual RGWMetadataHandler
*alloc_bucket_instance_meta_handler();
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 {
62 typedef std::shared_ptr
<RGWSyncModuleInstance
> RGWSyncModuleInstanceRef
;
64 class JSONFormattable
;
70 virtual ~RGWSyncModule() {}
72 virtual bool supports_writes() {
75 virtual bool supports_data_export() = 0;
76 virtual int create_instance(CephContext
*cct
, const JSONFormattable
& config
, RGWSyncModuleInstanceRef
*instance
) = 0;
79 typedef std::shared_ptr
<RGWSyncModule
> RGWSyncModuleRef
;
82 class RGWSyncModulesManager
{
85 map
<string
, RGWSyncModuleRef
> modules
;
87 RGWSyncModulesManager() : lock("RGWSyncModulesManager") {}
89 void register_module(const string
& name
, RGWSyncModuleRef
& module
, bool is_default
= false) {
90 Mutex::Locker
l(lock
);
91 modules
[name
] = module
;
93 modules
[string()] = module
;
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()) {
103 if (module
!= nullptr) {
104 *module
= iter
->second
;
110 int supports_data_export(const string
& name
) {
111 RGWSyncModuleRef module
;
112 if (!get_module(name
, &module
)) {
116 return module
.get()->supports_data_export();
119 int create_instance(CephContext
*cct
, const string
& name
, const JSONFormattable
& config
, RGWSyncModuleInstanceRef
*instance
) {
120 RGWSyncModuleRef module
;
121 if (!get_module(name
, &module
)) {
125 return module
.get()->create_instance(cct
, config
, instance
);
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
);
139 class RGWStatRemoteObjCBCR
: public RGWCoroutine
{
141 RGWDataSyncEnv
*sync_env
;
143 RGWBucketInfo bucket_info
;
146 ceph::real_time mtime
;
149 map
<string
, bufferlist
> attrs
;
150 map
<string
, string
> headers
;
152 RGWStatRemoteObjCBCR(RGWDataSyncEnv
*_sync_env
,
153 RGWBucketInfo
& _bucket_info
, rgw_obj_key
& _key
);
154 ~RGWStatRemoteObjCBCR() override
{}
156 void set_result(ceph::real_time
& _mtime
,
159 map
<string
, bufferlist
>&& _attrs
,
160 map
<string
, string
>&& _headers
) {
164 attrs
= std::move(_attrs
);
165 headers
= std::move(_headers
);
169 class RGWCallStatRemoteObjCR
: public RGWCoroutine
{
170 ceph::real_time mtime
;
173 map
<string
, bufferlist
> attrs
;
174 map
<string
, string
> headers
;
177 RGWDataSyncEnv
*sync_env
;
179 RGWBucketInfo bucket_info
;
183 RGWCallStatRemoteObjCR(RGWDataSyncEnv
*_sync_env
,
184 RGWBucketInfo
& _bucket_info
, rgw_obj_key
& _key
);
186 ~RGWCallStatRemoteObjCR() override
{}
188 int operate() override
;
190 virtual RGWStatRemoteObjCBCR
*allocate_callback() {
195 void rgw_register_sync_modules(RGWSyncModulesManager
*modules_manager
);