1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
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 RGWDataSyncCtx
;
13 struct RGWDataSyncEnv
;
14 struct rgw_bucket_entry_owner
;
16 struct rgw_bucket_sync_pipe
;
19 class RGWDataSyncModule
{
21 RGWDataSyncModule() {}
22 virtual ~RGWDataSyncModule() {}
24 virtual void init(RGWDataSyncCtx
*sync_env
, uint64_t instance_id
) {}
26 virtual RGWCoroutine
*init_sync(const DoutPrefixProvider
*dpp
, RGWDataSyncCtx
*sc
) {
30 virtual RGWCoroutine
*start_sync(const DoutPrefixProvider
*dpp
, RGWDataSyncCtx
*sc
) {
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
,
35 bool versioned
, uint64_t versioned_epoch
, rgw_zone_set
*zones_trace
) = 0;
36 virtual RGWCoroutine
*create_delete_marker(const DoutPrefixProvider
*dpp
, 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;
41 class RGWMetadataHandler
;
42 class RGWBucketInstanceMetadataHandlerBase
;
44 class RGWSyncModuleInstance
{
46 RGWSyncModuleInstance() {}
47 virtual ~RGWSyncModuleInstance() {}
48 virtual RGWDataSyncModule
*get_data_handler() = 0;
49 virtual RGWRESTMgr
*get_rest_filter(int dialect
, RGWRESTMgr
*orig
) {
52 virtual bool supports_user_writes() {
55 virtual RGWMetadataHandler
*alloc_bucket_meta_handler();
56 virtual RGWBucketInstanceMetadataHandlerBase
*alloc_bucket_instance_meta_handler();
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 {
65 typedef std::shared_ptr
<RGWSyncModuleInstance
> RGWSyncModuleInstanceRef
;
67 class JSONFormattable
;
73 virtual ~RGWSyncModule() {}
75 virtual bool supports_writes() {
78 virtual bool supports_data_export() = 0;
79 virtual int create_instance(const DoutPrefixProvider
*dpp
, CephContext
*cct
, const JSONFormattable
& config
, RGWSyncModuleInstanceRef
*instance
) = 0;
82 typedef std::shared_ptr
<RGWSyncModule
> RGWSyncModuleRef
;
85 class RGWSyncModulesManager
{
86 ceph::mutex lock
= ceph::make_mutex("RGWSyncModulesManager");
88 std::map
<std::string
, RGWSyncModuleRef
> modules
;
90 RGWSyncModulesManager() = default;
92 void register_module(const std::string
& name
, RGWSyncModuleRef
& module
, bool is_default
= false) {
93 std::lock_guard l
{lock
};
94 modules
[name
] = module
;
96 modules
[std::string()] = module
;
100 bool get_module(const std::string
& name
, RGWSyncModuleRef
*module
) {
101 std::lock_guard l
{lock
};
102 auto iter
= modules
.find(name
);
103 if (iter
== modules
.end()) {
106 if (module
!= nullptr) {
107 *module
= iter
->second
;
113 bool supports_data_export(const std::string
& name
) {
114 RGWSyncModuleRef module
;
115 if (!get_module(name
, &module
)) {
119 return module
->supports_data_export();
122 int create_instance(const DoutPrefixProvider
*dpp
, CephContext
*cct
, const std::string
& name
, const JSONFormattable
& config
, RGWSyncModuleInstanceRef
*instance
) {
123 RGWSyncModuleRef module
;
124 if (!get_module(name
, &module
)) {
128 return module
.get()->create_instance(dpp
, cct
, config
, instance
);
131 std::vector
<std::string
> get_registered_module_names() const {
132 std::vector
<std::string
> names
;
133 for (auto& i
: modules
) {
134 if (!i
.first
.empty()) {
135 names
.push_back(i
.first
);
142 class RGWStatRemoteObjCBCR
: public RGWCoroutine
{
145 RGWDataSyncEnv
*sync_env
;
147 rgw_bucket src_bucket
;
150 ceph::real_time mtime
;
153 std::map
<std::string
, bufferlist
> attrs
;
154 std::map
<std::string
, std::string
> headers
;
156 RGWStatRemoteObjCBCR(RGWDataSyncCtx
*_sc
,
157 rgw_bucket
& _src_bucket
, rgw_obj_key
& _key
);
158 ~RGWStatRemoteObjCBCR() override
{}
160 void set_result(ceph::real_time
& _mtime
,
162 const std::string
& _etag
,
163 std::map
<std::string
, bufferlist
>&& _attrs
,
164 std::map
<std::string
, std::string
>&& _headers
) {
168 attrs
= std::move(_attrs
);
169 headers
= std::move(_headers
);
173 class RGWCallStatRemoteObjCR
: public RGWCoroutine
{
174 ceph::real_time mtime
;
177 std::map
<std::string
, bufferlist
> attrs
;
178 std::map
<std::string
, std::string
> headers
;
182 RGWDataSyncEnv
*sync_env
;
184 rgw_bucket src_bucket
;
188 RGWCallStatRemoteObjCR(RGWDataSyncCtx
*_sc
,
189 rgw_bucket
& _src_bucket
, rgw_obj_key
& _key
);
191 ~RGWCallStatRemoteObjCR() override
{}
193 int operate(const DoutPrefixProvider
*dpp
) override
;
195 virtual RGWStatRemoteObjCBCR
*allocate_callback() {
200 void rgw_register_sync_modules(RGWSyncModulesManager
*modules_manager
);