]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_zone.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / rgw / rgw_zone.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 #ifndef CEPH_RGW_ZONE_H
5 #define CEPH_RGW_ZONE_H
6
7 #include "rgw_common.h"
8 #include "rgw_sync_policy.h"
9
10 namespace rgw_zone_defaults {
11
12 extern std::string zone_names_oid_prefix;
13 extern std::string region_info_oid_prefix;
14 extern std::string realm_names_oid_prefix;
15 extern std::string zone_group_info_oid_prefix;
16 extern std::string realm_info_oid_prefix;
17 extern std::string default_region_info_oid;
18 extern std::string default_zone_group_info_oid;
19 extern std::string region_map_oid;
20 extern std::string default_realm_info_oid;
21 extern std::string default_zonegroup_name;
22 extern std::string default_zone_name;
23 extern std::string zonegroup_names_oid_prefix;
24 extern std::string RGW_DEFAULT_ZONE_ROOT_POOL;
25 extern std::string RGW_DEFAULT_ZONEGROUP_ROOT_POOL;
26 extern std::string RGW_DEFAULT_REALM_ROOT_POOL;
27 extern std::string RGW_DEFAULT_PERIOD_ROOT_POOL;
28 extern std::string avail_pools;
29 extern std::string default_storage_pool_suffix;
30
31 }
32
33 class JSONObj;
34 class RGWSyncModulesManager;
35
36
37 struct RGWNameToId {
38 std::string obj_id;
39
40 void encode(bufferlist& bl) const {
41 ENCODE_START(1, 1, bl);
42 encode(obj_id, bl);
43 ENCODE_FINISH(bl);
44 }
45
46 void decode(bufferlist::const_iterator& bl) {
47 DECODE_START(1, bl);
48 decode(obj_id, bl);
49 DECODE_FINISH(bl);
50 }
51
52 void dump(Formatter *f) const;
53 void decode_json(JSONObj *obj);
54 };
55 WRITE_CLASS_ENCODER(RGWNameToId)
56
57 struct RGWDefaultSystemMetaObjInfo {
58 std::string default_id;
59
60 void encode(bufferlist& bl) const {
61 ENCODE_START(1, 1, bl);
62 encode(default_id, bl);
63 ENCODE_FINISH(bl);
64 }
65
66 void decode(bufferlist::const_iterator& bl) {
67 DECODE_START(1, bl);
68 decode(default_id, bl);
69 DECODE_FINISH(bl);
70 }
71
72 void dump(Formatter *f) const;
73 void decode_json(JSONObj *obj);
74 };
75 WRITE_CLASS_ENCODER(RGWDefaultSystemMetaObjInfo)
76
77 class RGWSI_SysObj;
78 class RGWSI_Zone;
79
80 class RGWSystemMetaObj {
81 protected:
82 std::string id;
83 std::string name;
84
85 CephContext *cct{nullptr};
86 RGWSI_SysObj *sysobj_svc{nullptr};
87 RGWSI_Zone *zone_svc{nullptr};
88
89 int store_name(bool exclusive);
90 int store_info(bool exclusive);
91 int read_info(const std::string& obj_id, bool old_format = false);
92 int read_id(const std::string& obj_name, std::string& obj_id);
93 int read_default(RGWDefaultSystemMetaObjInfo& default_info,
94 const std::string& oid);
95 /* read and use default id */
96 int use_default(bool old_format = false);
97
98 public:
99 RGWSystemMetaObj() {}
100 RGWSystemMetaObj(const std::string& _name): name(_name) {}
101 RGWSystemMetaObj(const std::string& _id, const std::string& _name) : id(_id), name(_name) {}
102 RGWSystemMetaObj(CephContext *_cct, RGWSI_SysObj *_sysobj_svc) {
103 reinit_instance(_cct, _sysobj_svc);
104 }
105 RGWSystemMetaObj(const std::string& _name, CephContext *_cct, RGWSI_SysObj *_sysobj_svc): name(_name) {
106 reinit_instance(_cct, _sysobj_svc);
107 }
108
109 const std::string& get_name() const { return name; }
110 const std::string& get_id() const { return id; }
111
112 void set_name(const std::string& _name) { name = _name;}
113 void set_id(const std::string& _id) { id = _id;}
114 void clear_id() { id.clear(); }
115
116 virtual ~RGWSystemMetaObj() {}
117
118 virtual void encode(bufferlist& bl) const {
119 ENCODE_START(1, 1, bl);
120 encode(id, bl);
121 encode(name, bl);
122 ENCODE_FINISH(bl);
123 }
124
125 virtual void decode(bufferlist::const_iterator& bl) {
126 DECODE_START(1, bl);
127 decode(id, bl);
128 decode(name, bl);
129 DECODE_FINISH(bl);
130 }
131
132 void reinit_instance(CephContext *_cct, RGWSI_SysObj *_sysobj_svc);
133 int init(CephContext *_cct, RGWSI_SysObj *_sysobj_svc, bool setup_obj = true, bool old_format = false);
134 virtual int read_default_id(std::string& default_id, bool old_format = false);
135 virtual int set_as_default(bool exclusive = false);
136 int delete_default();
137 virtual int create(bool exclusive = true);
138 int delete_obj(bool old_format = false);
139 int rename(const std::string& new_name);
140 int update() { return store_info(false);}
141 int update_name() { return store_name(false);}
142 int read();
143 int write(bool exclusive);
144
145 virtual rgw_pool get_pool(CephContext *cct) const = 0;
146 virtual const std::string get_default_oid(bool old_format = false) const = 0;
147 virtual const std::string& get_names_oid_prefix() const = 0;
148 virtual const std::string& get_info_oid_prefix(bool old_format = false) const = 0;
149 virtual const std::string& get_predefined_name(CephContext *cct) const = 0;
150
151 void dump(Formatter *f) const;
152 void decode_json(JSONObj *obj);
153 };
154 WRITE_CLASS_ENCODER(RGWSystemMetaObj)
155
156 struct RGWZoneStorageClass {
157 boost::optional<rgw_pool> data_pool;
158 boost::optional<std::string> compression_type;
159
160 void encode(bufferlist& bl) const {
161 ENCODE_START(1, 1, bl);
162 encode(data_pool, bl);
163 encode(compression_type, bl);
164 ENCODE_FINISH(bl);
165 }
166
167 void decode(bufferlist::const_iterator& bl) {
168 DECODE_START(1, bl);
169 decode(data_pool, bl);
170 decode(compression_type, bl);
171 DECODE_FINISH(bl);
172 }
173
174 void dump(Formatter *f) const;
175 void decode_json(JSONObj *obj);
176 };
177 WRITE_CLASS_ENCODER(RGWZoneStorageClass)
178
179
180 class RGWZoneStorageClasses {
181 map<string, RGWZoneStorageClass> m;
182
183 /* in memory only */
184 RGWZoneStorageClass *standard_class;
185
186 public:
187 RGWZoneStorageClasses() {
188 standard_class = &m[RGW_STORAGE_CLASS_STANDARD];
189 }
190 RGWZoneStorageClasses(const RGWZoneStorageClasses& rhs) {
191 m = rhs.m;
192 standard_class = &m[RGW_STORAGE_CLASS_STANDARD];
193 }
194 RGWZoneStorageClasses& operator=(const RGWZoneStorageClasses& rhs) {
195 m = rhs.m;
196 standard_class = &m[RGW_STORAGE_CLASS_STANDARD];
197 return *this;
198 }
199
200 const RGWZoneStorageClass& get_standard() const {
201 return *standard_class;
202 }
203
204 bool find(const string& sc, const RGWZoneStorageClass **pstorage_class) const {
205 auto iter = m.find(sc);
206 if (iter == m.end()) {
207 return false;
208 }
209 *pstorage_class = &iter->second;
210 return true;
211 }
212
213 bool exists(const string& sc) const {
214 if (sc.empty()) {
215 return true;
216 }
217 auto iter = m.find(sc);
218 return (iter != m.end());
219 }
220
221 const map<string, RGWZoneStorageClass>& get_all() const {
222 return m;
223 }
224
225 map<string, RGWZoneStorageClass>& get_all() {
226 return m;
227 }
228
229 void set_storage_class(const string& sc, const rgw_pool *data_pool, const string *compression_type) {
230 const string *psc = &sc;
231 if (sc.empty()) {
232 psc = &RGW_STORAGE_CLASS_STANDARD;
233 }
234 RGWZoneStorageClass& storage_class = m[*psc];
235 if (data_pool) {
236 storage_class.data_pool = *data_pool;
237 }
238 if (compression_type) {
239 storage_class.compression_type = *compression_type;
240 }
241 }
242
243 void remove_storage_class(const string& sc) {
244 if (!sc.empty()) {
245 m.erase(sc);
246 }
247 }
248
249 void encode(bufferlist& bl) const {
250 ENCODE_START(1, 1, bl);
251 encode(m, bl);
252 ENCODE_FINISH(bl);
253 }
254
255 void decode(bufferlist::const_iterator& bl) {
256 DECODE_START(1, bl);
257 decode(m, bl);
258 standard_class = &m[RGW_STORAGE_CLASS_STANDARD];
259 DECODE_FINISH(bl);
260 }
261
262 void dump(Formatter *f) const;
263 void decode_json(JSONObj *obj);
264 };
265 WRITE_CLASS_ENCODER(RGWZoneStorageClasses)
266
267 struct RGWZonePlacementInfo {
268 rgw_pool index_pool;
269 rgw_pool data_extra_pool; /* if not set we should use data_pool */
270 RGWZoneStorageClasses storage_classes;
271 RGWBucketIndexType index_type;
272
273 RGWZonePlacementInfo() : index_type(RGWBIType_Normal) {}
274
275 void encode(bufferlist& bl) const {
276 ENCODE_START(7, 1, bl);
277 encode(index_pool.to_str(), bl);
278 rgw_pool standard_data_pool = get_data_pool(RGW_STORAGE_CLASS_STANDARD);
279 encode(standard_data_pool.to_str(), bl);
280 encode(data_extra_pool.to_str(), bl);
281 encode((uint32_t)index_type, bl);
282 string standard_compression_type = get_compression_type(RGW_STORAGE_CLASS_STANDARD);
283 encode(standard_compression_type, bl);
284 encode(storage_classes, bl);
285 ENCODE_FINISH(bl);
286 }
287
288 void decode(bufferlist::const_iterator& bl) {
289 DECODE_START(7, bl);
290 string index_pool_str;
291 string data_pool_str;
292 decode(index_pool_str, bl);
293 index_pool = rgw_pool(index_pool_str);
294 decode(data_pool_str, bl);
295 rgw_pool standard_data_pool(data_pool_str);
296 if (struct_v >= 4) {
297 string data_extra_pool_str;
298 decode(data_extra_pool_str, bl);
299 data_extra_pool = rgw_pool(data_extra_pool_str);
300 }
301 if (struct_v >= 5) {
302 uint32_t it;
303 decode(it, bl);
304 index_type = (RGWBucketIndexType)it;
305 }
306 string standard_compression_type;
307 if (struct_v >= 6) {
308 decode(standard_compression_type, bl);
309 }
310 if (struct_v >= 7) {
311 decode(storage_classes, bl);
312 } else {
313 storage_classes.set_storage_class(RGW_STORAGE_CLASS_STANDARD, &standard_data_pool,
314 (!standard_compression_type.empty() ? &standard_compression_type : nullptr));
315 }
316 DECODE_FINISH(bl);
317 }
318 const rgw_pool& get_data_extra_pool() const {
319 static rgw_pool no_pool;
320 if (data_extra_pool.empty()) {
321 return storage_classes.get_standard().data_pool.get_value_or(no_pool);
322 }
323 return data_extra_pool;
324 }
325 const rgw_pool& get_data_pool(const string& sc) const {
326 const RGWZoneStorageClass *storage_class;
327 static rgw_pool no_pool;
328
329 if (!storage_classes.find(sc, &storage_class)) {
330 return storage_classes.get_standard().data_pool.get_value_or(no_pool);
331 }
332
333 return storage_class->data_pool.get_value_or(no_pool);
334 }
335 const rgw_pool& get_standard_data_pool() const {
336 return get_data_pool(RGW_STORAGE_CLASS_STANDARD);
337 }
338
339 const string& get_compression_type(const string& sc) const {
340 const RGWZoneStorageClass *storage_class;
341 static string no_compression;
342
343 if (!storage_classes.find(sc, &storage_class)) {
344 return no_compression;
345 }
346 return storage_class->compression_type.get_value_or(no_compression);
347 }
348
349 bool storage_class_exists(const string& sc) const {
350 return storage_classes.exists(sc);
351 }
352
353 void dump(Formatter *f) const;
354 void decode_json(JSONObj *obj);
355
356 };
357 WRITE_CLASS_ENCODER(RGWZonePlacementInfo)
358
359 struct RGWZoneParams : RGWSystemMetaObj {
360 rgw_pool domain_root;
361 rgw_pool control_pool;
362 rgw_pool gc_pool;
363 rgw_pool lc_pool;
364 rgw_pool log_pool;
365 rgw_pool intent_log_pool;
366 rgw_pool usage_log_pool;
367
368 rgw_pool user_keys_pool;
369 rgw_pool user_email_pool;
370 rgw_pool user_swift_pool;
371 rgw_pool user_uid_pool;
372 rgw_pool roles_pool;
373 rgw_pool reshard_pool;
374 rgw_pool otp_pool;
375
376 RGWAccessKey system_key;
377
378 map<std::string, RGWZonePlacementInfo> placement_pools;
379
380 std::string realm_id;
381
382 JSONFormattable tier_config;
383
384 RGWZoneParams() : RGWSystemMetaObj() {}
385 explicit RGWZoneParams(const std::string& name) : RGWSystemMetaObj(name){}
386 RGWZoneParams(const rgw_zone_id& id, const std::string& name) : RGWSystemMetaObj(id.id, name) {}
387 RGWZoneParams(const rgw_zone_id& id, const std::string& name, const std::string& _realm_id)
388 : RGWSystemMetaObj(id.id, name), realm_id(_realm_id) {}
389
390 rgw_pool get_pool(CephContext *cct) const override;
391 const std::string get_default_oid(bool old_format = false) const override;
392 const std::string& get_names_oid_prefix() const override;
393 const std::string& get_info_oid_prefix(bool old_format = false) const override;
394 const std::string& get_predefined_name(CephContext *cct) const override;
395
396 int init(CephContext *_cct, RGWSI_SysObj *_sysobj_svc, bool setup_obj = true,
397 bool old_format = false);
398 using RGWSystemMetaObj::init;
399 int read_default_id(std::string& default_id, bool old_format = false) override;
400 int set_as_default(bool exclusive = false) override;
401 int create_default(bool old_format = false);
402 int create(bool exclusive = true) override;
403 int fix_pool_names();
404
405 const string& get_compression_type(const rgw_placement_rule& placement_rule) const;
406
407 void encode(bufferlist& bl) const override {
408 ENCODE_START(12, 1, bl);
409 encode(domain_root, bl);
410 encode(control_pool, bl);
411 encode(gc_pool, bl);
412 encode(log_pool, bl);
413 encode(intent_log_pool, bl);
414 encode(usage_log_pool, bl);
415 encode(user_keys_pool, bl);
416 encode(user_email_pool, bl);
417 encode(user_swift_pool, bl);
418 encode(user_uid_pool, bl);
419 RGWSystemMetaObj::encode(bl);
420 encode(system_key, bl);
421 encode(placement_pools, bl);
422 rgw_pool unused_metadata_heap;
423 encode(unused_metadata_heap, bl);
424 encode(realm_id, bl);
425 encode(lc_pool, bl);
426 map<std::string, std::string, ltstr_nocase> old_tier_config;
427 encode(old_tier_config, bl);
428 encode(roles_pool, bl);
429 encode(reshard_pool, bl);
430 encode(otp_pool, bl);
431 encode(tier_config, bl);
432 ENCODE_FINISH(bl);
433 }
434
435 void decode(bufferlist::const_iterator& bl) override {
436 DECODE_START(12, bl);
437 decode(domain_root, bl);
438 decode(control_pool, bl);
439 decode(gc_pool, bl);
440 decode(log_pool, bl);
441 decode(intent_log_pool, bl);
442 decode(usage_log_pool, bl);
443 decode(user_keys_pool, bl);
444 decode(user_email_pool, bl);
445 decode(user_swift_pool, bl);
446 decode(user_uid_pool, bl);
447 if (struct_v >= 6) {
448 RGWSystemMetaObj::decode(bl);
449 } else if (struct_v >= 2) {
450 decode(name, bl);
451 id = name;
452 }
453 if (struct_v >= 3)
454 decode(system_key, bl);
455 if (struct_v >= 4)
456 decode(placement_pools, bl);
457 if (struct_v >= 5) {
458 rgw_pool unused_metadata_heap;
459 decode(unused_metadata_heap, bl);
460 }
461 if (struct_v >= 6) {
462 decode(realm_id, bl);
463 }
464 if (struct_v >= 7) {
465 decode(lc_pool, bl);
466 } else {
467 lc_pool = log_pool.name + ":lc";
468 }
469 map<std::string, std::string, ltstr_nocase> old_tier_config;
470 if (struct_v >= 8) {
471 decode(old_tier_config, bl);
472 }
473 if (struct_v >= 9) {
474 decode(roles_pool, bl);
475 } else {
476 roles_pool = name + ".rgw.meta:roles";
477 }
478 if (struct_v >= 10) {
479 decode(reshard_pool, bl);
480 } else {
481 reshard_pool = log_pool.name + ":reshard";
482 }
483 if (struct_v >= 11) {
484 ::decode(otp_pool, bl);
485 } else {
486 otp_pool = name + ".rgw.otp";
487 }
488 if (struct_v >= 12) {
489 ::decode(tier_config, bl);
490 } else {
491 for (auto& kv : old_tier_config) {
492 tier_config.set(kv.first, kv.second);
493 }
494 }
495 DECODE_FINISH(bl);
496 }
497 void dump(Formatter *f) const;
498 void decode_json(JSONObj *obj);
499 static void generate_test_instances(list<RGWZoneParams*>& o);
500
501 bool get_placement(const std::string& placement_id, RGWZonePlacementInfo *placement) const {
502 auto iter = placement_pools.find(placement_id);
503 if (iter == placement_pools.end()) {
504 return false;
505 }
506 *placement = iter->second;
507 return true;
508 }
509
510 /*
511 * return data pool of the head object
512 */
513 bool get_head_data_pool(const rgw_placement_rule& placement_rule, const rgw_obj& obj, rgw_pool *pool) const {
514 const rgw_data_placement_target& explicit_placement = obj.bucket.explicit_placement;
515 if (!explicit_placement.data_pool.empty()) {
516 if (!obj.in_extra_data) {
517 *pool = explicit_placement.data_pool;
518 } else {
519 *pool = explicit_placement.get_data_extra_pool();
520 }
521 return true;
522 }
523 if (placement_rule.empty()) {
524 return false;
525 }
526 auto iter = placement_pools.find(placement_rule.name);
527 if (iter == placement_pools.end()) {
528 return false;
529 }
530 if (!obj.in_extra_data) {
531 *pool = iter->second.get_data_pool(placement_rule.storage_class);
532 } else {
533 *pool = iter->second.get_data_extra_pool();
534 }
535 return true;
536 }
537
538 bool valid_placement(const rgw_placement_rule& rule) const {
539 auto iter = placement_pools.find(rule.name);
540 if (iter == placement_pools.end()) {
541 return false;
542 }
543 return iter->second.storage_class_exists(rule.storage_class);
544 }
545 };
546 WRITE_CLASS_ENCODER(RGWZoneParams)
547
548 struct RGWZone {
549 std::string id;
550 std::string name;
551 list<std::string> endpoints;
552 bool log_meta;
553 bool log_data;
554 bool read_only;
555 std::string tier_type;
556
557 std::string redirect_zone;
558
559 /**
560 * Represents the number of shards for the bucket index object, a value of zero
561 * indicates there is no sharding. By default (no sharding, the name of the object
562 * is '.dir.{marker}', with sharding, the name is '.dir.{marker}.{sharding_id}',
563 * sharding_id is zero-based value. It is not recommended to set a too large value
564 * (e.g. thousand) as it increases the cost for bucket listing.
565 */
566 uint32_t bucket_index_max_shards;
567
568 // pre-shard buckets on creation to enable some write-parallism by default,
569 // delay the need to reshard as the bucket grows, and (in multisite) get some
570 // bucket index sharding where dynamic resharding is not supported
571 static constexpr uint32_t default_bucket_index_max_shards = 11;
572
573 bool sync_from_all;
574 set<std::string> sync_from; /* list of zones to sync from */
575
576 RGWZone()
577 : log_meta(false), log_data(false), read_only(false),
578 bucket_index_max_shards(default_bucket_index_max_shards),
579 sync_from_all(true) {}
580
581 void encode(bufferlist& bl) const {
582 ENCODE_START(7, 1, bl);
583 encode(name, bl);
584 encode(endpoints, bl);
585 encode(log_meta, bl);
586 encode(log_data, bl);
587 encode(bucket_index_max_shards, bl);
588 encode(id, bl);
589 encode(read_only, bl);
590 encode(tier_type, bl);
591 encode(sync_from_all, bl);
592 encode(sync_from, bl);
593 encode(redirect_zone, bl);
594 ENCODE_FINISH(bl);
595 }
596
597 void decode(bufferlist::const_iterator& bl) {
598 DECODE_START(7, bl);
599 decode(name, bl);
600 if (struct_v < 4) {
601 id = name;
602 }
603 decode(endpoints, bl);
604 if (struct_v >= 2) {
605 decode(log_meta, bl);
606 decode(log_data, bl);
607 }
608 if (struct_v >= 3) {
609 decode(bucket_index_max_shards, bl);
610 }
611 if (struct_v >= 4) {
612 decode(id, bl);
613 decode(read_only, bl);
614 }
615 if (struct_v >= 5) {
616 decode(tier_type, bl);
617 }
618 if (struct_v >= 6) {
619 decode(sync_from_all, bl);
620 decode(sync_from, bl);
621 }
622 if (struct_v >= 7) {
623 decode(redirect_zone, bl);
624 }
625 DECODE_FINISH(bl);
626 }
627 void dump(Formatter *f) const;
628 void decode_json(JSONObj *obj);
629 static void generate_test_instances(list<RGWZone*>& o);
630
631 bool is_read_only() const { return read_only; }
632
633 bool syncs_from(const std::string& zone_name) const {
634 return (sync_from_all || sync_from.find(zone_name) != sync_from.end());
635 }
636 };
637 WRITE_CLASS_ENCODER(RGWZone)
638
639 struct RGWDefaultZoneGroupInfo {
640 std::string default_zonegroup;
641
642 void encode(bufferlist& bl) const {
643 ENCODE_START(1, 1, bl);
644 encode(default_zonegroup, bl);
645 ENCODE_FINISH(bl);
646 }
647
648 void decode(bufferlist::const_iterator& bl) {
649 DECODE_START(1, bl);
650 decode(default_zonegroup, bl);
651 DECODE_FINISH(bl);
652 }
653 void dump(Formatter *f) const;
654 void decode_json(JSONObj *obj);
655 //todo: implement ceph-dencoder
656 };
657 WRITE_CLASS_ENCODER(RGWDefaultZoneGroupInfo)
658
659 struct RGWZoneGroupPlacementTarget {
660 std::string name;
661 set<std::string> tags;
662 set<std::string> storage_classes;
663
664 bool user_permitted(const list<std::string>& user_tags) const {
665 if (tags.empty()) {
666 return true;
667 }
668 for (auto& rule : user_tags) {
669 if (tags.find(rule) != tags.end()) {
670 return true;
671 }
672 }
673 return false;
674 }
675
676 void encode(bufferlist& bl) const {
677 ENCODE_START(2, 1, bl);
678 encode(name, bl);
679 encode(tags, bl);
680 encode(storage_classes, bl);
681 ENCODE_FINISH(bl);
682 }
683
684 void decode(bufferlist::const_iterator& bl) {
685 DECODE_START(2, bl);
686 decode(name, bl);
687 decode(tags, bl);
688 if (struct_v >= 2) {
689 decode(storage_classes, bl);
690 }
691 if (storage_classes.empty()) {
692 storage_classes.insert(RGW_STORAGE_CLASS_STANDARD);
693 }
694 DECODE_FINISH(bl);
695 }
696 void dump(Formatter *f) const;
697 void decode_json(JSONObj *obj);
698 };
699 WRITE_CLASS_ENCODER(RGWZoneGroupPlacementTarget)
700
701 struct RGWZoneGroup : public RGWSystemMetaObj {
702 std::string api_name;
703 list<std::string> endpoints;
704 bool is_master = false;
705
706 rgw_zone_id master_zone;
707 map<rgw_zone_id, RGWZone> zones;
708
709 map<std::string, RGWZoneGroupPlacementTarget> placement_targets;
710 rgw_placement_rule default_placement;
711
712 list<std::string> hostnames;
713 list<std::string> hostnames_s3website;
714 // TODO: Maybe convert hostnames to a map<std::string,list<std::string>> for
715 // endpoint_type->hostnames
716 /*
717 20:05 < _robbat21irssi> maybe I do someting like: if (hostname_map.empty()) { populate all map keys from hostnames; };
718 20:05 < _robbat21irssi> but that's a later compatability migration planning bit
719 20:06 < yehudasa> more like if (!hostnames.empty()) {
720 20:06 < yehudasa> for (list<std::string>::iterator iter = hostnames.begin(); iter != hostnames.end(); ++iter) {
721 20:06 < yehudasa> hostname_map["s3"].append(iter->second);
722 20:07 < yehudasa> hostname_map["s3website"].append(iter->second);
723 20:07 < yehudasa> s/append/push_back/g
724 20:08 < _robbat21irssi> inner loop over APIs
725 20:08 < yehudasa> yeah, probably
726 20:08 < _robbat21irssi> s3, s3website, swift, swith_auth, swift_website
727 */
728 map<std::string, list<std::string> > api_hostname_map;
729 map<std::string, list<std::string> > api_endpoints_map;
730
731 std::string realm_id;
732
733 rgw_sync_policy_info sync_policy;
734
735 RGWZoneGroup(): is_master(false){}
736 RGWZoneGroup(const std::string &id, const std::string &name):RGWSystemMetaObj(id, name) {}
737 explicit RGWZoneGroup(const std::string &_name):RGWSystemMetaObj(_name) {}
738 RGWZoneGroup(const std::string &_name, bool _is_master, CephContext *cct, RGWSI_SysObj* sysobj_svc,
739 const std::string& _realm_id, const list<std::string>& _endpoints)
740 : RGWSystemMetaObj(_name, cct , sysobj_svc), endpoints(_endpoints), is_master(_is_master),
741 realm_id(_realm_id) {}
742
743 bool is_master_zonegroup() const { return is_master;}
744 void update_master(bool _is_master) {
745 is_master = _is_master;
746 post_process_params();
747 }
748 void post_process_params();
749
750 void encode(bufferlist& bl) const override {
751 ENCODE_START(5, 1, bl);
752 encode(name, bl);
753 encode(api_name, bl);
754 encode(is_master, bl);
755 encode(endpoints, bl);
756 encode(master_zone, bl);
757 encode(zones, bl);
758 encode(placement_targets, bl);
759 encode(default_placement, bl);
760 encode(hostnames, bl);
761 encode(hostnames_s3website, bl);
762 RGWSystemMetaObj::encode(bl);
763 encode(realm_id, bl);
764 encode(sync_policy, bl);
765 ENCODE_FINISH(bl);
766 }
767
768 void decode(bufferlist::const_iterator& bl) override {
769 DECODE_START(5, bl);
770 decode(name, bl);
771 decode(api_name, bl);
772 decode(is_master, bl);
773 decode(endpoints, bl);
774 decode(master_zone, bl);
775 decode(zones, bl);
776 decode(placement_targets, bl);
777 decode(default_placement, bl);
778 if (struct_v >= 2) {
779 decode(hostnames, bl);
780 }
781 if (struct_v >= 3) {
782 decode(hostnames_s3website, bl);
783 }
784 if (struct_v >= 4) {
785 RGWSystemMetaObj::decode(bl);
786 decode(realm_id, bl);
787 } else {
788 id = name;
789 }
790 if (struct_v >= 5) {
791 decode(sync_policy, bl);
792 }
793 DECODE_FINISH(bl);
794 }
795
796 int read_default_id(std::string& default_id, bool old_format = false) override;
797 int set_as_default(bool exclusive = false) override;
798 int create_default(bool old_format = false);
799 int equals(const std::string& other_zonegroup) const;
800 int add_zone(const RGWZoneParams& zone_params, bool *is_master, bool *read_only,
801 const list<std::string>& endpoints, const std::string *ptier_type,
802 bool *psync_from_all, list<std::string>& sync_from,
803 list<std::string>& sync_from_rm, std::string *predirect_zone,
804 std::optional<int> bucket_index_max_shards, RGWSyncModulesManager *sync_mgr);
805 int remove_zone(const std::string& zone_id);
806 int rename_zone(const RGWZoneParams& zone_params);
807 rgw_pool get_pool(CephContext *cct) const override;
808 const std::string get_default_oid(bool old_region_format = false) const override;
809 const std::string& get_info_oid_prefix(bool old_region_format = false) const override;
810 const std::string& get_names_oid_prefix() const override;
811 const std::string& get_predefined_name(CephContext *cct) const override;
812
813 void dump(Formatter *f) const;
814 void decode_json(JSONObj *obj);
815 static void generate_test_instances(list<RGWZoneGroup*>& o);
816 };
817 WRITE_CLASS_ENCODER(RGWZoneGroup)
818
819 struct RGWPeriodMap
820 {
821 std::string id;
822 map<std::string, RGWZoneGroup> zonegroups;
823 map<std::string, RGWZoneGroup> zonegroups_by_api;
824 map<std::string, uint32_t> short_zone_ids;
825
826 std::string master_zonegroup;
827
828 void encode(bufferlist& bl) const;
829 void decode(bufferlist::const_iterator& bl);
830
831 int update(const RGWZoneGroup& zonegroup, CephContext *cct);
832
833 void dump(Formatter *f) const;
834 void decode_json(JSONObj *obj);
835
836 void reset() {
837 zonegroups.clear();
838 zonegroups_by_api.clear();
839 master_zonegroup.clear();
840 }
841
842 uint32_t get_zone_short_id(const std::string& zone_id) const;
843 };
844 WRITE_CLASS_ENCODER(RGWPeriodMap)
845
846 struct RGWPeriodConfig
847 {
848 RGWQuotaInfo bucket_quota;
849 RGWQuotaInfo user_quota;
850
851 void encode(bufferlist& bl) const {
852 ENCODE_START(1, 1, bl);
853 encode(bucket_quota, bl);
854 encode(user_quota, bl);
855 ENCODE_FINISH(bl);
856 }
857
858 void decode(bufferlist::const_iterator& bl) {
859 DECODE_START(1, bl);
860 decode(bucket_quota, bl);
861 decode(user_quota, bl);
862 DECODE_FINISH(bl);
863 }
864
865 void dump(Formatter *f) const;
866 void decode_json(JSONObj *obj);
867
868 // the period config must be stored in a local object outside of the period,
869 // so that it can be used in a default configuration where no realm/period
870 // exists
871 int read(RGWSI_SysObj *sysobj_svc, const std::string& realm_id);
872 int write(RGWSI_SysObj *sysobj_svc, const std::string& realm_id);
873
874 static std::string get_oid(const std::string& realm_id);
875 static rgw_pool get_pool(CephContext *cct);
876 };
877 WRITE_CLASS_ENCODER(RGWPeriodConfig)
878
879 /* for backward comaptability */
880 struct RGWRegionMap {
881
882 map<std::string, RGWZoneGroup> regions;
883
884 std::string master_region;
885
886 RGWQuotaInfo bucket_quota;
887 RGWQuotaInfo user_quota;
888
889 void encode(bufferlist& bl) const;
890 void decode(bufferlist::const_iterator& bl);
891
892 void dump(Formatter *f) const;
893 void decode_json(JSONObj *obj);
894 };
895 WRITE_CLASS_ENCODER(RGWRegionMap)
896
897 struct RGWZoneGroupMap {
898
899 map<std::string, RGWZoneGroup> zonegroups;
900 map<std::string, RGWZoneGroup> zonegroups_by_api;
901
902 std::string master_zonegroup;
903
904 RGWQuotaInfo bucket_quota;
905 RGWQuotaInfo user_quota;
906
907 /* construct the map */
908 int read(CephContext *cct, RGWSI_SysObj *sysobj_svc);
909
910 void encode(bufferlist& bl) const;
911 void decode(bufferlist::const_iterator& bl);
912
913 void dump(Formatter *f) const;
914 void decode_json(JSONObj *obj);
915 };
916 WRITE_CLASS_ENCODER(RGWZoneGroupMap)
917
918 class RGWRealm;
919 class RGWPeriod;
920
921 class RGWRealm : public RGWSystemMetaObj
922 {
923 std::string current_period;
924 epoch_t epoch{0}; //< realm epoch, incremented for each new period
925
926 int create_control(bool exclusive);
927 int delete_control();
928 public:
929 RGWRealm() {}
930 RGWRealm(const std::string& _id, const std::string& _name = "") : RGWSystemMetaObj(_id, _name) {}
931 RGWRealm(CephContext *_cct, RGWSI_SysObj *_sysobj_svc): RGWSystemMetaObj(_cct, _sysobj_svc) {}
932 RGWRealm(const std::string& _name, CephContext *_cct, RGWSI_SysObj *_sysobj_svc): RGWSystemMetaObj(_name, _cct, _sysobj_svc){}
933
934 void encode(bufferlist& bl) const override {
935 ENCODE_START(1, 1, bl);
936 RGWSystemMetaObj::encode(bl);
937 encode(current_period, bl);
938 encode(epoch, bl);
939 ENCODE_FINISH(bl);
940 }
941
942 void decode(bufferlist::const_iterator& bl) override {
943 DECODE_START(1, bl);
944 RGWSystemMetaObj::decode(bl);
945 decode(current_period, bl);
946 decode(epoch, bl);
947 DECODE_FINISH(bl);
948 }
949
950 int create(bool exclusive = true) override;
951 int delete_obj();
952 rgw_pool get_pool(CephContext *cct) const override;
953 const std::string get_default_oid(bool old_format = false) const override;
954 const std::string& get_names_oid_prefix() const override;
955 const std::string& get_info_oid_prefix(bool old_format = false) const override;
956 const std::string& get_predefined_name(CephContext *cct) const override;
957
958 using RGWSystemMetaObj::read_id; // expose as public for radosgw-admin
959
960 void dump(Formatter *f) const;
961 void decode_json(JSONObj *obj);
962 static void generate_test_instances(list<RGWRealm*>& o);
963
964 const std::string& get_current_period() const {
965 return current_period;
966 }
967 int set_current_period(RGWPeriod& period);
968 void clear_current_period_and_epoch() {
969 current_period.clear();
970 epoch = 0;
971 }
972 epoch_t get_epoch() const { return epoch; }
973
974 std::string get_control_oid() const;
975 /// send a notify on the realm control object
976 int notify_zone(bufferlist& bl);
977 /// notify the zone of a new period
978 int notify_new_period(const RGWPeriod& period);
979 };
980 WRITE_CLASS_ENCODER(RGWRealm)
981
982 struct RGWPeriodLatestEpochInfo {
983 epoch_t epoch = 0;
984
985 void encode(bufferlist& bl) const {
986 ENCODE_START(1, 1, bl);
987 encode(epoch, bl);
988 ENCODE_FINISH(bl);
989 }
990
991 void decode(bufferlist::const_iterator& bl) {
992 DECODE_START(1, bl);
993 decode(epoch, bl);
994 DECODE_FINISH(bl);
995 }
996
997 void dump(Formatter *f) const;
998 void decode_json(JSONObj *obj);
999 static void generate_test_instances(list<RGWPeriodLatestEpochInfo*>& o);
1000 };
1001 WRITE_CLASS_ENCODER(RGWPeriodLatestEpochInfo)
1002
1003
1004 /*
1005 * The RGWPeriod object contains the entire configuration of a
1006 * RGWRealm, including its RGWZoneGroups and RGWZones. Consistency of
1007 * this configuration is maintained across all zones by passing around
1008 * the RGWPeriod object in its JSON representation.
1009 *
1010 * If a new configuration changes which zone is the metadata master
1011 * zone (i.e., master zone of the master zonegroup), then a new
1012 * RGWPeriod::id (a uuid) is generated, its RGWPeriod::realm_epoch is
1013 * incremented, and the RGWRealm object is updated to reflect that new
1014 * current_period id and epoch. If the configuration changes BUT which
1015 * zone is the metadata master does NOT change, then only the
1016 * RGWPeriod::epoch is incremented (and the RGWPeriod::id remains the
1017 * same).
1018 *
1019 * When a new RGWPeriod is created with a new RGWPeriod::id (uuid), it
1020 * is linked back to its predecessor RGWPeriod through the
1021 * RGWPeriod::predecessor_uuid field, thus creating a "linked
1022 * list"-like structure of RGWPeriods back to the cluster's creation.
1023 */
1024 class RGWPeriod
1025 {
1026 std::string id; //< a uuid
1027 epoch_t epoch{0};
1028 std::string predecessor_uuid;
1029 std::vector<std::string> sync_status;
1030 RGWPeriodMap period_map;
1031 RGWPeriodConfig period_config;
1032 std::string master_zonegroup;
1033 rgw_zone_id master_zone;
1034
1035 std::string realm_id;
1036 std::string realm_name;
1037 epoch_t realm_epoch{1}; //< realm epoch when period was made current
1038
1039 CephContext *cct{nullptr};
1040 RGWSI_SysObj *sysobj_svc{nullptr};
1041
1042 int read_info();
1043 int read_latest_epoch(RGWPeriodLatestEpochInfo& epoch_info,
1044 RGWObjVersionTracker *objv = nullptr);
1045 int use_latest_epoch();
1046 int use_current_period();
1047
1048 const std::string get_period_oid() const;
1049 const std::string get_period_oid_prefix() const;
1050
1051 // gather the metadata sync status for each shard; only for use on master zone
1052 int update_sync_status(rgw::sal::RGWRadosStore *store,
1053 const RGWPeriod &current_period,
1054 std::ostream& error_stream, bool force_if_stale);
1055
1056 public:
1057 RGWPeriod() {}
1058
1059 explicit RGWPeriod(const std::string& period_id, epoch_t _epoch = 0)
1060 : id(period_id), epoch(_epoch) {}
1061
1062 const std::string& get_id() const { return id; }
1063 epoch_t get_epoch() const { return epoch; }
1064 epoch_t get_realm_epoch() const { return realm_epoch; }
1065 const std::string& get_predecessor() const { return predecessor_uuid; }
1066 const rgw_zone_id& get_master_zone() const { return master_zone; }
1067 const std::string& get_master_zonegroup() const { return master_zonegroup; }
1068 const std::string& get_realm() const { return realm_id; }
1069 const RGWPeriodMap& get_map() const { return period_map; }
1070 RGWPeriodConfig& get_config() { return period_config; }
1071 const RGWPeriodConfig& get_config() const { return period_config; }
1072 const std::vector<std::string>& get_sync_status() const { return sync_status; }
1073 rgw_pool get_pool(CephContext *cct) const;
1074 const std::string& get_latest_epoch_oid() const;
1075 const std::string& get_info_oid_prefix() const;
1076
1077 void set_user_quota(RGWQuotaInfo& user_quota) {
1078 period_config.user_quota = user_quota;
1079 }
1080
1081 void set_bucket_quota(RGWQuotaInfo& bucket_quota) {
1082 period_config.bucket_quota = bucket_quota;
1083 }
1084
1085 void set_id(const string& _id) {
1086 this->id = _id;
1087 period_map.id = _id;
1088 }
1089 void set_epoch(epoch_t epoch) { this->epoch = epoch; }
1090 void set_realm_epoch(epoch_t epoch) { realm_epoch = epoch; }
1091
1092 void set_predecessor(const std::string& predecessor)
1093 {
1094 predecessor_uuid = predecessor;
1095 }
1096
1097 void set_realm_id(const std::string& _realm_id) {
1098 realm_id = _realm_id;
1099 }
1100
1101 int reflect();
1102
1103 int get_zonegroup(RGWZoneGroup& zonegroup,
1104 const std::string& zonegroup_id) const;
1105
1106 bool is_single_zonegroup() const
1107 {
1108 return (period_map.zonegroups.size() <= 1);
1109 }
1110
1111 /*
1112 returns true if there are several zone groups with a least one zone
1113 */
1114 bool is_multi_zonegroups_with_zones() const
1115 {
1116 int count = 0;
1117 for (const auto& zg: period_map.zonegroups) {
1118 if (zg.second.zones.size() > 0) {
1119 if (count++ > 0) {
1120 return true;
1121 }
1122 }
1123 }
1124 return false;
1125 }
1126
1127 int get_latest_epoch(epoch_t& epoch);
1128 int set_latest_epoch(epoch_t epoch, bool exclusive = false,
1129 RGWObjVersionTracker *objv = nullptr);
1130 // update latest_epoch if the given epoch is higher, else return -EEXIST
1131 int update_latest_epoch(epoch_t epoch);
1132
1133 int init(CephContext *_cct, RGWSI_SysObj *_sysobj_svc, const std::string &period_realm_id, const std::string &period_realm_name = "",
1134 bool setup_obj = true);
1135 int init(CephContext *_cct, RGWSI_SysObj *_sysobj_svc, bool setup_obj = true);
1136
1137 int create(bool exclusive = true);
1138 int delete_obj();
1139 int store_info(bool exclusive);
1140 int add_zonegroup(const RGWZoneGroup& zonegroup);
1141
1142 void fork();
1143 int update();
1144
1145 // commit a staging period; only for use on master zone
1146 int commit(rgw::sal::RGWRadosStore *store,
1147 RGWRealm& realm, const RGWPeriod &current_period,
1148 std::ostream& error_stream, bool force_if_stale = false);
1149
1150 void encode(bufferlist& bl) const {
1151 ENCODE_START(1, 1, bl);
1152 encode(id, bl);
1153 encode(epoch, bl);
1154 encode(realm_epoch, bl);
1155 encode(predecessor_uuid, bl);
1156 encode(sync_status, bl);
1157 encode(period_map, bl);
1158 encode(master_zone, bl);
1159 encode(master_zonegroup, bl);
1160 encode(period_config, bl);
1161 encode(realm_id, bl);
1162 encode(realm_name, bl);
1163 ENCODE_FINISH(bl);
1164 }
1165
1166 void decode(bufferlist::const_iterator& bl) {
1167 DECODE_START(1, bl);
1168 decode(id, bl);
1169 decode(epoch, bl);
1170 decode(realm_epoch, bl);
1171 decode(predecessor_uuid, bl);
1172 decode(sync_status, bl);
1173 decode(period_map, bl);
1174 decode(master_zone, bl);
1175 decode(master_zonegroup, bl);
1176 decode(period_config, bl);
1177 decode(realm_id, bl);
1178 decode(realm_name, bl);
1179 DECODE_FINISH(bl);
1180 }
1181 void dump(Formatter *f) const;
1182 void decode_json(JSONObj *obj);
1183 static void generate_test_instances(list<RGWPeriod*>& o);
1184
1185 static std::string get_staging_id(const std::string& realm_id) {
1186 return realm_id + ":staging";
1187 }
1188 };
1189 WRITE_CLASS_ENCODER(RGWPeriod)
1190
1191 #endif