]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_mdlog.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rgw / rgw_mdlog.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2019 Red Hat, Inc.
8 *
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.
13 *
14 */
15
16
17 #pragma once
18
19 #include "common/RWLock.h"
20
21 #include "rgw_metadata.h"
22 #include "rgw_mdlog_types.h"
23
24 #include "services/svc_rados.h"
25
26 #define META_LOG_OBJ_PREFIX "meta.log."
27
28 struct RGWMetadataLogInfo {
29 std::string marker;
30 real_time last_update;
31
32 void dump(Formatter *f) const;
33 void decode_json(JSONObj *obj);
34 };
35
36 class RGWCompletionManager;
37
38 class RGWMetadataLogInfoCompletion : public RefCountedObject {
39 public:
40 using info_callback_t = std::function<void(int, const cls_log_header&)>;
41 private:
42 cls_log_header header;
43 RGWSI_RADOS::Obj io_obj;
44 librados::AioCompletion *completion;
45 std::mutex mutex; //< protects callback between cancel/complete
46 boost::optional<info_callback_t> callback; //< cleared on cancel
47 public:
48 explicit RGWMetadataLogInfoCompletion(info_callback_t callback);
49 ~RGWMetadataLogInfoCompletion() override;
50
51 RGWSI_RADOS::Obj& get_io_obj() { return io_obj; }
52 cls_log_header& get_header() { return header; }
53 librados::AioCompletion* get_completion() { return completion; }
54
55 void finish(librados::completion_t cb) {
56 std::lock_guard<std::mutex> lock(mutex);
57 if (callback) {
58 (*callback)(completion->get_return_value(), header);
59 }
60 }
61 void cancel() {
62 std::lock_guard<std::mutex> lock(mutex);
63 callback = boost::none;
64 }
65 };
66
67 class RGWMetadataLog {
68 CephContext *cct;
69 const std::string prefix;
70
71 struct Svc {
72 RGWSI_Zone *zone{nullptr};
73 RGWSI_Cls *cls{nullptr};
74 } svc;
75
76 static std::string make_prefix(const std::string& period) {
77 if (period.empty())
78 return META_LOG_OBJ_PREFIX;
79 return META_LOG_OBJ_PREFIX + period + ".";
80 }
81
82 RWLock lock;
83 std::set<int> modified_shards;
84
85 void mark_modified(int shard_id);
86 public:
87 RGWMetadataLog(CephContext *_cct,
88 RGWSI_Zone *_zone_svc,
89 RGWSI_Cls *_cls_svc,
90 const std::string& period)
91 : cct(_cct),
92 prefix(make_prefix(period)),
93 lock("RGWMetaLog::lock") {
94 svc.zone = _zone_svc;
95 svc.cls = _cls_svc;
96 }
97
98
99 void get_shard_oid(int id, std::string& oid) const {
100 char buf[16];
101 snprintf(buf, sizeof(buf), "%d", id);
102 oid = prefix + buf;
103 }
104
105 int add_entry(const DoutPrefixProvider *dpp, const std::string& hash_key, const std::string& section, const std::string& key, bufferlist& bl);
106 int get_shard_id(const std::string& hash_key, int *shard_id);
107 int store_entries_in_shard(const DoutPrefixProvider *dpp, std::list<cls_log_entry>& entries, int shard_id, librados::AioCompletion *completion);
108
109 struct LogListCtx {
110 int cur_shard;
111 std::string marker;
112 real_time from_time;
113 real_time end_time;
114
115 std::string cur_oid;
116
117 bool done;
118
119 LogListCtx() : cur_shard(0), done(false) {}
120 };
121
122 void init_list_entries(int shard_id, const real_time& from_time,
123 const real_time& end_time, const std::string& marker,
124 void **handle);
125 void complete_list_entries(void *handle);
126 int list_entries(const DoutPrefixProvider *dpp,
127 void *handle,
128 int max_entries,
129 std::list<cls_log_entry>& entries,
130 std::string *out_marker,
131 bool *truncated);
132
133 int trim(const DoutPrefixProvider *dpp, int shard_id, const real_time& from_time, const real_time& end_time, const std::string& start_marker, const std::string& end_marker);
134 int get_info(const DoutPrefixProvider *dpp, int shard_id, RGWMetadataLogInfo *info);
135 int get_info_async(const DoutPrefixProvider *dpp, int shard_id, RGWMetadataLogInfoCompletion *completion);
136 int lock_exclusive(const DoutPrefixProvider *dpp, int shard_id, timespan duration, std::string&zone_id, std::string& owner_id);
137 int unlock(const DoutPrefixProvider *dpp, int shard_id, std::string& zone_id, std::string& owner_id);
138
139 int update_shards(std::list<int>& shards);
140
141 void read_clear_modified(std::set<int> &modified);
142 };
143
144 struct LogStatusDump {
145 RGWMDLogStatus status;
146
147 explicit LogStatusDump(RGWMDLogStatus _status) : status(_status) {}
148 void dump(Formatter *f) const;
149 };
150
151 struct RGWMetadataLogData {
152 obj_version read_version;
153 obj_version write_version;
154 RGWMDLogStatus status;
155
156 RGWMetadataLogData() : status(MDLOG_STATUS_UNKNOWN) {}
157
158 void encode(bufferlist& bl) const;
159 void decode(bufferlist::const_iterator& bl);
160 void dump(Formatter *f) const;
161 void decode_json(JSONObj *obj);
162 };
163 WRITE_CLASS_ENCODER(RGWMetadataLogData)
164
165 struct RGWMetadataLogHistory {
166 epoch_t oldest_realm_epoch;
167 std::string oldest_period_id;
168
169 void encode(bufferlist& bl) const {
170 ENCODE_START(1, 1, bl);
171 encode(oldest_realm_epoch, bl);
172 encode(oldest_period_id, bl);
173 ENCODE_FINISH(bl);
174 }
175 void decode(bufferlist::const_iterator& p) {
176 DECODE_START(1, p);
177 decode(oldest_realm_epoch, p);
178 decode(oldest_period_id, p);
179 DECODE_FINISH(p);
180 }
181
182 static const std::string oid;
183 };
184 WRITE_CLASS_ENCODER(RGWMetadataLogHistory)
185