summaryrefslogtreecommitdiffstats
path: root/src/rgw/services/svc_meta_be_sobj.h
blob: 8c5660a6d54d9fdd6ccfff3f1513472925bd1422 (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
// -*- 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 "rgw/rgw_service.h"

#include "svc_meta_be.h"
#include "svc_sys_obj.h"


class RGWSI_MBSObj_Handler_Module : public RGWSI_MetaBackend::Module {
protected:
  string section;
public:
  RGWSI_MBSObj_Handler_Module(const string& _section) : section(_section) {}
  virtual void get_pool_and_oid(const std::string& key, rgw_pool *pool, std::string *oid) = 0;
  virtual const std::string& get_oid_prefix() = 0;
  virtual std::string key_to_oid(const std::string& key) = 0;
  virtual bool is_valid_oid(const std::string& oid) = 0;
  virtual std::string oid_to_key(const std::string& oid) = 0;

  const std::string& get_section() {
    return section;
  }

  /* key to use for hashing entries for log shard placement */
  virtual std::string get_hash_key(const std::string& key) {
    return section + ":" + key;
  }
};

struct RGWSI_MBSObj_GetParams : public RGWSI_MetaBackend::GetParams {
  bufferlist *pbl{nullptr};
  map<string, bufferlist> *pattrs{nullptr};
  rgw_cache_entry_info *cache_info{nullptr};
  boost::optional<obj_version> refresh_version;

  RGWSI_MBSObj_GetParams() {}
  RGWSI_MBSObj_GetParams(bufferlist *_pbl,
                         std::map<string, bufferlist> *_pattrs,
                         ceph::real_time *_pmtime) : RGWSI_MetaBackend::GetParams(_pmtime),
                                                     pbl(_pbl),
                                                     pattrs(_pattrs) {}

  RGWSI_MBSObj_GetParams& set_cache_info(rgw_cache_entry_info *_cache_info) {
    cache_info = _cache_info;
    return *this;
  }
  RGWSI_MBSObj_GetParams& set_refresh_version(boost::optional<obj_version>& _refresh_version) {
    refresh_version = _refresh_version;
    return *this;
  }
};

struct RGWSI_MBSObj_PutParams : public RGWSI_MetaBackend::PutParams {
  bufferlist bl;
  map<string, bufferlist> *pattrs{nullptr};
  bool exclusive{false};

  RGWSI_MBSObj_PutParams() {}
  RGWSI_MBSObj_PutParams(std::map<string, bufferlist> *_pattrs,
                         const ceph::real_time& _mtime) : RGWSI_MetaBackend::PutParams(_mtime),
                                                          pattrs(_pattrs) {}
  RGWSI_MBSObj_PutParams(bufferlist& _bl,
                         std::map<string, bufferlist> *_pattrs,
                         const ceph::real_time& _mtime,
                         bool _exclusive) : RGWSI_MetaBackend::PutParams(_mtime),
                                            bl(_bl),
                                            pattrs(_pattrs),
                                            exclusive(_exclusive) {}
};

struct RGWSI_MBSObj_RemoveParams : public RGWSI_MetaBackend::RemoveParams {
};

class RGWSI_MetaBackend_SObj : public RGWSI_MetaBackend
{
protected:
  RGWSI_SysObj *sysobj_svc{nullptr};

public:
  struct Context_SObj : public RGWSI_MetaBackend::Context {
    RGWSI_SysObj *sysobj_svc{nullptr};

    RGWSI_MBSObj_Handler_Module *module{nullptr};
    std::optional<RGWSysObjectCtx> _obj_ctx;
    RGWSysObjectCtx *obj_ctx{nullptr};
    struct _list {
      std::optional<RGWSI_SysObj::Pool> pool;
      std::optional<RGWSI_SysObj::Pool::Op> op;
    } list;

    Context_SObj(RGWSI_SysObj *_sysobj_svc,
                 RGWSysObjectCtx *_oc = nullptr) : sysobj_svc(_sysobj_svc),
                                                   obj_ctx(_oc) {}

    void init(RGWSI_MetaBackend_Handler *h) override;
  };

  RGWSI_MetaBackend_SObj(CephContext *cct);
  virtual ~RGWSI_MetaBackend_SObj();

  RGWSI_MetaBackend::Type get_type() {
    return MDBE_SOBJ;
  }

  void init(RGWSI_SysObj *_sysobj_svc,
            RGWSI_MDLog *_mdlog_svc) {
    base_init(_mdlog_svc);
    sysobj_svc = _sysobj_svc;
  }

  RGWSI_MetaBackend_Handler *alloc_be_handler() override;
  RGWSI_MetaBackend::Context *alloc_ctx() override;


  int call_with_get_params(ceph::real_time *pmtime, std::function<int(RGWSI_MetaBackend::GetParams&)> cb) override;

  int pre_modify(const DoutPrefixProvider *dpp, 
                 RGWSI_MetaBackend::Context *ctx,
                 const string& key,
                 RGWMetadataLogData& log_data,
                 RGWObjVersionTracker *objv_tracker,
                 RGWMDLogStatus op_type,
                 optional_yield y);
  int post_modify(const DoutPrefixProvider *dpp, 
                  RGWSI_MetaBackend::Context *ctx,
                  const string& key,
                  RGWMetadataLogData& log_data,
                  RGWObjVersionTracker *objv_tracker, int ret,
                  optional_yield y);

  int get_entry(RGWSI_MetaBackend::Context *ctx,
                const string& key,
                RGWSI_MetaBackend::GetParams& params,
                RGWObjVersionTracker *objv_tracker,
                optional_yield y,
                const DoutPrefixProvider *dpp) override;
  int put_entry(const DoutPrefixProvider *dpp, 
                RGWSI_MetaBackend::Context *ctx,
                const string& key,
                RGWSI_MetaBackend::PutParams& params,
                RGWObjVersionTracker *objv_tracker,
                optional_yield y) override;
  int remove_entry(const DoutPrefixProvider *dpp, 
                   RGWSI_MetaBackend::Context *ctx,
                   const string& key,
                   RGWSI_MetaBackend::RemoveParams& params,
                   RGWObjVersionTracker *objv_tracker,
                   optional_yield y) override;

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

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

  int call(std::optional<RGWSI_MetaBackend_CtxParams> opt,
           std::function<int(RGWSI_MetaBackend::Context *)> f) override;
};


class RGWSI_MetaBackend_Handler_SObj : public RGWSI_MetaBackend_Handler {
  friend class RGWSI_MetaBackend_SObj::Context_SObj;

  RGWSI_MBSObj_Handler_Module *module{nullptr};

public:
  RGWSI_MetaBackend_Handler_SObj(RGWSI_MetaBackend *be) : 
                                            RGWSI_MetaBackend_Handler(be) {}
  
  void set_module(RGWSI_MBSObj_Handler_Module *_module) {
    module = _module;
  }

  RGWSI_MBSObj_Handler_Module *get_module() {
    return module;
  }
};