1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2019 Red Hat, Inc.
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
19 #include "rgw_metadata.h"
20 #include "rgw_mdlog_types.h"
22 #include "services/svc_rados.h"
24 #define META_LOG_OBJ_PREFIX "meta.log."
26 struct RGWMetadataLogInfo
{
28 real_time last_update
;
30 void dump(Formatter
*f
) const;
31 void decode_json(JSONObj
*obj
);
34 class RGWCompletionManager
;
36 class RGWMetadataLogInfoCompletion
: public RefCountedObject
{
38 using info_callback_t
= std::function
<void(int, const cls_log_header
&)>;
40 cls_log_header header
;
41 RGWSI_RADOS::Obj io_obj
;
42 librados::AioCompletion
*completion
;
43 std::mutex mutex
; //< protects callback between cancel/complete
44 boost::optional
<info_callback_t
> callback
; //< cleared on cancel
46 explicit RGWMetadataLogInfoCompletion(info_callback_t callback
);
47 ~RGWMetadataLogInfoCompletion() override
;
49 RGWSI_RADOS::Obj
& get_io_obj() { return io_obj
; }
50 cls_log_header
& get_header() { return header
; }
51 librados::AioCompletion
* get_completion() { return completion
; }
53 void finish(librados::completion_t cb
) {
54 std::lock_guard
<std::mutex
> lock(mutex
);
56 (*callback
)(completion
->get_return_value(), header
);
60 std::lock_guard
<std::mutex
> lock(mutex
);
61 callback
= boost::none
;
65 class RGWMetadataLog
{
70 RGWSI_Zone
*zone
{nullptr};
71 RGWSI_Cls
*cls
{nullptr};
74 static std::string
make_prefix(const std::string
& period
) {
76 return META_LOG_OBJ_PREFIX
;
77 return META_LOG_OBJ_PREFIX
+ period
+ ".";
81 set
<int> modified_shards
;
83 void mark_modified(int shard_id
);
85 RGWMetadataLog(CephContext
*_cct
,
86 RGWSI_Zone
*_zone_svc
,
88 const std::string
& period
)
90 prefix(make_prefix(period
)),
91 lock("RGWMetaLog::lock") {
97 void get_shard_oid(int id
, string
& oid
) const {
99 snprintf(buf
, sizeof(buf
), "%d", id
);
103 int add_entry(const DoutPrefixProvider
*dpp
, const string
& hash_key
, const string
& section
, const string
& key
, bufferlist
& bl
);
104 int get_shard_id(const string
& hash_key
, int *shard_id
);
105 int store_entries_in_shard(const DoutPrefixProvider
*dpp
, list
<cls_log_entry
>& entries
, int shard_id
, librados::AioCompletion
*completion
);
117 LogListCtx() : cur_shard(0), done(false) {}
120 void init_list_entries(int shard_id
, const real_time
& from_time
,
121 const real_time
& end_time
, const string
& marker
,
123 void complete_list_entries(void *handle
);
124 int list_entries(const DoutPrefixProvider
*dpp
,
127 list
<cls_log_entry
>& entries
,
131 int trim(const DoutPrefixProvider
*dpp
, int shard_id
, const real_time
& from_time
, const real_time
& end_time
, const string
& start_marker
, const string
& end_marker
);
132 int get_info(const DoutPrefixProvider
*dpp
, int shard_id
, RGWMetadataLogInfo
*info
);
133 int get_info_async(const DoutPrefixProvider
*dpp
, int shard_id
, RGWMetadataLogInfoCompletion
*completion
);
134 int lock_exclusive(const DoutPrefixProvider
*dpp
, int shard_id
, timespan duration
, string
&zone_id
, string
& owner_id
);
135 int unlock(const DoutPrefixProvider
*dpp
, int shard_id
, string
& zone_id
, string
& owner_id
);
137 int update_shards(list
<int>& shards
);
139 void read_clear_modified(set
<int> &modified
);
142 struct LogStatusDump
{
143 RGWMDLogStatus status
;
145 explicit LogStatusDump(RGWMDLogStatus _status
) : status(_status
) {}
146 void dump(Formatter
*f
) const;
149 struct RGWMetadataLogData
{
150 obj_version read_version
;
151 obj_version write_version
;
152 RGWMDLogStatus status
;
154 RGWMetadataLogData() : status(MDLOG_STATUS_UNKNOWN
) {}
156 void encode(bufferlist
& bl
) const;
157 void decode(bufferlist::const_iterator
& bl
);
158 void dump(Formatter
*f
) const;
159 void decode_json(JSONObj
*obj
);
161 WRITE_CLASS_ENCODER(RGWMetadataLogData
)
163 struct RGWMetadataLogHistory
{
164 epoch_t oldest_realm_epoch
;
165 std::string oldest_period_id
;
167 void encode(bufferlist
& bl
) const {
168 ENCODE_START(1, 1, bl
);
169 encode(oldest_realm_epoch
, bl
);
170 encode(oldest_period_id
, bl
);
173 void decode(bufferlist::const_iterator
& p
) {
175 decode(oldest_realm_epoch
, p
);
176 decode(oldest_period_id
, p
);
180 static const std::string oid
;
182 WRITE_CLASS_ENCODER(RGWMetadataLogHistory
)