]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_bucket_layout.cc
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / rgw / rgw_bucket_layout.cc
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) 2020 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 #include <boost/algorithm/string.hpp>
17 #include "rgw_bucket_layout.h"
18
19 namespace rgw {
20
21 // BucketIndexType
22 std::string_view to_string(const BucketIndexType& t)
23 {
24 switch (t) {
25 case BucketIndexType::Normal: return "Normal";
26 case BucketIndexType::Indexless: return "Indexless";
27 default: return "Unknown";
28 }
29 }
30 bool parse(std::string_view str, BucketIndexType& t)
31 {
32 if (boost::iequals(str, "Normal")) {
33 t = BucketIndexType::Normal;
34 return true;
35 }
36 if (boost::iequals(str, "Indexless")) {
37 t = BucketIndexType::Indexless;
38 return true;
39 }
40 return false;
41 }
42 void encode_json_impl(const char *name, const BucketIndexType& t, ceph::Formatter *f)
43 {
44 encode_json(name, to_string(t), f);
45 }
46 void decode_json_obj(BucketIndexType& t, JSONObj *obj)
47 {
48 std::string str;
49 decode_json_obj(str, obj);
50 parse(str, t);
51 }
52
53 // BucketHashType
54 std::string_view to_string(const BucketHashType& t)
55 {
56 switch (t) {
57 case BucketHashType::Mod: return "Mod";
58 default: return "Unknown";
59 }
60 }
61 bool parse(std::string_view str, BucketHashType& t)
62 {
63 if (boost::iequals(str, "Mod")) {
64 t = BucketHashType::Mod;
65 return true;
66 }
67 return false;
68 }
69 void encode_json_impl(const char *name, const BucketHashType& t, ceph::Formatter *f)
70 {
71 encode_json(name, to_string(t), f);
72 }
73 void decode_json_obj(BucketHashType& t, JSONObj *obj)
74 {
75 std::string str;
76 decode_json_obj(str, obj);
77 parse(str, t);
78 }
79
80 // bucket_index_normal_layout
81 void encode(const bucket_index_normal_layout& l, bufferlist& bl, uint64_t f)
82 {
83 ENCODE_START(1, 1, bl);
84 encode(l.num_shards, bl);
85 encode(l.hash_type, bl);
86 ENCODE_FINISH(bl);
87 }
88 void decode(bucket_index_normal_layout& l, bufferlist::const_iterator& bl)
89 {
90 DECODE_START(1, bl);
91 decode(l.num_shards, bl);
92 decode(l.hash_type, bl);
93 DECODE_FINISH(bl);
94 }
95 void encode_json_impl(const char *name, const bucket_index_normal_layout& l, ceph::Formatter *f)
96 {
97 f->open_object_section(name);
98 encode_json("num_shards", l.num_shards, f);
99 encode_json("hash_type", l.hash_type, f);
100 f->close_section();
101 }
102 void decode_json_obj(bucket_index_normal_layout& l, JSONObj *obj)
103 {
104 JSONDecoder::decode_json("num_shards", l.num_shards, obj);
105 JSONDecoder::decode_json("hash_type", l.hash_type, obj);
106 }
107
108 // bucket_index_layout
109 void encode(const bucket_index_layout& l, bufferlist& bl, uint64_t f)
110 {
111 ENCODE_START(1, 1, bl);
112 encode(l.type, bl);
113 switch (l.type) {
114 case BucketIndexType::Normal:
115 encode(l.normal, bl);
116 break;
117 case BucketIndexType::Indexless:
118 break;
119 }
120 ENCODE_FINISH(bl);
121 }
122 void decode(bucket_index_layout& l, bufferlist::const_iterator& bl)
123 {
124 DECODE_START(1, bl);
125 decode(l.type, bl);
126 switch (l.type) {
127 case BucketIndexType::Normal:
128 decode(l.normal, bl);
129 break;
130 case BucketIndexType::Indexless:
131 break;
132 }
133 DECODE_FINISH(bl);
134 }
135 void encode_json_impl(const char *name, const bucket_index_layout& l, ceph::Formatter *f)
136 {
137 f->open_object_section(name);
138 encode_json("type", l.type, f);
139 encode_json("normal", l.normal, f);
140 f->close_section();
141 }
142 void decode_json_obj(bucket_index_layout& l, JSONObj *obj)
143 {
144 JSONDecoder::decode_json("type", l.type, obj);
145 JSONDecoder::decode_json("normal", l.normal, obj);
146 }
147
148 // bucket_index_layout_generation
149 void encode(const bucket_index_layout_generation& l, bufferlist& bl, uint64_t f)
150 {
151 ENCODE_START(1, 1, bl);
152 encode(l.gen, bl);
153 encode(l.layout, bl);
154 ENCODE_FINISH(bl);
155 }
156 void decode(bucket_index_layout_generation& l, bufferlist::const_iterator& bl)
157 {
158 DECODE_START(1, bl);
159 decode(l.gen, bl);
160 decode(l.layout, bl);
161 DECODE_FINISH(bl);
162 }
163 void encode_json_impl(const char *name, const bucket_index_layout_generation& l, ceph::Formatter *f)
164 {
165 f->open_object_section(name);
166 encode_json("gen", l.gen, f);
167 encode_json("layout", l.layout, f);
168 f->close_section();
169 }
170 void decode_json_obj(bucket_index_layout_generation& l, JSONObj *obj)
171 {
172 JSONDecoder::decode_json("gen", l.gen, obj);
173 JSONDecoder::decode_json("layout", l.layout, obj);
174 }
175
176 // BucketLogType
177 std::string_view to_string(const BucketLogType& t)
178 {
179 switch (t) {
180 case BucketLogType::InIndex: return "InIndex";
181 default: return "Unknown";
182 }
183 }
184 bool parse(std::string_view str, BucketLogType& t)
185 {
186 if (boost::iequals(str, "InIndex")) {
187 t = BucketLogType::InIndex;
188 return true;
189 }
190 return false;
191 }
192 void encode_json_impl(const char *name, const BucketLogType& t, ceph::Formatter *f)
193 {
194 encode_json(name, to_string(t), f);
195 }
196 void decode_json_obj(BucketLogType& t, JSONObj *obj)
197 {
198 std::string str;
199 decode_json_obj(str, obj);
200 parse(str, t);
201 }
202
203 // bucket_index_log_layout
204 void encode(const bucket_index_log_layout& l, bufferlist& bl, uint64_t f)
205 {
206 ENCODE_START(1, 1, bl);
207 encode(l.gen, bl);
208 encode(l.layout, bl);
209 ENCODE_FINISH(bl);
210 }
211 void decode(bucket_index_log_layout& l, bufferlist::const_iterator& bl)
212 {
213 DECODE_START(1, bl);
214 decode(l.gen, bl);
215 decode(l.layout, bl);
216 DECODE_FINISH(bl);
217 }
218 void encode_json_impl(const char *name, const bucket_index_log_layout& l, ceph::Formatter *f)
219 {
220 f->open_object_section(name);
221 encode_json("gen", l.gen, f);
222 encode_json("layout", l.layout, f);
223 f->close_section();
224 }
225 void decode_json_obj(bucket_index_log_layout& l, JSONObj *obj)
226 {
227 JSONDecoder::decode_json("gen", l.gen, obj);
228 JSONDecoder::decode_json("layout", l.layout, obj);
229 }
230
231 // bucket_log_layout
232 void encode(const bucket_log_layout& l, bufferlist& bl, uint64_t f)
233 {
234 ENCODE_START(1, 1, bl);
235 encode(l.type, bl);
236 switch (l.type) {
237 case BucketLogType::InIndex:
238 encode(l.in_index, bl);
239 break;
240 }
241 ENCODE_FINISH(bl);
242 }
243 void decode(bucket_log_layout& l, bufferlist::const_iterator& bl)
244 {
245 DECODE_START(1, bl);
246 decode(l.type, bl);
247 switch (l.type) {
248 case BucketLogType::InIndex:
249 decode(l.in_index, bl);
250 break;
251 }
252 DECODE_FINISH(bl);
253 }
254 void encode_json_impl(const char *name, const bucket_log_layout& l, ceph::Formatter *f)
255 {
256 f->open_object_section(name);
257 encode_json("type", l.type, f);
258 if (l.type == BucketLogType::InIndex) {
259 encode_json("in_index", l.in_index, f);
260 }
261 f->close_section();
262 }
263 void decode_json_obj(bucket_log_layout& l, JSONObj *obj)
264 {
265 JSONDecoder::decode_json("type", l.type, obj);
266 JSONDecoder::decode_json("in_index", l.in_index, obj);
267 }
268
269 // bucket_log_layout_generation
270 void encode(const bucket_log_layout_generation& l, bufferlist& bl, uint64_t f)
271 {
272 ENCODE_START(1, 1, bl);
273 encode(l.gen, bl);
274 encode(l.layout, bl);
275 ENCODE_FINISH(bl);
276 }
277 void decode(bucket_log_layout_generation& l, bufferlist::const_iterator& bl)
278 {
279 DECODE_START(1, bl);
280 decode(l.gen, bl);
281 decode(l.layout, bl);
282 DECODE_FINISH(bl);
283 }
284 void encode_json_impl(const char *name, const bucket_log_layout_generation& l, ceph::Formatter *f)
285 {
286 f->open_object_section(name);
287 encode_json("gen", l.gen, f);
288 encode_json("layout", l.layout, f);
289 f->close_section();
290 }
291 void decode_json_obj(bucket_log_layout_generation& l, JSONObj *obj)
292 {
293 JSONDecoder::decode_json("gen", l.gen, obj);
294 JSONDecoder::decode_json("layout", l.layout, obj);
295 }
296
297 // BucketReshardState
298 std::string_view to_string(const BucketReshardState& s)
299 {
300 switch (s) {
301 case BucketReshardState::None: return "None";
302 case BucketReshardState::InProgress: return "InProgress";
303 default: return "Unknown";
304 }
305 }
306 bool parse(std::string_view str, BucketReshardState& s)
307 {
308 if (boost::iequals(str, "None")) {
309 s = BucketReshardState::None;
310 return true;
311 }
312 if (boost::iequals(str, "InProgress")) {
313 s = BucketReshardState::InProgress;
314 return true;
315 }
316 return false;
317 }
318 void encode_json_impl(const char *name, const BucketReshardState& s, ceph::Formatter *f)
319 {
320 encode_json(name, to_string(s), f);
321 }
322 void decode_json_obj(BucketReshardState& s, JSONObj *obj)
323 {
324 std::string str;
325 decode_json_obj(str, obj);
326 parse(str, s);
327 }
328
329
330 // BucketLayout
331 void encode(const BucketLayout& l, bufferlist& bl, uint64_t f)
332 {
333 ENCODE_START(2, 1, bl);
334 encode(l.resharding, bl);
335 encode(l.current_index, bl);
336 encode(l.target_index, bl);
337 encode(l.logs, bl);
338 ENCODE_FINISH(bl);
339 }
340 void decode(BucketLayout& l, bufferlist::const_iterator& bl)
341 {
342 DECODE_START(2, bl);
343 decode(l.resharding, bl);
344 decode(l.current_index, bl);
345 decode(l.target_index, bl);
346 if (struct_v < 2) {
347 l.logs.clear();
348 // initialize the log layout to match the current index layout
349 if (l.current_index.layout.type == BucketIndexType::Normal) {
350 l.logs.push_back(log_layout_from_index(0, l.current_index));
351 }
352 } else {
353 decode(l.logs, bl);
354 }
355 DECODE_FINISH(bl);
356 }
357 void encode_json_impl(const char *name, const BucketLayout& l, ceph::Formatter *f)
358 {
359 f->open_object_section(name);
360 encode_json("resharding", l.resharding, f);
361 encode_json("current_index", l.current_index, f);
362 if (l.target_index) {
363 encode_json("target_index", *l.target_index, f);
364 }
365 f->open_array_section("logs");
366 for (const auto& log : l.logs) {
367 encode_json("log", log, f);
368 }
369 f->close_section(); // logs[]
370 f->close_section();
371 }
372 void decode_json_obj(BucketLayout& l, JSONObj *obj)
373 {
374 JSONDecoder::decode_json("resharding", l.resharding, obj);
375 JSONDecoder::decode_json("current_index", l.current_index, obj);
376 JSONDecoder::decode_json("target_index", l.target_index, obj);
377 JSONDecoder::decode_json("logs", l.logs, obj);
378 }
379
380 } // namespace rgw