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