summaryrefslogtreecommitdiffstats
path: root/src/rgw/services/svc_meta_be.h
blob: af749d497f34b9f146cefbeac8f9719a82f970a2 (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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab ft=cpp

/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2019 Red Hat, Inc.
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation. See file COPYING.
 *
 */


#pragma once

#include "svc_meta_be_params.h"

#include "rgw/rgw_service.h"
#include "rgw/rgw_mdlog_types.h"

class RGWMetadataLogData;

class RGWSI_MDLog;
class RGWSI_Meta;
class RGWObjVersionTracker;
class RGWSI_MetaBackend_Handler;

class RGWSI_MetaBackend : public RGWServiceInstance
{
  friend class RGWSI_Meta;
public:
  class Module;
  class Context;
protected:
  RGWSI_MDLog *mdlog_svc{nullptr};

  void base_init(RGWSI_MDLog *_mdlog_svc) {
    mdlog_svc = _mdlog_svc;
  }

  int prepare_mutate(RGWSI_MetaBackend::Context *ctx,
                     const std::string& key,
                     const ceph::real_time& mtime,
                     RGWObjVersionTracker *objv_tracker,
                     optional_yield y,
                     const DoutPrefixProvider *dpp);

  virtual int do_mutate(Context *ctx,
                     const std::string& key,
                     const ceph::real_time& mtime, RGWObjVersionTracker *objv_tracker,
                     RGWMDLogStatus op_type,
                     optional_yield y,
                     std::function<int()> f,
                     bool generic_prepare,
                     const DoutPrefixProvider *dpp);

  virtual int pre_modify(const DoutPrefixProvider *dpp, 
                         Context *ctx,
                         const std::string& key,
                         RGWMetadataLogData& log_data,
                         RGWObjVersionTracker *objv_tracker,
                         RGWMDLogStatus op_type,
                         optional_yield y);
  virtual int post_modify(const DoutPrefixProvider *dpp, 
                          Context *ctx,
                          const std::string& key,
                          RGWMetadataLogData& log_data,
                          RGWObjVersionTracker *objv_tracker, int ret,
                          optional_yield y);
public:
  class Module {
    /*
     * Backend specialization module
     */
  public:
    virtual ~Module() = 0;
  };

  using ModuleRef = std::shared_ptr<Module>;

  struct Context { /*
                    * A single metadata operation context. Will be holding info about
                    * backend and operation itself; operation might span multiple backend
                    * calls.
                    */
    virtual ~Context() = 0;

    virtual void init(RGWSI_MetaBackend_Handler *h) = 0;
  };

  virtual Context *alloc_ctx() = 0;

  struct PutParams {
    ceph::real_time mtime;

    PutParams() {}
    PutParams(const ceph::real_time& _mtime) : mtime(_mtime) {}
    virtual ~PutParams() = 0;
  };

  struct GetParams {
    GetParams() {}
    GetParams(ceph::real_time *_pmtime) : pmtime(_pmtime) {}
    virtual ~GetParams();

    ceph::real_time *pmtime{nullptr};
  };

  struct RemoveParams {
    virtual ~RemoveParams() = 0;

    ceph::real_time mtime;
  };

  struct MutateParams {
    ceph::real_time mtime;
    RGWMDLogStatus op_type;

    MutateParams() {}
    MutateParams(const ceph::real_time& _mtime,
		 RGWMDLogStatus _op_type) : mtime(_mtime), op_type(_op_type) {}
    virtual ~MutateParams() {}
  };

  enum Type {
    MDBE_SOBJ = 0,
    MDBE_OTP  = 1,
  };

  RGWSI_MetaBackend(CephContext *cct) : RGWServiceInstance(cct) {}
  virtual ~RGWSI_MetaBackend() {}

  virtual Type get_type() = 0;

  virtual RGWSI_MetaBackend_Handler *alloc_be_handler() = 0;
  virtual int call_with_get_params(ceph::real_time *pmtime, std::function<int(RGWSI_MetaBackend::GetParams&)>) = 0;

  /* these should be implemented by backends */
  virtual int get_entry(RGWSI_MetaBackend::Context *ctx,
                        const std::string& key,
                        RGWSI_MetaBackend::GetParams& params,
                        RGWObjVersionTracker *objv_tracker,
                        optional_yield y,
                        const DoutPrefixProvider *dpp) = 0;
  virtual int put_entry(const DoutPrefixProvider *dpp, 
                        RGWSI_MetaBackend::Context *ctx,
                        const std::string& key,
                        RGWSI_MetaBackend::PutParams& params,
                        RGWObjVersionTracker *objv_tracker,
                        optional_yield y) = 0;
  virtual int remove_entry(const DoutPrefixProvider *dpp, 
                           Context *ctx,
                           const std::string& key,
                           RGWSI_MetaBackend::RemoveParams& params,
                           RGWObjVersionTracker *objv_tracker,
                           optional_yield y) = 0;

  virtual int list_init(const DoutPrefixProvider *dpp, RGWSI_MetaBackend::Context *ctx, const string& marker) = 0;
  virtual int list_next(RGWSI_MetaBackend::Context *ctx,
                        int max, list<string> *keys,
                        bool *truncated)  = 0;
  virtual int list_get_marker(RGWSI_MetaBackend::Context *ctx,
                              string *marker) = 0;

  int call(std::function<int(RGWSI_MetaBackend::Context *)> f) {
    return call(nullopt, f);
  }

  virtual int call(std::optional<RGWSI_MetaBackend_CtxParams> opt,
                   std::function<int(RGWSI_MetaBackend::Context *)> f) = 0;

  virtual int get_shard_id(RGWSI_MetaBackend::Context *ctx,
			   const std::string& key,
			   int *shard_id) = 0;

  /* higher level */
  virtual int get(Context *ctx,
                  const std::string& key,
                  GetParams &params,
                  RGWObjVersionTracker *objv_tracker,
                  optional_yield y,
                  const DoutPrefixProvider *dpp);

  virtual int put(Context *ctx,
                  const std::string& key,
                  PutParams& params,
                  RGWObjVersionTracker *objv_tracker,
                  optional_yield y,
                  const DoutPrefixProvider *dpp);

  virtual int remove(Context *ctx,
                     const std::string& key,
                     RemoveParams& params,
                     RGWObjVersionTracker *objv_tracker,
                     optional_yield y,
                     const DoutPrefixProvider *dpp);

  virtual int mutate(Context *ctx,
                     const std::string& key,
                     MutateParams& params,
		     RGWObjVersionTracker *objv_tracker,
                     optional_yield y,
                     std::function<int()> f,
                     const DoutPrefixProvider *dpp);
};

class RGWSI_MetaBackend_Handler {
  RGWSI_MetaBackend *be{nullptr};

public:
  class Op {
    friend class RGWSI_MetaBackend_Handler;

    RGWSI_MetaBackend *be;
    RGWSI_MetaBackend::Context *be_ctx;

    Op(RGWSI_MetaBackend *_be,
       RGWSI_MetaBackend::Context *_ctx) : be(_be), be_ctx(_ctx) {}

  public:
    RGWSI_MetaBackend::Context *ctx() {
      return be_ctx;
    }

    int get(const std::string& key,
            RGWSI_MetaBackend::GetParams &params,
            RGWObjVersionTracker *objv_tracker,
            optional_yield y, const DoutPrefixProvider *dpp) {
      return be->get(be_ctx, key, params, objv_tracker, y, dpp);
    }

    int put(const std::string& key,
            RGWSI_MetaBackend::PutParams& params,
            RGWObjVersionTracker *objv_tracker,
            optional_yield y, const DoutPrefixProvider *dpp) {
      return be->put(be_ctx, key, params, objv_tracker, y, dpp);
    }

    int remove(const std::string& key,
               RGWSI_MetaBackend::RemoveParams& params,
               RGWObjVersionTracker *objv_tracker,
               optional_yield y, const DoutPrefixProvider *dpp) {
      return be->remove(be_ctx, key, params, objv_tracker, y, dpp);
    }

    int mutate(const std::string& key,
	       RGWSI_MetaBackend::MutateParams& params,
	       RGWObjVersionTracker *objv_tracker,
               optional_yield y,
	       std::function<int()> f,
               const DoutPrefixProvider *dpp) {
      return be->mutate(be_ctx, key, params, objv_tracker, y, f, dpp);
    }

    int list_init(const DoutPrefixProvider *dpp, const string& marker) {
      return be->list_init(dpp, be_ctx, marker);
    }
    int list_next(int max, list<string> *keys,
                  bool *truncated) {
      return be->list_next(be_ctx, max, keys, truncated);
    }
    int list_get_marker(string *marker) {
      return be->list_get_marker(be_ctx, marker);
    }

    int get_shard_id(const std::string& key, int *shard_id) {
      return be->get_shard_id(be_ctx, key, shard_id);
    }
  };

  class Op_ManagedCtx : public Op {
    std::unique_ptr<RGWSI_MetaBackend::Context> pctx;
  public:
    Op_ManagedCtx(RGWSI_MetaBackend_Handler *handler);
  };

  RGWSI_MetaBackend_Handler(RGWSI_MetaBackend *_be) : be(_be) {}
  virtual ~RGWSI_MetaBackend_Handler() {}

  int call(std::function<int(Op *)> f) {
    return call(nullopt, f);
  }

  virtual int call(std::optional<RGWSI_MetaBackend_CtxParams> bectx_params,
                   std::function<int(Op *)> f);
};