]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | |
2 | ||
3 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | |
4 | // vim: ts=8 sw=2 smarttab ft=cpp | |
5 | ||
6 | /* | |
7 | * Ceph - scalable distributed file system | |
8 | * | |
9 | * Copyright (C) 2019 Red Hat, Inc. | |
10 | * | |
11 | * This is free software; you can redistribute it and/or | |
12 | * modify it under the terms of the GNU Lesser General Public | |
13 | * License version 2.1, as published by the Free Software | |
14 | * Foundation. See file COPYING. | |
15 | * | |
16 | */ | |
17 | ||
18 | ||
19 | #pragma once | |
20 | ||
21 | #include "rgw/rgw_service.h" | |
22 | ||
23 | #include "svc_meta_be.h" | |
24 | #include "svc_sys_obj.h" | |
25 | ||
26 | ||
27 | class RGWSI_MBSObj_Handler_Module : public RGWSI_MetaBackend::Module { | |
28 | protected: | |
29 | string section; | |
30 | public: | |
31 | RGWSI_MBSObj_Handler_Module(const string& _section) : section(_section) {} | |
32 | virtual void get_pool_and_oid(const std::string& key, rgw_pool *pool, std::string *oid) = 0; | |
33 | virtual const std::string& get_oid_prefix() = 0; | |
34 | virtual std::string key_to_oid(const std::string& key) = 0; | |
35 | virtual bool is_valid_oid(const std::string& oid) = 0; | |
36 | virtual std::string oid_to_key(const std::string& oid) = 0; | |
37 | ||
38 | const std::string& get_section() { | |
39 | return section; | |
40 | } | |
41 | ||
42 | /* key to use for hashing entries for log shard placement */ | |
43 | virtual std::string get_hash_key(const std::string& key) { | |
44 | return section + ":" + key; | |
45 | } | |
46 | }; | |
47 | ||
48 | struct RGWSI_MBSObj_GetParams : public RGWSI_MetaBackend::GetParams { | |
49 | bufferlist *pbl{nullptr}; | |
50 | map<string, bufferlist> *pattrs{nullptr}; | |
51 | rgw_cache_entry_info *cache_info{nullptr}; | |
52 | boost::optional<obj_version> refresh_version; | |
53 | ||
54 | RGWSI_MBSObj_GetParams() {} | |
55 | RGWSI_MBSObj_GetParams(bufferlist *_pbl, | |
56 | std::map<string, bufferlist> *_pattrs, | |
57 | ceph::real_time *_pmtime) : RGWSI_MetaBackend::GetParams(_pmtime), | |
58 | pbl(_pbl), | |
59 | pattrs(_pattrs) {} | |
60 | ||
61 | RGWSI_MBSObj_GetParams& set_cache_info(rgw_cache_entry_info *_cache_info) { | |
62 | cache_info = _cache_info; | |
63 | return *this; | |
64 | } | |
65 | RGWSI_MBSObj_GetParams& set_refresh_version(boost::optional<obj_version>& _refresh_version) { | |
66 | refresh_version = _refresh_version; | |
67 | return *this; | |
68 | } | |
69 | }; | |
70 | ||
71 | struct RGWSI_MBSObj_PutParams : public RGWSI_MetaBackend::PutParams { | |
72 | bufferlist bl; | |
73 | map<string, bufferlist> *pattrs{nullptr}; | |
74 | bool exclusive{false}; | |
75 | ||
76 | RGWSI_MBSObj_PutParams() {} | |
77 | RGWSI_MBSObj_PutParams(std::map<string, bufferlist> *_pattrs, | |
78 | const ceph::real_time& _mtime) : RGWSI_MetaBackend::PutParams(_mtime), | |
79 | pattrs(_pattrs) {} | |
80 | RGWSI_MBSObj_PutParams(bufferlist& _bl, | |
81 | std::map<string, bufferlist> *_pattrs, | |
82 | const ceph::real_time& _mtime, | |
83 | bool _exclusive) : RGWSI_MetaBackend::PutParams(_mtime), | |
84 | bl(_bl), | |
85 | pattrs(_pattrs), | |
86 | exclusive(_exclusive) {} | |
87 | }; | |
88 | ||
89 | struct RGWSI_MBSObj_RemoveParams : public RGWSI_MetaBackend::RemoveParams { | |
90 | }; | |
91 | ||
92 | class RGWSI_MetaBackend_SObj : public RGWSI_MetaBackend | |
93 | { | |
94 | protected: | |
95 | RGWSI_SysObj *sysobj_svc{nullptr}; | |
96 | ||
97 | public: | |
98 | struct Context_SObj : public RGWSI_MetaBackend::Context { | |
99 | RGWSI_SysObj *sysobj_svc{nullptr}; | |
100 | ||
101 | RGWSI_MBSObj_Handler_Module *module{nullptr}; | |
102 | std::optional<RGWSysObjectCtx> _obj_ctx; | |
103 | RGWSysObjectCtx *obj_ctx{nullptr}; | |
104 | struct _list { | |
105 | std::optional<RGWSI_SysObj::Pool> pool; | |
106 | std::optional<RGWSI_SysObj::Pool::Op> op; | |
107 | } list; | |
108 | ||
109 | Context_SObj(RGWSI_SysObj *_sysobj_svc, | |
110 | RGWSysObjectCtx *_oc = nullptr) : sysobj_svc(_sysobj_svc), | |
111 | obj_ctx(_oc) {} | |
112 | ||
113 | void init(RGWSI_MetaBackend_Handler *h) override; | |
114 | }; | |
115 | ||
116 | RGWSI_MetaBackend_SObj(CephContext *cct); | |
117 | virtual ~RGWSI_MetaBackend_SObj(); | |
118 | ||
119 | RGWSI_MetaBackend::Type get_type() { | |
120 | return MDBE_SOBJ; | |
121 | } | |
122 | ||
123 | void init(RGWSI_SysObj *_sysobj_svc, | |
124 | RGWSI_MDLog *_mdlog_svc) { | |
125 | base_init(_mdlog_svc); | |
126 | sysobj_svc = _sysobj_svc; | |
127 | } | |
128 | ||
129 | RGWSI_MetaBackend_Handler *alloc_be_handler() override; | |
130 | RGWSI_MetaBackend::Context *alloc_ctx() override; | |
131 | ||
132 | ||
133 | int call_with_get_params(ceph::real_time *pmtime, std::function<int(RGWSI_MetaBackend::GetParams&)> cb) override; | |
134 | ||
135 | int pre_modify(RGWSI_MetaBackend::Context *ctx, | |
136 | const string& key, | |
137 | RGWMetadataLogData& log_data, | |
138 | RGWObjVersionTracker *objv_tracker, | |
139 | RGWMDLogStatus op_type, | |
140 | optional_yield y); | |
141 | int post_modify(RGWSI_MetaBackend::Context *ctx, | |
142 | const string& key, | |
143 | RGWMetadataLogData& log_data, | |
144 | RGWObjVersionTracker *objv_tracker, int ret, | |
145 | optional_yield y); | |
146 | ||
147 | int get_entry(RGWSI_MetaBackend::Context *ctx, | |
148 | const string& key, | |
149 | RGWSI_MetaBackend::GetParams& params, | |
150 | RGWObjVersionTracker *objv_tracker, | |
151 | optional_yield y) override; | |
152 | int put_entry(RGWSI_MetaBackend::Context *ctx, | |
153 | const string& key, | |
154 | RGWSI_MetaBackend::PutParams& params, | |
155 | RGWObjVersionTracker *objv_tracker, | |
156 | optional_yield y) override; | |
157 | int remove_entry(RGWSI_MetaBackend::Context *ctx, | |
158 | const string& key, | |
159 | RGWSI_MetaBackend::RemoveParams& params, | |
160 | RGWObjVersionTracker *objv_tracker, | |
161 | optional_yield y) override; | |
162 | ||
163 | int list_init(RGWSI_MetaBackend::Context *_ctx, const string& marker) override; | |
164 | int list_next(RGWSI_MetaBackend::Context *_ctx, | |
165 | int max, list<string> *keys, | |
166 | bool *truncated) override; | |
167 | int list_get_marker(RGWSI_MetaBackend::Context *ctx, | |
168 | string *marker) override; | |
169 | ||
170 | int get_shard_id(RGWSI_MetaBackend::Context *ctx, | |
171 | const std::string& key, | |
172 | int *shard_id) override; | |
173 | ||
174 | int call(std::optional<RGWSI_MetaBackend_CtxParams> opt, | |
175 | std::function<int(RGWSI_MetaBackend::Context *)> f) override; | |
176 | }; | |
177 | ||
178 | ||
179 | class RGWSI_MetaBackend_Handler_SObj : public RGWSI_MetaBackend_Handler { | |
180 | friend class RGWSI_MetaBackend_SObj::Context_SObj; | |
181 | ||
182 | RGWSI_MBSObj_Handler_Module *module{nullptr}; | |
183 | ||
184 | public: | |
185 | RGWSI_MetaBackend_Handler_SObj(RGWSI_MetaBackend *be) : | |
186 | RGWSI_MetaBackend_Handler(be) {} | |
187 | ||
188 | void set_module(RGWSI_MBSObj_Handler_Module *_module) { | |
189 | module = _module; | |
190 | } | |
191 | ||
192 | RGWSI_MBSObj_Handler_Module *get_module() { | |
193 | return module; | |
194 | } | |
195 | }; |