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) 2020 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.
16 #include <boost/algorithm/string.hpp>
17 #include "rgw_bucket_layout.h"
22 std::string_view
to_string(const BucketIndexType
& t
)
25 case BucketIndexType::Normal
: return "Normal";
26 case BucketIndexType::Indexless
: return "Indexless";
27 default: return "Unknown";
30 bool parse(std::string_view str
, BucketIndexType
& t
)
32 if (boost::iequals(str
, "Normal")) {
33 t
= BucketIndexType::Normal
;
36 if (boost::iequals(str
, "Indexless")) {
37 t
= BucketIndexType::Indexless
;
42 void encode_json_impl(const char *name
, const BucketIndexType
& t
, ceph::Formatter
*f
)
44 encode_json(name
, to_string(t
), f
);
46 void decode_json_obj(BucketIndexType
& t
, JSONObj
*obj
)
49 decode_json_obj(str
, obj
);
54 std::string_view
to_string(const BucketHashType
& t
)
57 case BucketHashType::Mod
: return "Mod";
58 default: return "Unknown";
61 bool parse(std::string_view str
, BucketHashType
& t
)
63 if (boost::iequals(str
, "Mod")) {
64 t
= BucketHashType::Mod
;
69 void encode_json_impl(const char *name
, const BucketHashType
& t
, ceph::Formatter
*f
)
71 encode_json(name
, to_string(t
), f
);
73 void decode_json_obj(BucketHashType
& t
, JSONObj
*obj
)
76 decode_json_obj(str
, obj
);
80 // bucket_index_normal_layout
81 void encode(const bucket_index_normal_layout
& l
, bufferlist
& bl
, uint64_t f
)
83 ENCODE_START(1, 1, bl
);
84 encode(l
.num_shards
, bl
);
85 encode(l
.hash_type
, bl
);
88 void decode(bucket_index_normal_layout
& l
, bufferlist::const_iterator
& bl
)
91 decode(l
.num_shards
, bl
);
92 decode(l
.hash_type
, bl
);
95 void encode_json_impl(const char *name
, const bucket_index_normal_layout
& l
, ceph::Formatter
*f
)
97 f
->open_object_section(name
);
98 encode_json("num_shards", l
.num_shards
, f
);
99 encode_json("hash_type", l
.hash_type
, f
);
102 void decode_json_obj(bucket_index_normal_layout
& l
, JSONObj
*obj
)
104 JSONDecoder::decode_json("num_shards", l
.num_shards
, obj
);
105 JSONDecoder::decode_json("hash_type", l
.hash_type
, obj
);
108 // bucket_index_layout
109 void encode(const bucket_index_layout
& l
, bufferlist
& bl
, uint64_t f
)
111 ENCODE_START(1, 1, bl
);
114 case BucketIndexType::Normal
:
115 encode(l
.normal
, bl
);
117 case BucketIndexType::Indexless
:
122 void decode(bucket_index_layout
& l
, bufferlist::const_iterator
& bl
)
127 case BucketIndexType::Normal
:
128 decode(l
.normal
, bl
);
130 case BucketIndexType::Indexless
:
135 void encode_json_impl(const char *name
, const bucket_index_layout
& l
, ceph::Formatter
*f
)
137 f
->open_object_section(name
);
138 encode_json("type", l
.type
, f
);
139 encode_json("normal", l
.normal
, f
);
142 void decode_json_obj(bucket_index_layout
& l
, JSONObj
*obj
)
144 JSONDecoder::decode_json("type", l
.type
, obj
);
145 JSONDecoder::decode_json("normal", l
.normal
, obj
);
148 // bucket_index_layout_generation
149 void encode(const bucket_index_layout_generation
& l
, bufferlist
& bl
, uint64_t f
)
151 ENCODE_START(1, 1, bl
);
153 encode(l
.layout
, bl
);
156 void decode(bucket_index_layout_generation
& l
, bufferlist::const_iterator
& bl
)
160 decode(l
.layout
, bl
);
163 void encode_json_impl(const char *name
, const bucket_index_layout_generation
& l
, ceph::Formatter
*f
)
165 f
->open_object_section(name
);
166 encode_json("gen", l
.gen
, f
);
167 encode_json("layout", l
.layout
, f
);
170 void decode_json_obj(bucket_index_layout_generation
& l
, JSONObj
*obj
)
172 JSONDecoder::decode_json("gen", l
.gen
, obj
);
173 JSONDecoder::decode_json("layout", l
.layout
, obj
);
177 std::string_view
to_string(const BucketLogType
& t
)
180 case BucketLogType::InIndex
: return "InIndex";
181 default: return "Unknown";
184 bool parse(std::string_view str
, BucketLogType
& t
)
186 if (boost::iequals(str
, "InIndex")) {
187 t
= BucketLogType::InIndex
;
192 void encode_json_impl(const char *name
, const BucketLogType
& t
, ceph::Formatter
*f
)
194 encode_json(name
, to_string(t
), f
);
196 void decode_json_obj(BucketLogType
& t
, JSONObj
*obj
)
199 decode_json_obj(str
, obj
);
203 // bucket_index_log_layout
204 void encode(const bucket_index_log_layout
& l
, bufferlist
& bl
, uint64_t f
)
206 ENCODE_START(1, 1, bl
);
208 encode(l
.layout
, bl
);
211 void decode(bucket_index_log_layout
& l
, bufferlist::const_iterator
& bl
)
215 decode(l
.layout
, bl
);
218 void encode_json_impl(const char *name
, const bucket_index_log_layout
& l
, ceph::Formatter
*f
)
220 f
->open_object_section(name
);
221 encode_json("gen", l
.gen
, f
);
222 encode_json("layout", l
.layout
, f
);
225 void decode_json_obj(bucket_index_log_layout
& l
, JSONObj
*obj
)
227 JSONDecoder::decode_json("gen", l
.gen
, obj
);
228 JSONDecoder::decode_json("layout", l
.layout
, obj
);
232 void encode(const bucket_log_layout
& l
, bufferlist
& bl
, uint64_t f
)
234 ENCODE_START(1, 1, bl
);
237 case BucketLogType::InIndex
:
238 encode(l
.in_index
, bl
);
243 void decode(bucket_log_layout
& l
, bufferlist::const_iterator
& bl
)
248 case BucketLogType::InIndex
:
249 decode(l
.in_index
, bl
);
254 void encode_json_impl(const char *name
, const bucket_log_layout
& l
, ceph::Formatter
*f
)
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
);
263 void decode_json_obj(bucket_log_layout
& l
, JSONObj
*obj
)
265 JSONDecoder::decode_json("type", l
.type
, obj
);
266 JSONDecoder::decode_json("in_index", l
.in_index
, obj
);
269 // bucket_log_layout_generation
270 void encode(const bucket_log_layout_generation
& l
, bufferlist
& bl
, uint64_t f
)
272 ENCODE_START(1, 1, bl
);
274 encode(l
.layout
, bl
);
277 void decode(bucket_log_layout_generation
& l
, bufferlist::const_iterator
& bl
)
281 decode(l
.layout
, bl
);
284 void encode_json_impl(const char *name
, const bucket_log_layout_generation
& l
, ceph::Formatter
*f
)
286 f
->open_object_section(name
);
287 encode_json("gen", l
.gen
, f
);
288 encode_json("layout", l
.layout
, f
);
291 void decode_json_obj(bucket_log_layout_generation
& l
, JSONObj
*obj
)
293 JSONDecoder::decode_json("gen", l
.gen
, obj
);
294 JSONDecoder::decode_json("layout", l
.layout
, obj
);
297 // BucketReshardState
298 std::string_view
to_string(const BucketReshardState
& s
)
301 case BucketReshardState::None
: return "None";
302 case BucketReshardState::InProgress
: return "InProgress";
303 default: return "Unknown";
306 bool parse(std::string_view str
, BucketReshardState
& s
)
308 if (boost::iequals(str
, "None")) {
309 s
= BucketReshardState::None
;
312 if (boost::iequals(str
, "InProgress")) {
313 s
= BucketReshardState::InProgress
;
318 void encode_json_impl(const char *name
, const BucketReshardState
& s
, ceph::Formatter
*f
)
320 encode_json(name
, to_string(s
), f
);
322 void decode_json_obj(BucketReshardState
& s
, JSONObj
*obj
)
325 decode_json_obj(str
, obj
);
331 void encode(const BucketLayout
& l
, bufferlist
& bl
, uint64_t f
)
333 ENCODE_START(2, 1, bl
);
334 encode(l
.resharding
, bl
);
335 encode(l
.current_index
, bl
);
336 encode(l
.target_index
, bl
);
340 void decode(BucketLayout
& l
, bufferlist::const_iterator
& bl
)
343 decode(l
.resharding
, bl
);
344 decode(l
.current_index
, bl
);
345 decode(l
.target_index
, bl
);
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
));
357 void encode_json_impl(const char *name
, const BucketLayout
& l
, ceph::Formatter
*f
)
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
);
365 f
->open_array_section("logs");
366 for (const auto& log
: l
.logs
) {
367 encode_json("log", log
, f
);
369 f
->close_section(); // logs[]
372 void decode_json_obj(BucketLayout
& l
, JSONObj
*obj
)
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
);