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_METADATA_H
5 #define CEPH_RGW_METADATA_H
9 #include <boost/optional.hpp>
11 #include "include/types.h"
12 #include "rgw_common.h"
13 #include "rgw_period_history.h"
14 #include "rgw_mdlog_types.h"
15 #include "cls/version/cls_version_types.h"
16 #include "cls/log/cls_log_types.h"
17 #include "common/RefCountedObj.h"
18 #include "common/ceph_time.h"
19 #include "services/svc_meta_be.h"
22 namespace rgw
{ namespace sal
{
27 struct RGWObjVersionTracker
;
32 class RGWMetadataObject
{
35 ceph::real_time mtime
;
36 std::map
<string
, bufferlist
> *pattrs
{nullptr};
39 RGWMetadataObject() {}
40 virtual ~RGWMetadataObject() {}
41 obj_version
& get_version();
42 real_time
& get_mtime() { return mtime
; }
43 void set_pattrs(std::map
<string
, bufferlist
> *_pattrs
) {
46 std::map
<string
, bufferlist
> *get_pattrs() {
50 virtual void dump(Formatter
*f
) const {}
53 class RGWMetadataManager
;
55 class RGWMetadataHandler
{
56 friend class RGWMetadataManager
;
62 RGWMetadataHandler() {}
63 virtual ~RGWMetadataHandler() {}
64 virtual string
get_type() = 0;
66 void base_init(CephContext
*_cct
) {
70 virtual RGWMetadataObject
*get_meta_obj(JSONObj
*jo
, const obj_version
& objv
, const ceph::real_time
& mtime
) = 0;
72 virtual int get(string
& entry
, RGWMetadataObject
**obj
, optional_yield
) = 0;
73 virtual int put(string
& entry
,
74 RGWMetadataObject
*obj
,
75 RGWObjVersionTracker
& objv_tracker
,
76 optional_yield
, RGWMDLogSyncType type
,
77 bool from_remote_zone
) = 0;
78 virtual int remove(string
& entry
, RGWObjVersionTracker
& objv_tracker
, optional_yield
) = 0;
80 virtual int mutate(const string
& entry
,
81 const ceph::real_time
& mtime
,
82 RGWObjVersionTracker
*objv_tracker
,
84 RGWMDLogStatus op_type
,
85 std::function
<int()> f
) = 0;
87 virtual int list_keys_init(const string
& marker
, void **phandle
) = 0;
88 virtual int list_keys_next(void *handle
, int max
, list
<string
>& keys
, bool *truncated
) = 0;
89 virtual void list_keys_complete(void *handle
) = 0;
91 virtual string
get_marker(void *handle
) = 0;
93 virtual int get_shard_id(const string
& entry
, int *shard_id
) {
97 virtual int attach(RGWMetadataManager
*manager
);
100 class RGWMetadataHandler_GenericMetaBE
: public RGWMetadataHandler
{
101 friend class RGWSI_MetaBackend
;
102 friend class RGWMetadataManager
;
109 RGWSI_MetaBackend_Handler
*be_handler
;
111 virtual int do_get(RGWSI_MetaBackend_Handler::Op
*op
, string
& entry
, RGWMetadataObject
**obj
, optional_yield y
) = 0;
112 virtual int do_put(RGWSI_MetaBackend_Handler::Op
*op
, string
& entry
, RGWMetadataObject
*obj
,
113 RGWObjVersionTracker
& objv_tracker
, optional_yield y
,
114 RGWMDLogSyncType type
, bool from_remote_zone
) = 0;
115 virtual int do_put_operate(Put
*put_op
);
116 virtual int do_remove(RGWSI_MetaBackend_Handler::Op
*op
, string
& entry
, RGWObjVersionTracker
& objv_tracker
, optional_yield y
) = 0;
119 RGWMetadataHandler_GenericMetaBE() {}
121 void base_init(CephContext
*_cct
,
122 RGWSI_MetaBackend_Handler
*_be_handler
) {
123 RGWMetadataHandler::base_init(_cct
);
124 be_handler
= _be_handler
;
127 RGWSI_MetaBackend_Handler
*get_be_handler() {
133 RGWMetadataHandler_GenericMetaBE
*handler
;
134 RGWSI_MetaBackend_Handler::Op
*op
;
136 RGWMetadataObject
*obj
;
137 RGWObjVersionTracker
& objv_tracker
;
138 RGWMDLogSyncType apply_type
;
140 bool from_remote_zone
{false};
142 int get(RGWMetadataObject
**obj
) {
143 return handler
->do_get(op
, entry
, obj
, y
);
146 Put(RGWMetadataHandler_GenericMetaBE
*_handler
, RGWSI_MetaBackend_Handler::Op
*_op
,
147 string
& _entry
, RGWMetadataObject
*_obj
,
148 RGWObjVersionTracker
& _objv_tracker
, optional_yield _y
,
149 RGWMDLogSyncType _type
, bool from_remote_zone
);
153 virtual int put_pre() {
159 virtual int put_post() {
162 virtual int finalize() {
167 int get(string
& entry
, RGWMetadataObject
**obj
, optional_yield
) override
;
168 int put(string
& entry
, RGWMetadataObject
*obj
, RGWObjVersionTracker
& objv_tracker
, optional_yield
, RGWMDLogSyncType type
, bool from_remote_zone
) override
;
169 int remove(string
& entry
, RGWObjVersionTracker
& objv_tracker
, optional_yield
) override
;
171 int mutate(const string
& entry
,
172 const ceph::real_time
& mtime
,
173 RGWObjVersionTracker
*objv_tracker
,
175 RGWMDLogStatus op_type
,
176 std::function
<int()> f
) override
;
178 int get_shard_id(const string
& entry
, int *shard_id
) override
;
180 int list_keys_init(const std::string
& marker
, void **phandle
) override
;
181 int list_keys_next(void *handle
, int max
, std::list
<string
>& keys
, bool *truncated
) override
;
182 void list_keys_complete(void *handle
) override
;
184 std::string
get_marker(void *handle
) override
;
187 * Compare an incoming versus on-disk tag/version+mtime combo against
188 * the sync mode to see if the new one should replace the on-disk one.
190 * @return true if the update should proceed, false otherwise.
192 static bool check_versions(bool exists
,
193 const obj_version
& ondisk
, const real_time
& ondisk_time
,
194 const obj_version
& incoming
, const real_time
& incoming_time
,
195 RGWMDLogSyncType sync_mode
) {
198 if ((ondisk
.tag
!= incoming
.tag
) ||
199 (ondisk
.ver
>= incoming
.ver
))
203 if (ondisk_time
>= incoming_time
)
206 case APPLY_EXCLUSIVE
:
210 case APPLY_ALWAYS
: //deliberate fall-thru -- we always apply!
217 class RGWMetadataTopHandler
;
219 class RGWMetadataManager
{
220 friend class RGWMetadataHandler
;
223 RGWSI_Meta
*meta_svc
;
224 map
<string
, RGWMetadataHandler
*> handlers
;
225 std::unique_ptr
<RGWMetadataTopHandler
> md_top_handler
;
227 int find_handler(const string
& metadata_key
, RGWMetadataHandler
**handler
, string
& entry
);
228 int register_handler(RGWMetadataHandler
*handler
);
231 RGWMetadataManager(RGWSI_Meta
*_meta_svc
);
232 ~RGWMetadataManager();
234 RGWMetadataHandler
*get_handler(const string
& type
);
236 int get(string
& metadata_key
, Formatter
*f
, optional_yield y
);
237 int put(string
& metadata_key
, bufferlist
& bl
, optional_yield y
,
238 RGWMDLogSyncType sync_mode
,
239 bool from_remote_zone
,
240 obj_version
*existing_version
= NULL
);
241 int remove(string
& metadata_key
, optional_yield y
);
243 int mutate(const string
& metadata_key
,
244 const ceph::real_time
& mtime
,
245 RGWObjVersionTracker
*objv_tracker
,
247 RGWMDLogStatus op_type
,
248 std::function
<int()> f
);
250 int list_keys_init(const string
& section
, void **phandle
);
251 int list_keys_init(const string
& section
, const string
& marker
, void **phandle
);
252 int list_keys_next(void *handle
, int max
, list
<string
>& keys
, bool *truncated
);
253 void list_keys_complete(void *handle
);
255 string
get_marker(void *handle
);
257 void dump_log_entry(cls_log_entry
& entry
, Formatter
*f
);
259 void get_sections(list
<string
>& sections
);
261 void parse_metadata_key(const string
& metadata_key
, string
& type
, string
& entry
);
263 int get_shard_id(const string
& section
, const string
& key
, int *shard_id
);
266 class RGWMetadataHandlerPut_SObj
: public RGWMetadataHandler_GenericMetaBE::Put
269 std::unique_ptr
<RGWMetadataObject
> oo
;
270 RGWMetadataObject
*old_obj
{nullptr};
274 RGWMetadataHandlerPut_SObj(RGWMetadataHandler_GenericMetaBE
*handler
, RGWSI_MetaBackend_Handler::Op
*op
,
275 string
& entry
, RGWMetadataObject
*obj
, RGWObjVersionTracker
& objv_tracker
,
277 RGWMDLogSyncType type
, bool from_remote_zone
);
278 ~RGWMetadataHandlerPut_SObj();
280 int put_pre() override
;
282 virtual int put_check() {
285 virtual int put_checked();
286 virtual void encode_obj(bufferlist
*bl
) {}