]>
Commit | Line | Data |
---|---|---|
f64942e4 AA |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
522d829b | 4 | #pragma once |
7c673cae | 5 | |
20effc67 | 6 | #include <string> |
1e59de90 | 7 | #include <list> |
9f95a23c | 8 | #include <boost/container/flat_map.hpp> |
7c673cae FG |
9 | #include "common/ceph_time.h" |
10 | #include "common/Formatter.h" | |
11 | ||
522d829b TL |
12 | #include <fmt/format.h> |
13 | ||
7c673cae FG |
14 | #include "rgw/rgw_basic_types.h" |
15 | ||
1e59de90 TL |
16 | #define CEPH_RGW_REMOVE 'r' // value 114 |
17 | #define CEPH_RGW_UPDATE 'u' // value 117 | |
7c673cae FG |
18 | #define CEPH_RGW_DIR_SUGGEST_LOG_OP 0x80 |
19 | #define CEPH_RGW_DIR_SUGGEST_OP_MASK 0x7f | |
20 | ||
1e59de90 TL |
21 | constexpr uint64_t CEPH_RGW_DEFAULT_TAG_TIMEOUT = 120; // in seconds |
22 | ||
7c673cae FG |
23 | class JSONObj; |
24 | ||
11fdf7f2 | 25 | using ceph::operator <<; |
7c673cae | 26 | |
9f95a23c | 27 | struct rgw_zone_set_entry { |
f67539c2 | 28 | std::string zone; |
9f95a23c TL |
29 | std::optional<std::string> location_key; |
30 | ||
31 | bool operator<(const rgw_zone_set_entry& e) const { | |
32 | if (zone < e.zone) { | |
33 | return true; | |
34 | } | |
35 | if (zone > e.zone) { | |
36 | return false; | |
37 | } | |
38 | return (location_key < e.location_key); | |
39 | } | |
40 | ||
1e59de90 TL |
41 | bool operator==(const rgw_zone_set_entry& e) const { |
42 | return zone == e.zone && location_key == e.location_key; | |
43 | } | |
44 | ||
9f95a23c | 45 | rgw_zone_set_entry() {} |
f67539c2 | 46 | rgw_zone_set_entry(const std::string& _zone, |
9f95a23c TL |
47 | std::optional<std::string> _location_key) : zone(_zone), |
48 | location_key(_location_key) {} | |
f67539c2 | 49 | rgw_zone_set_entry(const std::string& s) { |
9f95a23c TL |
50 | from_str(s); |
51 | } | |
52 | ||
f67539c2 TL |
53 | void from_str(const std::string& s); |
54 | std::string to_str() const; | |
9f95a23c | 55 | |
f67539c2 TL |
56 | void encode(ceph::buffer::list &bl) const; |
57 | void decode(ceph::buffer::list::const_iterator &bl); | |
9f95a23c | 58 | |
f67539c2 | 59 | void dump(ceph::Formatter *f) const; |
9f95a23c TL |
60 | void decode_json(JSONObj *obj); |
61 | }; | |
62 | WRITE_CLASS_ENCODER(rgw_zone_set_entry) | |
63 | ||
64 | struct rgw_zone_set { | |
65 | std::set<rgw_zone_set_entry> entries; | |
66 | ||
f67539c2 | 67 | void encode(ceph::buffer::list &bl) const { |
9f95a23c TL |
68 | /* no ENCODE_START, ENCODE_END for backward compatibility */ |
69 | ceph::encode(entries, bl); | |
70 | } | |
f67539c2 | 71 | void decode(ceph::buffer::list::const_iterator &bl) { |
9f95a23c TL |
72 | /* no DECODE_START, DECODE_END for backward compatibility */ |
73 | ceph::decode(entries, bl); | |
74 | } | |
75 | ||
f67539c2 TL |
76 | void insert(const std::string& zone, std::optional<std::string> location_key); |
77 | bool exists(const std::string& zone, std::optional<std::string> location_key) const; | |
9f95a23c TL |
78 | }; |
79 | WRITE_CLASS_ENCODER(rgw_zone_set) | |
80 | ||
81 | /* backward compatibility, rgw_zone_set needs to encode/decode the same as std::set */ | |
82 | void encode_json(const char *name, const rgw_zone_set& zs, ceph::Formatter *f); | |
83 | void decode_json_obj(rgw_zone_set& zs, JSONObj *obj); | |
84 | ||
31f18b77 | 85 | |
7c673cae FG |
86 | enum RGWPendingState { |
87 | CLS_RGW_STATE_PENDING_MODIFY = 0, | |
88 | CLS_RGW_STATE_COMPLETE = 1, | |
89 | CLS_RGW_STATE_UNKNOWN = 2, | |
90 | }; | |
91 | ||
92 | enum RGWModifyOp { | |
93 | CLS_RGW_OP_ADD = 0, | |
94 | CLS_RGW_OP_DEL = 1, | |
95 | CLS_RGW_OP_CANCEL = 2, | |
96 | CLS_RGW_OP_UNKNOWN = 3, | |
97 | CLS_RGW_OP_LINK_OLH = 4, | |
98 | CLS_RGW_OP_LINK_OLH_DM = 5, /* creation of delete marker */ | |
99 | CLS_RGW_OP_UNLINK_INSTANCE = 6, | |
c07f9fc5 FG |
100 | CLS_RGW_OP_SYNCSTOP = 7, |
101 | CLS_RGW_OP_RESYNC = 8, | |
7c673cae FG |
102 | }; |
103 | ||
20effc67 TL |
104 | std::string_view to_string(RGWModifyOp op); |
105 | RGWModifyOp parse_modify_op(std::string_view name); | |
106 | ||
107 | inline std::ostream& operator<<(std::ostream& out, RGWModifyOp op) { | |
108 | return out << to_string(op); | |
109 | } | |
110 | ||
7c673cae FG |
111 | enum RGWBILogFlags { |
112 | RGW_BILOG_FLAG_VERSIONED_OP = 0x1, | |
113 | }; | |
114 | ||
115 | enum RGWCheckMTimeType { | |
116 | CLS_RGW_CHECK_TIME_MTIME_EQ = 0, | |
117 | CLS_RGW_CHECK_TIME_MTIME_LT = 1, | |
118 | CLS_RGW_CHECK_TIME_MTIME_LE = 2, | |
119 | CLS_RGW_CHECK_TIME_MTIME_GT = 3, | |
120 | CLS_RGW_CHECK_TIME_MTIME_GE = 4, | |
121 | }; | |
122 | ||
123 | #define ROUND_BLOCK_SIZE 4096 | |
124 | ||
f67539c2 | 125 | inline uint64_t cls_rgw_get_rounded_size(uint64_t size) { |
7c673cae FG |
126 | return (size + ROUND_BLOCK_SIZE - 1) & ~(ROUND_BLOCK_SIZE - 1); |
127 | } | |
128 | ||
9f95a23c | 129 | /* |
f67539c2 | 130 | * This takes a std::string that either wholly contains a delimiter or is a |
9f95a23c TL |
131 | * path that ends with a delimiter and appends a new character to the |
132 | * end such that when a we request bucket-index entries *after* this, | |
133 | * we'll get the next object after the "subdirectory". This works | |
134 | * because we append a '\xFF' charater, and no valid UTF-8 character | |
135 | * can contain that byte, so no valid entries can be skipped. | |
136 | */ | |
f67539c2 | 137 | inline std::string cls_rgw_after_delim(const std::string& path) { |
9f95a23c TL |
138 | // assert: ! path.empty() |
139 | return path + '\xFF'; | |
140 | } | |
141 | ||
7c673cae FG |
142 | struct rgw_bucket_pending_info { |
143 | RGWPendingState state; | |
144 | ceph::real_time timestamp; | |
145 | uint8_t op; | |
146 | ||
147 | rgw_bucket_pending_info() : state(CLS_RGW_STATE_PENDING_MODIFY), op(0) {} | |
148 | ||
f67539c2 | 149 | void encode(ceph::buffer::list &bl) const { |
7c673cae FG |
150 | ENCODE_START(2, 2, bl); |
151 | uint8_t s = (uint8_t)state; | |
11fdf7f2 TL |
152 | encode(s, bl); |
153 | encode(timestamp, bl); | |
154 | encode(op, bl); | |
7c673cae FG |
155 | ENCODE_FINISH(bl); |
156 | } | |
f67539c2 | 157 | void decode(ceph::buffer::list::const_iterator &bl) { |
7c673cae FG |
158 | DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); |
159 | uint8_t s; | |
11fdf7f2 | 160 | decode(s, bl); |
7c673cae | 161 | state = (RGWPendingState)s; |
11fdf7f2 TL |
162 | decode(timestamp, bl); |
163 | decode(op, bl); | |
7c673cae FG |
164 | DECODE_FINISH(bl); |
165 | } | |
f67539c2 | 166 | void dump(ceph::Formatter *f) const; |
7c673cae | 167 | void decode_json(JSONObj *obj); |
f67539c2 | 168 | static void generate_test_instances(std::list<rgw_bucket_pending_info*>& o); |
7c673cae FG |
169 | }; |
170 | WRITE_CLASS_ENCODER(rgw_bucket_pending_info) | |
171 | ||
11fdf7f2 TL |
172 | |
173 | // categories of objects stored in a bucket index (b-i) and used to | |
174 | // differentiate their associated statistics (bucket stats, and in | |
175 | // some cases user stats) | |
176 | enum class RGWObjCategory : uint8_t { | |
177 | None = 0, // b-i entries for delete markers; also used in | |
178 | // testing and for default values in default | |
179 | // constructors | |
180 | ||
181 | Main = 1, // b-i entries for standard objs | |
182 | ||
183 | Shadow = 2, // presumfably intended for multipart shadow | |
184 | // uploads; not currently used in the codebase | |
185 | ||
186 | MultiMeta = 3, // b-i entries for multipart upload metadata objs | |
20effc67 TL |
187 | |
188 | CloudTiered = 4, // b-i entries which are tiered to external cloud | |
11fdf7f2 TL |
189 | }; |
190 | ||
20effc67 TL |
191 | std::string_view to_string(RGWObjCategory c); |
192 | ||
193 | inline std::ostream& operator<<(std::ostream& out, RGWObjCategory c) { | |
194 | return out << to_string(c); | |
195 | } | |
11fdf7f2 | 196 | |
7c673cae | 197 | struct rgw_bucket_dir_entry_meta { |
11fdf7f2 | 198 | RGWObjCategory category; |
7c673cae FG |
199 | uint64_t size; |
200 | ceph::real_time mtime; | |
f67539c2 TL |
201 | std::string etag; |
202 | std::string owner; | |
203 | std::string owner_display_name; | |
204 | std::string content_type; | |
7c673cae | 205 | uint64_t accounted_size; |
f67539c2 TL |
206 | std::string user_data; |
207 | std::string storage_class; | |
11fdf7f2 | 208 | bool appendable; |
7c673cae FG |
209 | |
210 | rgw_bucket_dir_entry_meta() : | |
11fdf7f2 | 211 | category(RGWObjCategory::None), size(0), accounted_size(0), appendable(false) { } |
7c673cae | 212 | |
f67539c2 | 213 | void encode(ceph::buffer::list &bl) const { |
11fdf7f2 TL |
214 | ENCODE_START(7, 3, bl); |
215 | encode(category, bl); | |
216 | encode(size, bl); | |
217 | encode(mtime, bl); | |
218 | encode(etag, bl); | |
219 | encode(owner, bl); | |
220 | encode(owner_display_name, bl); | |
221 | encode(content_type, bl); | |
222 | encode(accounted_size, bl); | |
223 | encode(user_data, bl); | |
224 | encode(storage_class, bl); | |
225 | encode(appendable, bl); | |
7c673cae FG |
226 | ENCODE_FINISH(bl); |
227 | } | |
11fdf7f2 | 228 | |
f67539c2 | 229 | void decode(ceph::buffer::list::const_iterator &bl) { |
11fdf7f2 TL |
230 | DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl); |
231 | decode(category, bl); | |
232 | decode(size, bl); | |
233 | decode(mtime, bl); | |
234 | decode(etag, bl); | |
235 | decode(owner, bl); | |
236 | decode(owner_display_name, bl); | |
7c673cae | 237 | if (struct_v >= 2) |
11fdf7f2 | 238 | decode(content_type, bl); |
7c673cae | 239 | if (struct_v >= 4) |
11fdf7f2 | 240 | decode(accounted_size, bl); |
7c673cae FG |
241 | else |
242 | accounted_size = size; | |
243 | if (struct_v >= 5) | |
11fdf7f2 TL |
244 | decode(user_data, bl); |
245 | if (struct_v >= 6) | |
246 | decode(storage_class, bl); | |
247 | if (struct_v >= 7) | |
248 | decode(appendable, bl); | |
7c673cae FG |
249 | DECODE_FINISH(bl); |
250 | } | |
f67539c2 | 251 | void dump(ceph::Formatter *f) const; |
7c673cae | 252 | void decode_json(JSONObj *obj); |
f67539c2 | 253 | static void generate_test_instances(std::list<rgw_bucket_dir_entry_meta*>& o); |
7c673cae FG |
254 | }; |
255 | WRITE_CLASS_ENCODER(rgw_bucket_dir_entry_meta) | |
256 | ||
257 | template<class T> | |
f67539c2 | 258 | void encode_packed_val(T val, ceph::buffer::list& bl) |
7c673cae | 259 | { |
11fdf7f2 | 260 | using ceph::encode; |
7c673cae | 261 | if ((uint64_t)val < 0x80) { |
11fdf7f2 | 262 | encode((uint8_t)val, bl); |
7c673cae FG |
263 | } else { |
264 | unsigned char c = 0x80; | |
265 | ||
266 | if ((uint64_t)val < 0x100) { | |
267 | c |= 1; | |
11fdf7f2 TL |
268 | encode(c, bl); |
269 | encode((uint8_t)val, bl); | |
7c673cae FG |
270 | } else if ((uint64_t)val <= 0x10000) { |
271 | c |= 2; | |
11fdf7f2 TL |
272 | encode(c, bl); |
273 | encode((uint16_t)val, bl); | |
7c673cae FG |
274 | } else if ((uint64_t)val <= 0x1000000) { |
275 | c |= 4; | |
11fdf7f2 TL |
276 | encode(c, bl); |
277 | encode((uint32_t)val, bl); | |
7c673cae FG |
278 | } else { |
279 | c |= 8; | |
11fdf7f2 TL |
280 | encode(c, bl); |
281 | encode((uint64_t)val, bl); | |
7c673cae FG |
282 | } |
283 | } | |
284 | } | |
285 | ||
286 | template<class T> | |
f67539c2 | 287 | void decode_packed_val(T& val, ceph::buffer::list::const_iterator& bl) |
7c673cae | 288 | { |
11fdf7f2 | 289 | using ceph::decode; |
7c673cae | 290 | unsigned char c; |
11fdf7f2 | 291 | decode(c, bl); |
7c673cae FG |
292 | if (c < 0x80) { |
293 | val = c; | |
294 | return; | |
295 | } | |
296 | ||
297 | c &= ~0x80; | |
298 | ||
299 | switch (c) { | |
300 | case 1: | |
301 | { | |
302 | uint8_t v; | |
11fdf7f2 | 303 | decode(v, bl); |
7c673cae FG |
304 | val = v; |
305 | } | |
306 | break; | |
307 | case 2: | |
308 | { | |
309 | uint16_t v; | |
11fdf7f2 | 310 | decode(v, bl); |
7c673cae FG |
311 | val = v; |
312 | } | |
313 | break; | |
314 | case 4: | |
315 | { | |
316 | uint32_t v; | |
11fdf7f2 | 317 | decode(v, bl); |
7c673cae FG |
318 | val = v; |
319 | } | |
320 | break; | |
321 | case 8: | |
322 | { | |
323 | uint64_t v; | |
11fdf7f2 | 324 | decode(v, bl); |
7c673cae FG |
325 | val = v; |
326 | } | |
327 | break; | |
328 | default: | |
f67539c2 | 329 | throw ceph::buffer::malformed_input(); |
7c673cae FG |
330 | } |
331 | } | |
332 | ||
333 | struct rgw_bucket_entry_ver { | |
334 | int64_t pool; | |
335 | uint64_t epoch; | |
336 | ||
337 | rgw_bucket_entry_ver() : pool(-1), epoch(0) {} | |
338 | ||
f67539c2 | 339 | void encode(ceph::buffer::list &bl) const { |
7c673cae | 340 | ENCODE_START(1, 1, bl); |
11fdf7f2 TL |
341 | encode_packed_val(pool, bl); |
342 | encode_packed_val(epoch, bl); | |
7c673cae FG |
343 | ENCODE_FINISH(bl); |
344 | } | |
f67539c2 | 345 | void decode(ceph::buffer::list::const_iterator &bl) { |
7c673cae | 346 | DECODE_START(1, bl); |
11fdf7f2 TL |
347 | decode_packed_val(pool, bl); |
348 | decode_packed_val(epoch, bl); | |
7c673cae FG |
349 | DECODE_FINISH(bl); |
350 | } | |
f67539c2 | 351 | void dump(ceph::Formatter *f) const; |
7c673cae | 352 | void decode_json(JSONObj *obj); |
f67539c2 | 353 | static void generate_test_instances(std::list<rgw_bucket_entry_ver*>& o); |
7c673cae FG |
354 | }; |
355 | WRITE_CLASS_ENCODER(rgw_bucket_entry_ver) | |
356 | ||
1e59de90 | 357 | typedef rgw_obj_index_key cls_rgw_obj_key; |
7c673cae | 358 | |
20effc67 TL |
359 | inline std::ostream& operator<<(std::ostream& out, const cls_rgw_obj_key& o) { |
360 | out << o.name; | |
361 | if (!o.instance.empty()) { | |
362 | out << '[' << o.instance << ']'; | |
363 | } | |
364 | return out; | |
365 | } | |
7c673cae | 366 | |
7c673cae | 367 | struct rgw_bucket_dir_entry { |
9f95a23c TL |
368 | /* a versioned object instance */ |
369 | static constexpr uint16_t FLAG_VER = 0x1; | |
370 | /* the last object instance of a versioned object */ | |
371 | static constexpr uint16_t FLAG_CURRENT = 0x2; | |
372 | /* delete marker */ | |
373 | static constexpr uint16_t FLAG_DELETE_MARKER = 0x4; | |
374 | /* object is versioned, a placeholder for the plain entry */ | |
375 | static constexpr uint16_t FLAG_VER_MARKER = 0x8; | |
376 | /* object is a proxy; it is not listed in the bucket index but is a | |
377 | * prefix ending with a delimiter, perhaps common to multiple | |
378 | * entries; it is only useful when a delimiter is used and | |
379 | * represents a "subdirectory" (again, ending in a delimiter) that | |
380 | * may contain one or more actual entries/objects */ | |
381 | static constexpr uint16_t FLAG_COMMON_PREFIX = 0x8000; | |
382 | ||
7c673cae FG |
383 | cls_rgw_obj_key key; |
384 | rgw_bucket_entry_ver ver; | |
385 | std::string locator; | |
386 | bool exists; | |
11fdf7f2 | 387 | rgw_bucket_dir_entry_meta meta; |
f67539c2 | 388 | std::multimap<std::string, rgw_bucket_pending_info> pending_map; |
7c673cae | 389 | uint64_t index_ver; |
f67539c2 | 390 | std::string tag; |
7c673cae FG |
391 | uint16_t flags; |
392 | uint64_t versioned_epoch; | |
393 | ||
394 | rgw_bucket_dir_entry() : | |
395 | exists(false), index_ver(0), flags(0), versioned_epoch(0) {} | |
396 | ||
f67539c2 | 397 | void encode(ceph::buffer::list &bl) const { |
7c673cae | 398 | ENCODE_START(8, 3, bl); |
11fdf7f2 TL |
399 | encode(key.name, bl); |
400 | encode(ver.epoch, bl); | |
401 | encode(exists, bl); | |
402 | encode(meta, bl); | |
403 | encode(pending_map, bl); | |
404 | encode(locator, bl); | |
405 | encode(ver, bl); | |
406 | encode_packed_val(index_ver, bl); | |
407 | encode(tag, bl); | |
408 | encode(key.instance, bl); | |
409 | encode(flags, bl); | |
410 | encode(versioned_epoch, bl); | |
7c673cae FG |
411 | ENCODE_FINISH(bl); |
412 | } | |
f67539c2 | 413 | void decode(ceph::buffer::list::const_iterator &bl) { |
7c673cae | 414 | DECODE_START_LEGACY_COMPAT_LEN(8, 3, 3, bl); |
11fdf7f2 TL |
415 | decode(key.name, bl); |
416 | decode(ver.epoch, bl); | |
417 | decode(exists, bl); | |
418 | decode(meta, bl); | |
419 | decode(pending_map, bl); | |
7c673cae | 420 | if (struct_v >= 2) { |
11fdf7f2 | 421 | decode(locator, bl); |
7c673cae FG |
422 | } |
423 | if (struct_v >= 4) { | |
11fdf7f2 | 424 | decode(ver, bl); |
7c673cae FG |
425 | } else { |
426 | ver.pool = -1; | |
427 | } | |
428 | if (struct_v >= 5) { | |
11fdf7f2 TL |
429 | decode_packed_val(index_ver, bl); |
430 | decode(tag, bl); | |
7c673cae FG |
431 | } |
432 | if (struct_v >= 6) { | |
11fdf7f2 | 433 | decode(key.instance, bl); |
7c673cae FG |
434 | } |
435 | if (struct_v >= 7) { | |
11fdf7f2 | 436 | decode(flags, bl); |
7c673cae FG |
437 | } |
438 | if (struct_v >= 8) { | |
11fdf7f2 | 439 | decode(versioned_epoch, bl); |
7c673cae FG |
440 | } |
441 | DECODE_FINISH(bl); | |
442 | } | |
443 | ||
9f95a23c TL |
444 | bool is_current() const { |
445 | int test_flags = | |
446 | rgw_bucket_dir_entry::FLAG_VER | rgw_bucket_dir_entry::FLAG_CURRENT; | |
447 | return (flags & rgw_bucket_dir_entry::FLAG_VER) == 0 || | |
7c673cae FG |
448 | (flags & test_flags) == test_flags; |
449 | } | |
9f95a23c TL |
450 | bool is_delete_marker() const { |
451 | return (flags & rgw_bucket_dir_entry::FLAG_DELETE_MARKER) != 0; | |
452 | } | |
453 | bool is_visible() const { | |
7c673cae FG |
454 | return is_current() && !is_delete_marker(); |
455 | } | |
9f95a23c TL |
456 | bool is_valid() const { |
457 | return (flags & rgw_bucket_dir_entry::FLAG_VER_MARKER) == 0; | |
458 | } | |
459 | bool is_common_prefix() const { | |
460 | return flags & rgw_bucket_dir_entry::FLAG_COMMON_PREFIX; | |
461 | } | |
7c673cae | 462 | |
f67539c2 | 463 | void dump(ceph::Formatter *f) const; |
7c673cae | 464 | void decode_json(JSONObj *obj); |
f67539c2 | 465 | static void generate_test_instances(std::list<rgw_bucket_dir_entry*>& o); |
7c673cae FG |
466 | }; |
467 | WRITE_CLASS_ENCODER(rgw_bucket_dir_entry) | |
468 | ||
11fdf7f2 TL |
469 | enum class BIIndexType : uint8_t { |
470 | Invalid = 0, | |
471 | Plain = 1, | |
472 | Instance = 2, | |
473 | OLH = 3, | |
7c673cae FG |
474 | }; |
475 | ||
476 | struct rgw_bucket_category_stats; | |
477 | ||
478 | struct rgw_cls_bi_entry { | |
479 | BIIndexType type; | |
f67539c2 TL |
480 | std::string idx; |
481 | ceph::buffer::list data; | |
7c673cae | 482 | |
11fdf7f2 | 483 | rgw_cls_bi_entry() : type(BIIndexType::Invalid) {} |
7c673cae | 484 | |
f67539c2 | 485 | void encode(ceph::buffer::list& bl) const { |
7c673cae | 486 | ENCODE_START(1, 1, bl); |
11fdf7f2 TL |
487 | encode(type, bl); |
488 | encode(idx, bl); | |
489 | encode(data, bl); | |
7c673cae FG |
490 | ENCODE_FINISH(bl); |
491 | } | |
492 | ||
f67539c2 | 493 | void decode(ceph::buffer::list::const_iterator& bl) { |
7c673cae FG |
494 | DECODE_START(1, bl); |
495 | uint8_t c; | |
11fdf7f2 | 496 | decode(c, bl); |
7c673cae | 497 | type = (BIIndexType)c; |
11fdf7f2 TL |
498 | decode(idx, bl); |
499 | decode(data, bl); | |
7c673cae FG |
500 | DECODE_FINISH(bl); |
501 | } | |
502 | ||
f67539c2 | 503 | void dump(ceph::Formatter *f) const; |
7c673cae | 504 | void decode_json(JSONObj *obj, cls_rgw_obj_key *effective_key = NULL); |
1e59de90 | 505 | static void generate_test_instances(std::list<rgw_cls_bi_entry*>& o); |
11fdf7f2 TL |
506 | bool get_info(cls_rgw_obj_key *key, RGWObjCategory *category, |
507 | rgw_bucket_category_stats *accounted_stats); | |
7c673cae FG |
508 | }; |
509 | WRITE_CLASS_ENCODER(rgw_cls_bi_entry) | |
510 | ||
511 | enum OLHLogOp { | |
512 | CLS_RGW_OLH_OP_UNKNOWN = 0, | |
513 | CLS_RGW_OLH_OP_LINK_OLH = 1, | |
514 | CLS_RGW_OLH_OP_UNLINK_OLH = 2, /* object does not exist */ | |
515 | CLS_RGW_OLH_OP_REMOVE_INSTANCE = 3, | |
516 | }; | |
517 | ||
518 | struct rgw_bucket_olh_log_entry { | |
519 | uint64_t epoch; | |
520 | OLHLogOp op; | |
f67539c2 | 521 | std::string op_tag; |
7c673cae FG |
522 | cls_rgw_obj_key key; |
523 | bool delete_marker; | |
524 | ||
525 | rgw_bucket_olh_log_entry() : epoch(0), op(CLS_RGW_OLH_OP_UNKNOWN), delete_marker(false) {} | |
526 | ||
527 | ||
f67539c2 | 528 | void encode(ceph::buffer::list &bl) const { |
7c673cae | 529 | ENCODE_START(1, 1, bl); |
11fdf7f2 TL |
530 | encode(epoch, bl); |
531 | encode((__u8)op, bl); | |
532 | encode(op_tag, bl); | |
533 | encode(key, bl); | |
534 | encode(delete_marker, bl); | |
7c673cae FG |
535 | ENCODE_FINISH(bl); |
536 | } | |
f67539c2 | 537 | void decode(ceph::buffer::list::const_iterator &bl) { |
7c673cae | 538 | DECODE_START(1, bl); |
11fdf7f2 | 539 | decode(epoch, bl); |
7c673cae | 540 | uint8_t c; |
11fdf7f2 | 541 | decode(c, bl); |
7c673cae | 542 | op = (OLHLogOp)c; |
11fdf7f2 TL |
543 | decode(op_tag, bl); |
544 | decode(key, bl); | |
545 | decode(delete_marker, bl); | |
7c673cae FG |
546 | DECODE_FINISH(bl); |
547 | } | |
f67539c2 TL |
548 | static void generate_test_instances(std::list<rgw_bucket_olh_log_entry*>& o); |
549 | void dump(ceph::Formatter *f) const; | |
7c673cae FG |
550 | void decode_json(JSONObj *obj); |
551 | }; | |
552 | WRITE_CLASS_ENCODER(rgw_bucket_olh_log_entry) | |
553 | ||
554 | struct rgw_bucket_olh_entry { | |
555 | cls_rgw_obj_key key; | |
556 | bool delete_marker; | |
557 | uint64_t epoch; | |
f67539c2 TL |
558 | std::map<uint64_t, std::vector<struct rgw_bucket_olh_log_entry> > pending_log; |
559 | std::string tag; | |
7c673cae FG |
560 | bool exists; |
561 | bool pending_removal; | |
562 | ||
563 | rgw_bucket_olh_entry() : delete_marker(false), epoch(0), exists(false), pending_removal(false) {} | |
564 | ||
f67539c2 | 565 | void encode(ceph::buffer::list &bl) const { |
7c673cae | 566 | ENCODE_START(1, 1, bl); |
11fdf7f2 TL |
567 | encode(key, bl); |
568 | encode(delete_marker, bl); | |
569 | encode(epoch, bl); | |
570 | encode(pending_log, bl); | |
571 | encode(tag, bl); | |
572 | encode(exists, bl); | |
573 | encode(pending_removal, bl); | |
7c673cae FG |
574 | ENCODE_FINISH(bl); |
575 | } | |
f67539c2 | 576 | void decode(ceph::buffer::list::const_iterator &bl) { |
7c673cae | 577 | DECODE_START(1, bl); |
11fdf7f2 TL |
578 | decode(key, bl); |
579 | decode(delete_marker, bl); | |
580 | decode(epoch, bl); | |
581 | decode(pending_log, bl); | |
582 | decode(tag, bl); | |
583 | decode(exists, bl); | |
584 | decode(pending_removal, bl); | |
7c673cae FG |
585 | DECODE_FINISH(bl); |
586 | } | |
f67539c2 | 587 | void dump(ceph::Formatter *f) const; |
7c673cae | 588 | void decode_json(JSONObj *obj); |
1e59de90 | 589 | static void generate_test_instances(std::list<rgw_bucket_olh_entry*>& o); |
7c673cae FG |
590 | }; |
591 | WRITE_CLASS_ENCODER(rgw_bucket_olh_entry) | |
592 | ||
593 | struct rgw_bi_log_entry { | |
f67539c2 TL |
594 | std::string id; |
595 | std::string object; | |
596 | std::string instance; | |
7c673cae FG |
597 | ceph::real_time timestamp; |
598 | rgw_bucket_entry_ver ver; | |
599 | RGWModifyOp op; | |
600 | RGWPendingState state; | |
601 | uint64_t index_ver; | |
f67539c2 | 602 | std::string tag; |
7c673cae | 603 | uint16_t bilog_flags; |
f67539c2 TL |
604 | std::string owner; /* only being set if it's a delete marker */ |
605 | std::string owner_display_name; /* only being set if it's a delete marker */ | |
31f18b77 | 606 | rgw_zone_set zones_trace; |
7c673cae FG |
607 | |
608 | rgw_bi_log_entry() : op(CLS_RGW_OP_UNKNOWN), state(CLS_RGW_STATE_PENDING_MODIFY), index_ver(0), bilog_flags(0) {} | |
609 | ||
f67539c2 | 610 | void encode(ceph::buffer::list &bl) const { |
31f18b77 | 611 | ENCODE_START(4, 1, bl); |
11fdf7f2 TL |
612 | encode(id, bl); |
613 | encode(object, bl); | |
614 | encode(timestamp, bl); | |
615 | encode(ver, bl); | |
616 | encode(tag, bl); | |
7c673cae | 617 | uint8_t c = (uint8_t)op; |
11fdf7f2 | 618 | encode(c, bl); |
7c673cae | 619 | c = (uint8_t)state; |
11fdf7f2 | 620 | encode(c, bl); |
7c673cae | 621 | encode_packed_val(index_ver, bl); |
11fdf7f2 TL |
622 | encode(instance, bl); |
623 | encode(bilog_flags, bl); | |
624 | encode(owner, bl); | |
625 | encode(owner_display_name, bl); | |
626 | encode(zones_trace, bl); | |
7c673cae FG |
627 | ENCODE_FINISH(bl); |
628 | } | |
f67539c2 | 629 | void decode(ceph::buffer::list::const_iterator &bl) { |
31f18b77 | 630 | DECODE_START(4, bl); |
11fdf7f2 TL |
631 | decode(id, bl); |
632 | decode(object, bl); | |
633 | decode(timestamp, bl); | |
634 | decode(ver, bl); | |
635 | decode(tag, bl); | |
7c673cae | 636 | uint8_t c; |
11fdf7f2 | 637 | decode(c, bl); |
7c673cae | 638 | op = (RGWModifyOp)c; |
11fdf7f2 | 639 | decode(c, bl); |
7c673cae FG |
640 | state = (RGWPendingState)c; |
641 | decode_packed_val(index_ver, bl); | |
642 | if (struct_v >= 2) { | |
11fdf7f2 TL |
643 | decode(instance, bl); |
644 | decode(bilog_flags, bl); | |
7c673cae FG |
645 | } |
646 | if (struct_v >= 3) { | |
11fdf7f2 TL |
647 | decode(owner, bl); |
648 | decode(owner_display_name, bl); | |
7c673cae | 649 | } |
31f18b77 | 650 | if (struct_v >= 4) { |
11fdf7f2 | 651 | decode(zones_trace, bl); |
31f18b77 | 652 | } |
7c673cae FG |
653 | DECODE_FINISH(bl); |
654 | } | |
f67539c2 | 655 | void dump(ceph::Formatter *f) const; |
7c673cae | 656 | void decode_json(JSONObj *obj); |
f67539c2 | 657 | static void generate_test_instances(std::list<rgw_bi_log_entry*>& o); |
7c673cae FG |
658 | |
659 | bool is_versioned() { | |
660 | return ((bilog_flags & RGW_BILOG_FLAG_VERSIONED_OP) != 0); | |
661 | } | |
662 | }; | |
663 | WRITE_CLASS_ENCODER(rgw_bi_log_entry) | |
664 | ||
665 | struct rgw_bucket_category_stats { | |
666 | uint64_t total_size; | |
667 | uint64_t total_size_rounded; | |
668 | uint64_t num_entries; | |
669 | uint64_t actual_size{0}; //< account for compression, encryption | |
670 | ||
671 | rgw_bucket_category_stats() : total_size(0), total_size_rounded(0), num_entries(0) {} | |
672 | ||
f67539c2 | 673 | void encode(ceph::buffer::list &bl) const { |
7c673cae | 674 | ENCODE_START(3, 2, bl); |
11fdf7f2 TL |
675 | encode(total_size, bl); |
676 | encode(total_size_rounded, bl); | |
677 | encode(num_entries, bl); | |
678 | encode(actual_size, bl); | |
7c673cae FG |
679 | ENCODE_FINISH(bl); |
680 | } | |
f67539c2 | 681 | void decode(ceph::buffer::list::const_iterator &bl) { |
7c673cae | 682 | DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); |
11fdf7f2 TL |
683 | decode(total_size, bl); |
684 | decode(total_size_rounded, bl); | |
685 | decode(num_entries, bl); | |
7c673cae | 686 | if (struct_v >= 3) { |
11fdf7f2 | 687 | decode(actual_size, bl); |
7c673cae FG |
688 | } else { |
689 | actual_size = total_size; | |
690 | } | |
691 | DECODE_FINISH(bl); | |
692 | } | |
f67539c2 TL |
693 | void dump(ceph::Formatter *f) const; |
694 | static void generate_test_instances(std::list<rgw_bucket_category_stats*>& o); | |
7c673cae FG |
695 | }; |
696 | WRITE_CLASS_ENCODER(rgw_bucket_category_stats) | |
697 | ||
20effc67 TL |
698 | inline bool operator==(const rgw_bucket_category_stats& lhs, |
699 | const rgw_bucket_category_stats& rhs) { | |
700 | return lhs.total_size == rhs.total_size | |
701 | && lhs.total_size_rounded == rhs.total_size_rounded | |
702 | && lhs.num_entries == rhs.num_entries | |
703 | && lhs.actual_size == rhs.actual_size; | |
704 | } | |
705 | inline bool operator!=(const rgw_bucket_category_stats& lhs, | |
706 | const rgw_bucket_category_stats& rhs) { | |
707 | return !(lhs == rhs); | |
708 | } | |
709 | ||
9f95a23c TL |
710 | enum class cls_rgw_reshard_status : uint8_t { |
711 | NOT_RESHARDING = 0, | |
712 | IN_PROGRESS = 1, | |
713 | DONE = 2 | |
31f18b77 | 714 | }; |
39ae355f | 715 | std::ostream& operator<<(std::ostream&, cls_rgw_reshard_status); |
31f18b77 | 716 | |
f67539c2 | 717 | inline std::string to_string(const cls_rgw_reshard_status status) |
f64942e4 AA |
718 | { |
719 | switch (status) { | |
9f95a23c | 720 | case cls_rgw_reshard_status::NOT_RESHARDING: |
494da23a | 721 | return "not-resharding"; |
9f95a23c | 722 | case cls_rgw_reshard_status::IN_PROGRESS: |
494da23a | 723 | return "in-progress"; |
9f95a23c | 724 | case cls_rgw_reshard_status::DONE: |
494da23a | 725 | return "done"; |
f64942e4 AA |
726 | }; |
727 | return "Unknown reshard status"; | |
728 | } | |
729 | ||
31f18b77 | 730 | struct cls_rgw_bucket_instance_entry { |
9f95a23c TL |
731 | using RESHARD_STATUS = cls_rgw_reshard_status; |
732 | ||
733 | cls_rgw_reshard_status reshard_status{RESHARD_STATUS::NOT_RESHARDING}; | |
31f18b77 | 734 | |
f67539c2 | 735 | void encode(ceph::buffer::list& bl) const { |
1e59de90 | 736 | ENCODE_START(3, 1, bl); |
11fdf7f2 | 737 | encode((uint8_t)reshard_status, bl); |
1e59de90 TL |
738 | { // fields removed in v2 but added back as empty in v3 |
739 | std::string bucket_instance_id; | |
740 | encode(bucket_instance_id, bl); | |
741 | int32_t num_shards{-1}; | |
742 | encode(num_shards, bl); | |
743 | } | |
31f18b77 FG |
744 | ENCODE_FINISH(bl); |
745 | } | |
746 | ||
f67539c2 | 747 | void decode(ceph::buffer::list::const_iterator& bl) { |
1e59de90 | 748 | DECODE_START(3, bl); |
31f18b77 | 749 | uint8_t s; |
11fdf7f2 | 750 | decode(s, bl); |
31f18b77 | 751 | reshard_status = (cls_rgw_reshard_status)s; |
1e59de90 TL |
752 | if (struct_v != 2) { // fields removed from v2, added back in v3 |
753 | std::string bucket_instance_id; | |
754 | decode(bucket_instance_id, bl); | |
755 | int32_t num_shards{-1}; | |
756 | decode(num_shards, bl); | |
757 | } | |
31f18b77 FG |
758 | DECODE_FINISH(bl); |
759 | } | |
760 | ||
f67539c2 TL |
761 | void dump(ceph::Formatter *f) const; |
762 | static void generate_test_instances(std::list<cls_rgw_bucket_instance_entry*>& o); | |
31f18b77 FG |
763 | |
764 | void clear() { | |
9f95a23c | 765 | reshard_status = RESHARD_STATUS::NOT_RESHARDING; |
31f18b77 FG |
766 | } |
767 | ||
1e59de90 | 768 | void set_status(cls_rgw_reshard_status s) { |
31f18b77 | 769 | reshard_status = s; |
31f18b77 FG |
770 | } |
771 | ||
772 | bool resharding() const { | |
9f95a23c | 773 | return reshard_status != RESHARD_STATUS::NOT_RESHARDING; |
31f18b77 | 774 | } |
39ae355f | 775 | |
31f18b77 | 776 | bool resharding_in_progress() const { |
9f95a23c | 777 | return reshard_status == RESHARD_STATUS::IN_PROGRESS; |
31f18b77 | 778 | } |
39ae355f TL |
779 | |
780 | friend std::ostream& operator<<(std::ostream& out, const cls_rgw_bucket_instance_entry& v) { | |
1e59de90 | 781 | out << "instance entry reshard status: " << v.reshard_status; |
39ae355f TL |
782 | return out; |
783 | } | |
31f18b77 FG |
784 | }; |
785 | WRITE_CLASS_ENCODER(cls_rgw_bucket_instance_entry) | |
786 | ||
20effc67 TL |
787 | using rgw_bucket_dir_stats = std::map<RGWObjCategory, rgw_bucket_category_stats>; |
788 | ||
7c673cae | 789 | struct rgw_bucket_dir_header { |
20effc67 | 790 | rgw_bucket_dir_stats stats; |
7c673cae FG |
791 | uint64_t tag_timeout; |
792 | uint64_t ver; | |
793 | uint64_t master_ver; | |
f67539c2 | 794 | std::string max_marker; |
31f18b77 | 795 | cls_rgw_bucket_instance_entry new_instance; |
c07f9fc5 | 796 | bool syncstopped; |
7c673cae | 797 | |
c07f9fc5 | 798 | rgw_bucket_dir_header() : tag_timeout(0), ver(0), master_ver(0), syncstopped(false) {} |
7c673cae | 799 | |
f67539c2 | 800 | void encode(ceph::buffer::list &bl) const { |
c07f9fc5 | 801 | ENCODE_START(7, 2, bl); |
11fdf7f2 TL |
802 | encode(stats, bl); |
803 | encode(tag_timeout, bl); | |
804 | encode(ver, bl); | |
805 | encode(master_ver, bl); | |
806 | encode(max_marker, bl); | |
807 | encode(new_instance, bl); | |
808 | encode(syncstopped,bl); | |
7c673cae FG |
809 | ENCODE_FINISH(bl); |
810 | } | |
f67539c2 | 811 | void decode(ceph::buffer::list::const_iterator &bl) { |
31f18b77 | 812 | DECODE_START_LEGACY_COMPAT_LEN(6, 2, 2, bl); |
11fdf7f2 | 813 | decode(stats, bl); |
7c673cae | 814 | if (struct_v > 2) { |
11fdf7f2 | 815 | decode(tag_timeout, bl); |
7c673cae FG |
816 | } else { |
817 | tag_timeout = 0; | |
818 | } | |
819 | if (struct_v >= 4) { | |
11fdf7f2 TL |
820 | decode(ver, bl); |
821 | decode(master_ver, bl); | |
7c673cae FG |
822 | } else { |
823 | ver = 0; | |
824 | } | |
825 | if (struct_v >= 5) { | |
11fdf7f2 | 826 | decode(max_marker, bl); |
7c673cae | 827 | } |
31f18b77 | 828 | if (struct_v >= 6) { |
11fdf7f2 | 829 | decode(new_instance, bl); |
31f18b77 FG |
830 | } else { |
831 | new_instance = cls_rgw_bucket_instance_entry(); | |
832 | } | |
c07f9fc5 | 833 | if (struct_v >= 7) { |
11fdf7f2 | 834 | decode(syncstopped,bl); |
c07f9fc5 | 835 | } |
7c673cae FG |
836 | DECODE_FINISH(bl); |
837 | } | |
f67539c2 TL |
838 | void dump(ceph::Formatter *f) const; |
839 | static void generate_test_instances(std::list<rgw_bucket_dir_header*>& o); | |
31f18b77 FG |
840 | |
841 | bool resharding() const { | |
842 | return new_instance.resharding(); | |
843 | } | |
844 | bool resharding_in_progress() const { | |
845 | return new_instance.resharding_in_progress(); | |
846 | } | |
7c673cae FG |
847 | }; |
848 | WRITE_CLASS_ENCODER(rgw_bucket_dir_header) | |
849 | ||
850 | struct rgw_bucket_dir { | |
11fdf7f2 | 851 | rgw_bucket_dir_header header; |
f67539c2 | 852 | boost::container::flat_map<std::string, rgw_bucket_dir_entry> m; |
7c673cae | 853 | |
f67539c2 | 854 | void encode(ceph::buffer::list &bl) const { |
7c673cae | 855 | ENCODE_START(2, 2, bl); |
11fdf7f2 TL |
856 | encode(header, bl); |
857 | encode(m, bl); | |
7c673cae FG |
858 | ENCODE_FINISH(bl); |
859 | } | |
f67539c2 | 860 | void decode(ceph::buffer::list::const_iterator &bl) { |
7c673cae | 861 | DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); |
11fdf7f2 TL |
862 | decode(header, bl); |
863 | decode(m, bl); | |
7c673cae FG |
864 | DECODE_FINISH(bl); |
865 | } | |
f67539c2 TL |
866 | void dump(ceph::Formatter *f) const; |
867 | static void generate_test_instances(std::list<rgw_bucket_dir*>& o); | |
7c673cae FG |
868 | }; |
869 | WRITE_CLASS_ENCODER(rgw_bucket_dir) | |
870 | ||
871 | struct rgw_usage_data { | |
872 | uint64_t bytes_sent; | |
873 | uint64_t bytes_received; | |
874 | uint64_t ops; | |
875 | uint64_t successful_ops; | |
876 | ||
877 | rgw_usage_data() : bytes_sent(0), bytes_received(0), ops(0), successful_ops(0) {} | |
878 | rgw_usage_data(uint64_t sent, uint64_t received) : bytes_sent(sent), bytes_received(received), ops(0), successful_ops(0) {} | |
879 | ||
f67539c2 | 880 | void encode(ceph::buffer::list& bl) const { |
7c673cae | 881 | ENCODE_START(1, 1, bl); |
11fdf7f2 TL |
882 | encode(bytes_sent, bl); |
883 | encode(bytes_received, bl); | |
884 | encode(ops, bl); | |
885 | encode(successful_ops, bl); | |
7c673cae FG |
886 | ENCODE_FINISH(bl); |
887 | } | |
888 | ||
f67539c2 | 889 | void decode(ceph::buffer::list::const_iterator& bl) { |
7c673cae | 890 | DECODE_START(1, bl); |
11fdf7f2 TL |
891 | decode(bytes_sent, bl); |
892 | decode(bytes_received, bl); | |
893 | decode(ops, bl); | |
894 | decode(successful_ops, bl); | |
7c673cae FG |
895 | DECODE_FINISH(bl); |
896 | } | |
897 | ||
898 | void aggregate(const rgw_usage_data& usage) { | |
899 | bytes_sent += usage.bytes_sent; | |
900 | bytes_received += usage.bytes_received; | |
901 | ops += usage.ops; | |
902 | successful_ops += usage.successful_ops; | |
903 | } | |
1e59de90 TL |
904 | void dump(ceph::Formatter *f) const; |
905 | static void generate_test_instances(std::list<rgw_usage_data*>& o); | |
7c673cae FG |
906 | }; |
907 | WRITE_CLASS_ENCODER(rgw_usage_data) | |
908 | ||
909 | ||
910 | struct rgw_usage_log_entry { | |
911 | rgw_user owner; | |
912 | rgw_user payer; /* if empty, same as owner */ | |
f67539c2 | 913 | std::string bucket; |
7c673cae FG |
914 | uint64_t epoch; |
915 | rgw_usage_data total_usage; /* this one is kept for backwards compatibility */ | |
f67539c2 | 916 | std::map<std::string, rgw_usage_data> usage_map; |
7c673cae FG |
917 | |
918 | rgw_usage_log_entry() : epoch(0) {} | |
f67539c2 TL |
919 | rgw_usage_log_entry(std::string& o, std::string& b) : owner(o), bucket(b), epoch(0) {} |
920 | rgw_usage_log_entry(std::string& o, std::string& p, std::string& b) : owner(o), payer(p), bucket(b), epoch(0) {} | |
7c673cae | 921 | |
f67539c2 | 922 | void encode(ceph::buffer::list& bl) const { |
7c673cae | 923 | ENCODE_START(3, 1, bl); |
11fdf7f2 TL |
924 | encode(owner.to_str(), bl); |
925 | encode(bucket, bl); | |
926 | encode(epoch, bl); | |
927 | encode(total_usage.bytes_sent, bl); | |
928 | encode(total_usage.bytes_received, bl); | |
929 | encode(total_usage.ops, bl); | |
930 | encode(total_usage.successful_ops, bl); | |
931 | encode(usage_map, bl); | |
932 | encode(payer.to_str(), bl); | |
7c673cae FG |
933 | ENCODE_FINISH(bl); |
934 | } | |
935 | ||
936 | ||
f67539c2 | 937 | void decode(ceph::buffer::list::const_iterator& bl) { |
7c673cae | 938 | DECODE_START(3, bl); |
f67539c2 | 939 | std::string s; |
11fdf7f2 | 940 | decode(s, bl); |
7c673cae | 941 | owner.from_str(s); |
11fdf7f2 TL |
942 | decode(bucket, bl); |
943 | decode(epoch, bl); | |
944 | decode(total_usage.bytes_sent, bl); | |
945 | decode(total_usage.bytes_received, bl); | |
946 | decode(total_usage.ops, bl); | |
947 | decode(total_usage.successful_ops, bl); | |
7c673cae FG |
948 | if (struct_v < 2) { |
949 | usage_map[""] = total_usage; | |
950 | } else { | |
11fdf7f2 | 951 | decode(usage_map, bl); |
7c673cae FG |
952 | } |
953 | if (struct_v >= 3) { | |
f67539c2 | 954 | std::string p; |
11fdf7f2 | 955 | decode(p, bl); |
7c673cae FG |
956 | payer.from_str(p); |
957 | } | |
958 | DECODE_FINISH(bl); | |
959 | } | |
960 | ||
f67539c2 TL |
961 | void aggregate(const rgw_usage_log_entry& e, |
962 | std::map<std::string, bool> *categories = NULL) { | |
7c673cae FG |
963 | if (owner.empty()) { |
964 | owner = e.owner; | |
965 | bucket = e.bucket; | |
966 | epoch = e.epoch; | |
967 | payer = e.payer; | |
968 | } | |
969 | ||
f67539c2 | 970 | for (auto iter = e.usage_map.begin(); iter != e.usage_map.end(); ++iter) { |
7c673cae FG |
971 | if (!categories || !categories->size() || categories->count(iter->first)) { |
972 | add(iter->first, iter->second); | |
973 | } | |
974 | } | |
975 | } | |
976 | ||
f67539c2 TL |
977 | void sum(rgw_usage_data& usage, |
978 | std::map<std::string, bool>& categories) const { | |
7c673cae | 979 | usage = rgw_usage_data(); |
f67539c2 | 980 | for (auto iter = usage_map.begin(); iter != usage_map.end(); ++iter) { |
7c673cae FG |
981 | if (!categories.size() || categories.count(iter->first)) { |
982 | usage.aggregate(iter->second); | |
983 | } | |
984 | } | |
985 | } | |
986 | ||
f67539c2 | 987 | void add(const std::string& category, const rgw_usage_data& data) { |
7c673cae FG |
988 | usage_map[category].aggregate(data); |
989 | total_usage.aggregate(data); | |
990 | } | |
91327a77 | 991 | |
f67539c2 TL |
992 | void dump(ceph::Formatter* f) const; |
993 | static void generate_test_instances(std::list<rgw_usage_log_entry*>& o); | |
91327a77 | 994 | |
7c673cae FG |
995 | }; |
996 | WRITE_CLASS_ENCODER(rgw_usage_log_entry) | |
997 | ||
998 | struct rgw_usage_log_info { | |
f67539c2 | 999 | std::vector<rgw_usage_log_entry> entries; |
7c673cae | 1000 | |
f67539c2 | 1001 | void encode(ceph::buffer::list& bl) const { |
7c673cae | 1002 | ENCODE_START(1, 1, bl); |
11fdf7f2 | 1003 | encode(entries, bl); |
7c673cae FG |
1004 | ENCODE_FINISH(bl); |
1005 | } | |
1006 | ||
f67539c2 | 1007 | void decode(ceph::buffer::list::const_iterator& bl) { |
7c673cae | 1008 | DECODE_START(1, bl); |
11fdf7f2 | 1009 | decode(entries, bl); |
7c673cae FG |
1010 | DECODE_FINISH(bl); |
1011 | } | |
1e59de90 TL |
1012 | void dump(ceph::Formatter* f) const; |
1013 | static void generate_test_instances(std::list<rgw_usage_log_info*>& o); | |
7c673cae FG |
1014 | |
1015 | rgw_usage_log_info() {} | |
1016 | }; | |
1017 | WRITE_CLASS_ENCODER(rgw_usage_log_info) | |
1018 | ||
1019 | struct rgw_user_bucket { | |
f67539c2 TL |
1020 | std::string user; |
1021 | std::string bucket; | |
7c673cae FG |
1022 | |
1023 | rgw_user_bucket() {} | |
f67539c2 | 1024 | rgw_user_bucket(const std::string& u, const std::string& b) : user(u), bucket(b) {} |
7c673cae | 1025 | |
f67539c2 | 1026 | void encode(ceph::buffer::list& bl) const { |
7c673cae | 1027 | ENCODE_START(1, 1, bl); |
11fdf7f2 TL |
1028 | encode(user, bl); |
1029 | encode(bucket, bl); | |
7c673cae FG |
1030 | ENCODE_FINISH(bl); |
1031 | } | |
1032 | ||
f67539c2 | 1033 | void decode(ceph::buffer::list::const_iterator& bl) { |
7c673cae | 1034 | DECODE_START(1, bl); |
11fdf7f2 TL |
1035 | decode(user, bl); |
1036 | decode(bucket, bl); | |
7c673cae FG |
1037 | DECODE_FINISH(bl); |
1038 | } | |
1039 | ||
1040 | bool operator<(const rgw_user_bucket& ub2) const { | |
1041 | int comp = user.compare(ub2.user); | |
1042 | if (comp < 0) | |
1043 | return true; | |
1044 | else if (!comp) | |
1045 | return bucket.compare(ub2.bucket) < 0; | |
1046 | ||
1047 | return false; | |
1048 | } | |
1e59de90 TL |
1049 | void dump(ceph::Formatter* f) const; |
1050 | static void generate_test_instances(std::list<rgw_user_bucket*>& o); | |
7c673cae FG |
1051 | }; |
1052 | WRITE_CLASS_ENCODER(rgw_user_bucket) | |
1053 | ||
1054 | enum cls_rgw_gc_op { | |
1055 | CLS_RGW_GC_DEL_OBJ, | |
1056 | CLS_RGW_GC_DEL_BUCKET, | |
1057 | }; | |
1058 | ||
1059 | struct cls_rgw_obj { | |
f67539c2 | 1060 | std::string pool; |
7c673cae | 1061 | cls_rgw_obj_key key; |
f67539c2 | 1062 | std::string loc; |
7c673cae FG |
1063 | |
1064 | cls_rgw_obj() {} | |
f67539c2 | 1065 | cls_rgw_obj(std::string& _p, cls_rgw_obj_key& _k) : pool(_p), key(_k) {} |
7c673cae | 1066 | |
f67539c2 | 1067 | void encode(ceph::buffer::list& bl) const { |
7c673cae | 1068 | ENCODE_START(2, 1, bl); |
11fdf7f2 TL |
1069 | encode(pool, bl); |
1070 | encode(key.name, bl); | |
1071 | encode(loc, bl); | |
1072 | encode(key, bl); | |
7c673cae FG |
1073 | ENCODE_FINISH(bl); |
1074 | } | |
1075 | ||
f67539c2 | 1076 | void decode(ceph::buffer::list::const_iterator& bl) { |
7c673cae | 1077 | DECODE_START(2, bl); |
11fdf7f2 TL |
1078 | decode(pool, bl); |
1079 | decode(key.name, bl); | |
1080 | decode(loc, bl); | |
7c673cae | 1081 | if (struct_v >= 2) { |
11fdf7f2 | 1082 | decode(key, bl); |
7c673cae FG |
1083 | } |
1084 | DECODE_FINISH(bl); | |
1085 | } | |
1086 | ||
f67539c2 | 1087 | void dump(ceph::Formatter *f) const { |
7c673cae FG |
1088 | f->dump_string("pool", pool); |
1089 | f->dump_string("oid", key.name); | |
1090 | f->dump_string("key", loc); | |
1091 | f->dump_string("instance", key.instance); | |
1092 | } | |
f67539c2 | 1093 | static void generate_test_instances(std::list<cls_rgw_obj*>& ls) { |
7c673cae FG |
1094 | ls.push_back(new cls_rgw_obj); |
1095 | ls.push_back(new cls_rgw_obj); | |
1096 | ls.back()->pool = "mypool"; | |
1097 | ls.back()->key.name = "myoid"; | |
1098 | ls.back()->loc = "mykey"; | |
1099 | } | |
39ae355f TL |
1100 | |
1101 | size_t estimate_encoded_size() const { | |
1102 | constexpr size_t start_overhead = sizeof(__u8) + sizeof(__u8) + sizeof(ceph_le32); // version and length prefix | |
1103 | constexpr size_t string_overhead = sizeof(__u32); // strings are encoded with 32-bit length prefix | |
1104 | return start_overhead + | |
1105 | string_overhead + pool.size() + | |
1106 | string_overhead + key.name.size() + | |
1107 | string_overhead + loc.size() + | |
1108 | key.estimate_encoded_size(); | |
1109 | } | |
7c673cae FG |
1110 | }; |
1111 | WRITE_CLASS_ENCODER(cls_rgw_obj) | |
1112 | ||
1113 | struct cls_rgw_obj_chain { | |
f67539c2 | 1114 | std::list<cls_rgw_obj> objs; |
7c673cae FG |
1115 | |
1116 | cls_rgw_obj_chain() {} | |
1117 | ||
f67539c2 | 1118 | void push_obj(const std::string& pool, const cls_rgw_obj_key& key, const std::string& loc) { |
7c673cae FG |
1119 | cls_rgw_obj obj; |
1120 | obj.pool = pool; | |
1121 | obj.key = key; | |
1122 | obj.loc = loc; | |
1123 | objs.push_back(obj); | |
1124 | } | |
1125 | ||
f67539c2 | 1126 | void encode(ceph::buffer::list& bl) const { |
7c673cae | 1127 | ENCODE_START(1, 1, bl); |
11fdf7f2 | 1128 | encode(objs, bl); |
7c673cae FG |
1129 | ENCODE_FINISH(bl); |
1130 | } | |
1131 | ||
f67539c2 | 1132 | void decode(ceph::buffer::list::const_iterator& bl) { |
7c673cae | 1133 | DECODE_START(1, bl); |
11fdf7f2 | 1134 | decode(objs, bl); |
7c673cae FG |
1135 | DECODE_FINISH(bl); |
1136 | } | |
1137 | ||
f67539c2 | 1138 | void dump(ceph::Formatter *f) const { |
7c673cae | 1139 | f->open_array_section("objs"); |
f67539c2 | 1140 | for (std::list<cls_rgw_obj>::const_iterator p = objs.begin(); p != objs.end(); ++p) { |
7c673cae FG |
1141 | f->open_object_section("obj"); |
1142 | p->dump(f); | |
1143 | f->close_section(); | |
1144 | } | |
1145 | f->close_section(); | |
1146 | } | |
f67539c2 | 1147 | static void generate_test_instances(std::list<cls_rgw_obj_chain*>& ls) { |
7c673cae FG |
1148 | ls.push_back(new cls_rgw_obj_chain); |
1149 | } | |
1150 | ||
1151 | bool empty() { | |
1152 | return objs.empty(); | |
1153 | } | |
39ae355f TL |
1154 | |
1155 | size_t estimate_encoded_size() const { | |
1156 | constexpr size_t start_overhead = sizeof(__u8) + sizeof(__u8) + sizeof(ceph_le32); | |
1157 | constexpr size_t size_overhead = sizeof(__u32); // size of the chain | |
1158 | size_t chain_overhead = 0; | |
1159 | for (auto& it : objs) { | |
1160 | chain_overhead += it.estimate_encoded_size(); | |
1161 | } | |
1162 | return (start_overhead + size_overhead + chain_overhead); | |
1163 | } | |
7c673cae FG |
1164 | }; |
1165 | WRITE_CLASS_ENCODER(cls_rgw_obj_chain) | |
1166 | ||
1167 | struct cls_rgw_gc_obj_info | |
1168 | { | |
f67539c2 | 1169 | std::string tag; |
7c673cae FG |
1170 | cls_rgw_obj_chain chain; |
1171 | ceph::real_time time; | |
1172 | ||
1173 | cls_rgw_gc_obj_info() {} | |
1174 | ||
f67539c2 | 1175 | void encode(ceph::buffer::list& bl) const { |
7c673cae | 1176 | ENCODE_START(1, 1, bl); |
11fdf7f2 TL |
1177 | encode(tag, bl); |
1178 | encode(chain, bl); | |
1179 | encode(time, bl); | |
7c673cae FG |
1180 | ENCODE_FINISH(bl); |
1181 | } | |
1182 | ||
f67539c2 | 1183 | void decode(ceph::buffer::list::const_iterator& bl) { |
7c673cae | 1184 | DECODE_START(1, bl); |
11fdf7f2 TL |
1185 | decode(tag, bl); |
1186 | decode(chain, bl); | |
1187 | decode(time, bl); | |
7c673cae FG |
1188 | DECODE_FINISH(bl); |
1189 | } | |
1190 | ||
f67539c2 | 1191 | void dump(ceph::Formatter *f) const { |
7c673cae FG |
1192 | f->dump_string("tag", tag); |
1193 | f->open_object_section("chain"); | |
1194 | chain.dump(f); | |
1195 | f->close_section(); | |
1196 | f->dump_stream("time") << time; | |
1197 | } | |
f67539c2 | 1198 | static void generate_test_instances(std::list<cls_rgw_gc_obj_info*>& ls) { |
7c673cae FG |
1199 | ls.push_back(new cls_rgw_gc_obj_info); |
1200 | ls.push_back(new cls_rgw_gc_obj_info); | |
1201 | ls.back()->tag = "footag"; | |
20effc67 | 1202 | ceph_timespec ts{ceph_le32(21), ceph_le32(32)}; |
7c673cae FG |
1203 | ls.back()->time = ceph::real_clock::from_ceph_timespec(ts); |
1204 | } | |
39ae355f TL |
1205 | |
1206 | size_t estimate_encoded_size() const { | |
1207 | constexpr size_t start_overhead = sizeof(__u8) + sizeof(__u8) + sizeof(ceph_le32); // version and length prefix | |
1208 | constexpr size_t string_overhead = sizeof(__u32); // strings are encoded with 32-bit length prefix | |
1209 | constexpr size_t time_overhead = 2 * sizeof(ceph_le32); // time is stored as tv_sec and tv_nsec | |
1210 | return start_overhead + string_overhead + tag.size() + | |
1211 | time_overhead + chain.estimate_encoded_size(); | |
1212 | } | |
7c673cae FG |
1213 | }; |
1214 | WRITE_CLASS_ENCODER(cls_rgw_gc_obj_info) | |
1215 | ||
1216 | struct cls_rgw_lc_obj_head | |
1217 | { | |
11fdf7f2 | 1218 | time_t start_date = 0; |
f67539c2 | 1219 | std::string marker; |
1e59de90 | 1220 | time_t shard_rollover_date = 0; |
7c673cae FG |
1221 | |
1222 | cls_rgw_lc_obj_head() {} | |
1223 | ||
f67539c2 | 1224 | void encode(ceph::buffer::list& bl) const { |
1e59de90 | 1225 | ENCODE_START(2, 2, bl); |
7c673cae | 1226 | uint64_t t = start_date; |
11fdf7f2 TL |
1227 | encode(t, bl); |
1228 | encode(marker, bl); | |
1e59de90 | 1229 | encode(shard_rollover_date, bl); |
7c673cae FG |
1230 | ENCODE_FINISH(bl); |
1231 | } | |
1232 | ||
f67539c2 | 1233 | void decode(ceph::buffer::list::const_iterator& bl) { |
1e59de90 | 1234 | DECODE_START(2, bl); |
7c673cae | 1235 | uint64_t t; |
11fdf7f2 | 1236 | decode(t, bl); |
7c673cae | 1237 | start_date = static_cast<time_t>(t); |
11fdf7f2 | 1238 | decode(marker, bl); |
1e59de90 TL |
1239 | if (struct_v < 2) { |
1240 | shard_rollover_date = 0; | |
1241 | } else { | |
1242 | decode(t, bl); | |
1243 | shard_rollover_date = static_cast<time_t>(t); | |
1244 | } | |
7c673cae FG |
1245 | DECODE_FINISH(bl); |
1246 | } | |
1247 | ||
f67539c2 TL |
1248 | void dump(ceph::Formatter *f) const; |
1249 | static void generate_test_instances(std::list<cls_rgw_lc_obj_head*>& ls); | |
7c673cae FG |
1250 | }; |
1251 | WRITE_CLASS_ENCODER(cls_rgw_lc_obj_head) | |
1252 | ||
f6b5b4d7 TL |
1253 | struct cls_rgw_lc_entry { |
1254 | std::string bucket; | |
1255 | uint64_t start_time; // if in_progress | |
1256 | uint32_t status; | |
1257 | ||
1258 | cls_rgw_lc_entry() | |
1259 | : start_time(0), status(0) {} | |
1260 | ||
1261 | cls_rgw_lc_entry(const cls_rgw_lc_entry& rhs) = default; | |
1262 | ||
1263 | cls_rgw_lc_entry(const std::string& b, uint64_t t, uint32_t s) | |
1264 | : bucket(b), start_time(t), status(s) {}; | |
1265 | ||
1266 | void encode(bufferlist& bl) const { | |
1267 | ENCODE_START(1, 1, bl); | |
1268 | encode(bucket, bl); | |
1269 | encode(start_time, bl); | |
1270 | encode(status, bl); | |
1271 | ENCODE_FINISH(bl); | |
1272 | } | |
1273 | ||
1274 | void decode(bufferlist::const_iterator& bl) { | |
1275 | DECODE_START(1, bl); | |
1276 | decode(bucket, bl); | |
1277 | decode(start_time, bl); | |
1278 | decode(status, bl); | |
1279 | DECODE_FINISH(bl); | |
1280 | } | |
1e59de90 TL |
1281 | void dump(Formatter *f) const; |
1282 | static void generate_test_instances(std::list<cls_rgw_lc_entry*>& ls); | |
f6b5b4d7 TL |
1283 | }; |
1284 | WRITE_CLASS_ENCODER(cls_rgw_lc_entry); | |
1285 | ||
31f18b77 FG |
1286 | struct cls_rgw_reshard_entry |
1287 | { | |
1288 | ceph::real_time time; | |
f67539c2 TL |
1289 | std::string tenant; |
1290 | std::string bucket_name; | |
1291 | std::string bucket_id; | |
31f18b77 FG |
1292 | uint32_t old_num_shards{0}; |
1293 | uint32_t new_num_shards{0}; | |
1294 | ||
1295 | cls_rgw_reshard_entry() {} | |
1296 | ||
f67539c2 | 1297 | void encode(ceph::buffer::list& bl) const { |
1e59de90 | 1298 | ENCODE_START(2, 1, bl); |
11fdf7f2 TL |
1299 | encode(time, bl); |
1300 | encode(tenant, bl); | |
1301 | encode(bucket_name, bl); | |
1302 | encode(bucket_id, bl); | |
11fdf7f2 TL |
1303 | encode(old_num_shards, bl); |
1304 | encode(new_num_shards, bl); | |
31f18b77 FG |
1305 | ENCODE_FINISH(bl); |
1306 | } | |
1307 | ||
f67539c2 | 1308 | void decode(ceph::buffer::list::const_iterator& bl) { |
1e59de90 | 1309 | DECODE_START(2, bl); |
11fdf7f2 TL |
1310 | decode(time, bl); |
1311 | decode(tenant, bl); | |
1312 | decode(bucket_name, bl); | |
1313 | decode(bucket_id, bl); | |
1e59de90 TL |
1314 | if (struct_v < 2) { |
1315 | std::string new_instance_id; // removed in v2 | |
1316 | decode(new_instance_id, bl); | |
1317 | } | |
11fdf7f2 TL |
1318 | decode(old_num_shards, bl); |
1319 | decode(new_num_shards, bl); | |
31f18b77 FG |
1320 | DECODE_FINISH(bl); |
1321 | } | |
1322 | ||
f67539c2 TL |
1323 | void dump(ceph::Formatter *f) const; |
1324 | static void generate_test_instances(std::list<cls_rgw_reshard_entry*>& o); | |
31f18b77 | 1325 | |
f67539c2 TL |
1326 | static void generate_key(const std::string& tenant, const std::string& bucket_name, std::string *key); |
1327 | void get_key(std::string *key) const; | |
31f18b77 FG |
1328 | }; |
1329 | WRITE_CLASS_ENCODER(cls_rgw_reshard_entry) |