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