summaryrefslogtreecommitdiffstats
path: root/src/rgw/rgw_sync_module.h
blob: aa68934c06b157264e907ca55d9ab6c81354014d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_RGW_SYNC_MODULE_H
#define CEPH_RGW_SYNC_MODULE_H

#include "rgw_common.h"
#include "rgw_coroutine.h"

class RGWBucketInfo;
class RGWRemoteDataLog;
struct RGWDataSyncEnv;
struct rgw_bucket_entry_owner;
struct rgw_obj_key;


class RGWDataSyncModule {
public:
  RGWDataSyncModule() {}
  virtual ~RGWDataSyncModule() {}

  virtual void init(RGWDataSyncEnv *sync_env, uint64_t instance_id) {}

  virtual RGWCoroutine *init_sync(RGWDataSyncEnv *sync_env) {
    return nullptr;
  }

  virtual RGWCoroutine *start_sync(RGWDataSyncEnv *sync_env) {
    return nullptr;
  }
  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;
  virtual RGWCoroutine *remove_object(RGWDataSyncEnv *sync_env, RGWBucketInfo& bucket_info, rgw_obj_key& key, real_time& mtime,
                                      bool versioned, uint64_t versioned_epoch, rgw_zone_set *zones_trace) = 0;
  virtual RGWCoroutine *create_delete_marker(RGWDataSyncEnv *sync_env, RGWBucketInfo& bucket_info, rgw_obj_key& key, real_time& mtime,
                                             rgw_bucket_entry_owner& owner, bool versioned, uint64_t versioned_epoch, rgw_zone_set *zones_trace) = 0;
};

class RGWRESTMgr;
class RGWMetadataHandler;

class RGWSyncModuleInstance {
public:
  RGWSyncModuleInstance() {}
  virtual ~RGWSyncModuleInstance() {}
  virtual RGWDataSyncModule *get_data_handler() = 0;
  virtual RGWRESTMgr *get_rest_filter(int dialect, RGWRESTMgr *orig) {
    return orig;
  }
  virtual bool supports_user_writes() {
    return false;
  }
  virtual RGWMetadataHandler *alloc_bucket_meta_handler();
  virtual RGWMetadataHandler *alloc_bucket_instance_meta_handler();

  // indication whether the sync module start with full sync (default behavior)
  // incremental sync would follow anyway
  virtual bool should_full_sync() const {
      return true;
  }
};

typedef std::shared_ptr<RGWSyncModuleInstance> RGWSyncModuleInstanceRef;

class JSONFormattable;

class RGWSyncModule {

public:
  RGWSyncModule() {}
  virtual ~RGWSyncModule() {}

  virtual bool supports_writes() {
    return false;
  }
  virtual bool supports_data_export() = 0;
  virtual int create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) = 0;
};

typedef std::shared_ptr<RGWSyncModule> RGWSyncModuleRef;


class RGWSyncModulesManager {
  Mutex lock;

  map<string, RGWSyncModuleRef> modules;
public:
  RGWSyncModulesManager() : lock("RGWSyncModulesManager") {}

  void register_module(const string& name, RGWSyncModuleRef& module, bool is_default = false) {
    Mutex::Locker l(lock);
    modules[name] = module;
    if (is_default) {
      modules[string()] = module;
    }
  }

  bool get_module(const string& name, RGWSyncModuleRef *module) {
    Mutex::Locker l(lock);
    auto iter = modules.find(name);
    if (iter == modules.end()) {
      return false;
    }
    if (module != nullptr) {
      *module = iter->second;
    }
    return true;
  }


  int supports_data_export(const string& name) {
    RGWSyncModuleRef module;
    if (!get_module(name, &module)) {
      return -ENOENT;
    }

    return module.get()->supports_data_export();
  }

  int create_instance(CephContext *cct, const string& name, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) {
    RGWSyncModuleRef module;
    if (!get_module(name, &module)) {
      return -ENOENT;
    }

    return module.get()->create_instance(cct, config, instance);
  }

  vector<string> get_registered_module_names() const {
    vector<string> names;
    for (auto& i: modules) {
      if (!i.first.empty()) {
        names.push_back(i.first);
      }
    }
    return names;
  }
};

class RGWStatRemoteObjCBCR : public RGWCoroutine {
protected:
  RGWDataSyncEnv *sync_env;

  RGWBucketInfo bucket_info;
  rgw_obj_key key;

  ceph::real_time mtime;
  uint64_t size = 0;
  string etag;
  map<string, bufferlist> attrs;
  map<string, string> headers;
public:
  RGWStatRemoteObjCBCR(RGWDataSyncEnv *_sync_env,
                       RGWBucketInfo& _bucket_info, rgw_obj_key& _key);
  ~RGWStatRemoteObjCBCR() override {}

  void set_result(ceph::real_time& _mtime,
                  uint64_t _size,
                  const string& _etag,
                  map<string, bufferlist>&& _attrs,
                  map<string, string>&& _headers) {
    mtime = _mtime;
    size = _size;
    etag = _etag;
    attrs = std::move(_attrs);
    headers = std::move(_headers);
  }
};

class RGWCallStatRemoteObjCR : public RGWCoroutine {
  ceph::real_time mtime;
  uint64_t size{0};
  string etag;
  map<string, bufferlist> attrs;
  map<string, string> headers;

protected:
  RGWDataSyncEnv *sync_env;

  RGWBucketInfo bucket_info;
  rgw_obj_key key;

public:
  RGWCallStatRemoteObjCR(RGWDataSyncEnv *_sync_env,
                     RGWBucketInfo& _bucket_info, rgw_obj_key& _key);

  ~RGWCallStatRemoteObjCR() override {}

  int operate() override;

  virtual RGWStatRemoteObjCBCR *allocate_callback() {
    return nullptr;
  }
};

void rgw_register_sync_modules(RGWSyncModulesManager *modules_manager);

#endif