1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #ifndef CEPH_RGW_ZONE_H
5 #define CEPH_RGW_ZONE_H
7 #include "rgw_common.h"
8 #include "rgw_sync_policy.h"
10 namespace rgw_zone_defaults
{
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
;
34 class RGWSyncModulesManager
;
40 void encode(bufferlist
& bl
) const {
41 ENCODE_START(1, 1, bl
);
46 void decode(bufferlist::const_iterator
& bl
) {
52 void dump(Formatter
*f
) const;
53 void decode_json(JSONObj
*obj
);
55 WRITE_CLASS_ENCODER(RGWNameToId
)
57 struct RGWDefaultSystemMetaObjInfo
{
58 std::string default_id
;
60 void encode(bufferlist
& bl
) const {
61 ENCODE_START(1, 1, bl
);
62 encode(default_id
, bl
);
66 void decode(bufferlist::const_iterator
& bl
) {
68 decode(default_id
, bl
);
72 void dump(Formatter
*f
) const;
73 void decode_json(JSONObj
*obj
);
75 WRITE_CLASS_ENCODER(RGWDefaultSystemMetaObjInfo
)
80 class RGWSystemMetaObj
{
85 CephContext
*cct
{nullptr};
86 RGWSI_SysObj
*sysobj_svc
{nullptr};
87 RGWSI_Zone
*zone_svc
{nullptr};
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);
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
);
105 RGWSystemMetaObj(const std::string
& _name
, CephContext
*_cct
, RGWSI_SysObj
*_sysobj_svc
): name(_name
) {
106 reinit_instance(_cct
, _sysobj_svc
);
109 const std::string
& get_name() const { return name
; }
110 const std::string
& get_id() const { return id
; }
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(); }
116 virtual ~RGWSystemMetaObj() {}
118 virtual void encode(bufferlist
& bl
) const {
119 ENCODE_START(1, 1, bl
);
125 virtual void decode(bufferlist::const_iterator
& bl
) {
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);}
143 int write(bool exclusive
);
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;
151 void dump(Formatter
*f
) const;
152 void decode_json(JSONObj
*obj
);
154 WRITE_CLASS_ENCODER(RGWSystemMetaObj
)
156 struct RGWZoneStorageClass
{
157 boost::optional
<rgw_pool
> data_pool
;
158 boost::optional
<std::string
> compression_type
;
160 void encode(bufferlist
& bl
) const {
161 ENCODE_START(1, 1, bl
);
162 encode(data_pool
, bl
);
163 encode(compression_type
, bl
);
167 void decode(bufferlist::const_iterator
& bl
) {
169 decode(data_pool
, bl
);
170 decode(compression_type
, bl
);
174 void dump(Formatter
*f
) const;
175 void decode_json(JSONObj
*obj
);
177 WRITE_CLASS_ENCODER(RGWZoneStorageClass
)
180 class RGWZoneStorageClasses
{
181 map
<string
, RGWZoneStorageClass
> m
;
184 RGWZoneStorageClass
*standard_class
;
187 RGWZoneStorageClasses() {
188 standard_class
= &m
[RGW_STORAGE_CLASS_STANDARD
];
190 RGWZoneStorageClasses(const RGWZoneStorageClasses
& rhs
) {
192 standard_class
= &m
[RGW_STORAGE_CLASS_STANDARD
];
194 RGWZoneStorageClasses
& operator=(const RGWZoneStorageClasses
& rhs
) {
196 standard_class
= &m
[RGW_STORAGE_CLASS_STANDARD
];
200 const RGWZoneStorageClass
& get_standard() const {
201 return *standard_class
;
204 bool find(const string
& sc
, const RGWZoneStorageClass
**pstorage_class
) const {
205 auto iter
= m
.find(sc
);
206 if (iter
== m
.end()) {
209 *pstorage_class
= &iter
->second
;
213 bool exists(const string
& sc
) const {
217 auto iter
= m
.find(sc
);
218 return (iter
!= m
.end());
221 const map
<string
, RGWZoneStorageClass
>& get_all() const {
225 map
<string
, RGWZoneStorageClass
>& get_all() {
229 void set_storage_class(const string
& sc
, const rgw_pool
*data_pool
, const string
*compression_type
) {
230 const string
*psc
= &sc
;
232 psc
= &RGW_STORAGE_CLASS_STANDARD
;
234 RGWZoneStorageClass
& storage_class
= m
[*psc
];
236 storage_class
.data_pool
= *data_pool
;
238 if (compression_type
) {
239 storage_class
.compression_type
= *compression_type
;
243 void remove_storage_class(const string
& sc
) {
249 void encode(bufferlist
& bl
) const {
250 ENCODE_START(1, 1, bl
);
255 void decode(bufferlist::const_iterator
& bl
) {
258 standard_class
= &m
[RGW_STORAGE_CLASS_STANDARD
];
262 void dump(Formatter
*f
) const;
263 void decode_json(JSONObj
*obj
);
265 WRITE_CLASS_ENCODER(RGWZoneStorageClasses
)
267 struct RGWZonePlacementInfo
{
269 rgw_pool data_extra_pool
; /* if not set we should use data_pool */
270 RGWZoneStorageClasses storage_classes
;
271 RGWBucketIndexType index_type
;
273 RGWZonePlacementInfo() : index_type(RGWBIType_Normal
) {}
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
);
288 void decode(bufferlist::const_iterator
& 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
);
297 string data_extra_pool_str
;
298 decode(data_extra_pool_str
, bl
);
299 data_extra_pool
= rgw_pool(data_extra_pool_str
);
304 index_type
= (RGWBucketIndexType
)it
;
306 string standard_compression_type
;
308 decode(standard_compression_type
, bl
);
311 decode(storage_classes
, bl
);
313 storage_classes
.set_storage_class(RGW_STORAGE_CLASS_STANDARD
, &standard_data_pool
,
314 (!standard_compression_type
.empty() ? &standard_compression_type
: nullptr));
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
);
323 return data_extra_pool
;
325 const rgw_pool
& get_data_pool(const string
& sc
) const {
326 const RGWZoneStorageClass
*storage_class
;
327 static rgw_pool no_pool
;
329 if (!storage_classes
.find(sc
, &storage_class
)) {
330 return storage_classes
.get_standard().data_pool
.get_value_or(no_pool
);
333 return storage_class
->data_pool
.get_value_or(no_pool
);
335 const rgw_pool
& get_standard_data_pool() const {
336 return get_data_pool(RGW_STORAGE_CLASS_STANDARD
);
339 const string
& get_compression_type(const string
& sc
) const {
340 const RGWZoneStorageClass
*storage_class
;
341 static string no_compression
;
343 if (!storage_classes
.find(sc
, &storage_class
)) {
344 return no_compression
;
346 return storage_class
->compression_type
.get_value_or(no_compression
);
349 bool storage_class_exists(const string
& sc
) const {
350 return storage_classes
.exists(sc
);
353 void dump(Formatter
*f
) const;
354 void decode_json(JSONObj
*obj
);
357 WRITE_CLASS_ENCODER(RGWZonePlacementInfo
)
359 struct RGWZoneParams
: RGWSystemMetaObj
{
360 rgw_pool domain_root
;
361 rgw_pool control_pool
;
365 rgw_pool intent_log_pool
;
366 rgw_pool usage_log_pool
;
368 rgw_pool user_keys_pool
;
369 rgw_pool user_email_pool
;
370 rgw_pool user_swift_pool
;
371 rgw_pool user_uid_pool
;
373 rgw_pool reshard_pool
;
376 RGWAccessKey system_key
;
378 map
<std::string
, RGWZonePlacementInfo
> placement_pools
;
380 std::string realm_id
;
382 JSONFormattable tier_config
;
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
) {}
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
;
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();
405 const string
& get_compression_type(const rgw_placement_rule
& placement_rule
) const;
407 void encode(bufferlist
& bl
) const override
{
408 ENCODE_START(12, 1, bl
);
409 encode(domain_root
, bl
);
410 encode(control_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
);
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
);
435 void decode(bufferlist::const_iterator
& bl
) override
{
436 DECODE_START(12, bl
);
437 decode(domain_root
, bl
);
438 decode(control_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
);
448 RGWSystemMetaObj::decode(bl
);
449 } else if (struct_v
>= 2) {
454 decode(system_key
, bl
);
456 decode(placement_pools
, bl
);
458 rgw_pool unused_metadata_heap
;
459 decode(unused_metadata_heap
, bl
);
462 decode(realm_id
, bl
);
467 lc_pool
= log_pool
.name
+ ":lc";
469 map
<std::string
, std::string
, ltstr_nocase
> old_tier_config
;
471 decode(old_tier_config
, bl
);
474 decode(roles_pool
, bl
);
476 roles_pool
= name
+ ".rgw.meta:roles";
478 if (struct_v
>= 10) {
479 decode(reshard_pool
, bl
);
481 reshard_pool
= log_pool
.name
+ ":reshard";
483 if (struct_v
>= 11) {
484 ::decode(otp_pool
, bl
);
486 otp_pool
= name
+ ".rgw.otp";
488 if (struct_v
>= 12) {
489 ::decode(tier_config
, bl
);
491 for (auto& kv
: old_tier_config
) {
492 tier_config
.set(kv
.first
, kv
.second
);
497 void dump(Formatter
*f
) const;
498 void decode_json(JSONObj
*obj
);
499 static void generate_test_instances(list
<RGWZoneParams
*>& o
);
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()) {
506 *placement
= iter
->second
;
511 * return data pool of the head object
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
;
519 *pool
= explicit_placement
.get_data_extra_pool();
523 if (placement_rule
.empty()) {
526 auto iter
= placement_pools
.find(placement_rule
.name
);
527 if (iter
== placement_pools
.end()) {
530 if (!obj
.in_extra_data
) {
531 *pool
= iter
->second
.get_data_pool(placement_rule
.storage_class
);
533 *pool
= iter
->second
.get_data_extra_pool();
538 bool valid_placement(const rgw_placement_rule
& rule
) const {
539 auto iter
= placement_pools
.find(rule
.name
);
540 if (iter
== placement_pools
.end()) {
543 return iter
->second
.storage_class_exists(rule
.storage_class
);
546 WRITE_CLASS_ENCODER(RGWZoneParams
)
551 list
<std::string
> endpoints
;
555 std::string tier_type
;
557 std::string redirect_zone
;
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.
566 uint32_t bucket_index_max_shards
;
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;
574 set
<std::string
> sync_from
; /* list of zones to sync from */
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) {}
581 void encode(bufferlist
& bl
) const {
582 ENCODE_START(7, 1, bl
);
584 encode(endpoints
, bl
);
585 encode(log_meta
, bl
);
586 encode(log_data
, bl
);
587 encode(bucket_index_max_shards
, 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
);
597 void decode(bufferlist::const_iterator
& bl
) {
603 decode(endpoints
, bl
);
605 decode(log_meta
, bl
);
606 decode(log_data
, bl
);
609 decode(bucket_index_max_shards
, bl
);
613 decode(read_only
, bl
);
616 decode(tier_type
, bl
);
619 decode(sync_from_all
, bl
);
620 decode(sync_from
, bl
);
623 decode(redirect_zone
, bl
);
627 void dump(Formatter
*f
) const;
628 void decode_json(JSONObj
*obj
);
629 static void generate_test_instances(list
<RGWZone
*>& o
);
631 bool is_read_only() const { return read_only
; }
633 bool syncs_from(const std::string
& zone_name
) const {
634 return (sync_from_all
|| sync_from
.find(zone_name
) != sync_from
.end());
637 WRITE_CLASS_ENCODER(RGWZone
)
639 struct RGWDefaultZoneGroupInfo
{
640 std::string default_zonegroup
;
642 void encode(bufferlist
& bl
) const {
643 ENCODE_START(1, 1, bl
);
644 encode(default_zonegroup
, bl
);
648 void decode(bufferlist::const_iterator
& bl
) {
650 decode(default_zonegroup
, bl
);
653 void dump(Formatter
*f
) const;
654 void decode_json(JSONObj
*obj
);
655 //todo: implement ceph-dencoder
657 WRITE_CLASS_ENCODER(RGWDefaultZoneGroupInfo
)
659 struct RGWZoneGroupPlacementTarget
{
661 set
<std::string
> tags
;
662 set
<std::string
> storage_classes
;
664 bool user_permitted(const list
<std::string
>& user_tags
) const {
668 for (auto& rule
: user_tags
) {
669 if (tags
.find(rule
) != tags
.end()) {
676 void encode(bufferlist
& bl
) const {
677 ENCODE_START(2, 1, bl
);
680 encode(storage_classes
, bl
);
684 void decode(bufferlist::const_iterator
& bl
) {
689 decode(storage_classes
, bl
);
691 if (storage_classes
.empty()) {
692 storage_classes
.insert(RGW_STORAGE_CLASS_STANDARD
);
696 void dump(Formatter
*f
) const;
697 void decode_json(JSONObj
*obj
);
699 WRITE_CLASS_ENCODER(RGWZoneGroupPlacementTarget
)
701 struct RGWZoneGroup
: public RGWSystemMetaObj
{
702 std::string api_name
;
703 list
<std::string
> endpoints
;
704 bool is_master
= false;
706 rgw_zone_id master_zone
;
707 map
<rgw_zone_id
, RGWZone
> zones
;
709 map
<std::string
, RGWZoneGroupPlacementTarget
> placement_targets
;
710 rgw_placement_rule default_placement
;
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
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
728 map
<std::string
, list
<std::string
> > api_hostname_map
;
729 map
<std::string
, list
<std::string
> > api_endpoints_map
;
731 std::string realm_id
;
733 rgw_sync_policy_info sync_policy
;
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
) {}
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();
748 void post_process_params();
750 void encode(bufferlist
& bl
) const override
{
751 ENCODE_START(5, 1, bl
);
753 encode(api_name
, bl
);
754 encode(is_master
, bl
);
755 encode(endpoints
, bl
);
756 encode(master_zone
, 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
);
768 void decode(bufferlist::const_iterator
& bl
) override
{
771 decode(api_name
, bl
);
772 decode(is_master
, bl
);
773 decode(endpoints
, bl
);
774 decode(master_zone
, bl
);
776 decode(placement_targets
, bl
);
777 decode(default_placement
, bl
);
779 decode(hostnames
, bl
);
782 decode(hostnames_s3website
, bl
);
785 RGWSystemMetaObj::decode(bl
);
786 decode(realm_id
, bl
);
791 decode(sync_policy
, bl
);
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
;
813 void dump(Formatter
*f
) const;
814 void decode_json(JSONObj
*obj
);
815 static void generate_test_instances(list
<RGWZoneGroup
*>& o
);
817 WRITE_CLASS_ENCODER(RGWZoneGroup
)
822 map
<std::string
, RGWZoneGroup
> zonegroups
;
823 map
<std::string
, RGWZoneGroup
> zonegroups_by_api
;
824 map
<std::string
, uint32_t> short_zone_ids
;
826 std::string master_zonegroup
;
828 void encode(bufferlist
& bl
) const;
829 void decode(bufferlist::const_iterator
& bl
);
831 int update(const RGWZoneGroup
& zonegroup
, CephContext
*cct
);
833 void dump(Formatter
*f
) const;
834 void decode_json(JSONObj
*obj
);
838 zonegroups_by_api
.clear();
839 master_zonegroup
.clear();
842 uint32_t get_zone_short_id(const std::string
& zone_id
) const;
844 WRITE_CLASS_ENCODER(RGWPeriodMap
)
846 struct RGWPeriodConfig
848 RGWQuotaInfo bucket_quota
;
849 RGWQuotaInfo user_quota
;
851 void encode(bufferlist
& bl
) const {
852 ENCODE_START(1, 1, bl
);
853 encode(bucket_quota
, bl
);
854 encode(user_quota
, bl
);
858 void decode(bufferlist::const_iterator
& bl
) {
860 decode(bucket_quota
, bl
);
861 decode(user_quota
, bl
);
865 void dump(Formatter
*f
) const;
866 void decode_json(JSONObj
*obj
);
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
871 int read(RGWSI_SysObj
*sysobj_svc
, const std::string
& realm_id
);
872 int write(RGWSI_SysObj
*sysobj_svc
, const std::string
& realm_id
);
874 static std::string
get_oid(const std::string
& realm_id
);
875 static rgw_pool
get_pool(CephContext
*cct
);
877 WRITE_CLASS_ENCODER(RGWPeriodConfig
)
879 /* for backward comaptability */
880 struct RGWRegionMap
{
882 map
<std::string
, RGWZoneGroup
> regions
;
884 std::string master_region
;
886 RGWQuotaInfo bucket_quota
;
887 RGWQuotaInfo user_quota
;
889 void encode(bufferlist
& bl
) const;
890 void decode(bufferlist::const_iterator
& bl
);
892 void dump(Formatter
*f
) const;
893 void decode_json(JSONObj
*obj
);
895 WRITE_CLASS_ENCODER(RGWRegionMap
)
897 struct RGWZoneGroupMap
{
899 map
<std::string
, RGWZoneGroup
> zonegroups
;
900 map
<std::string
, RGWZoneGroup
> zonegroups_by_api
;
902 std::string master_zonegroup
;
904 RGWQuotaInfo bucket_quota
;
905 RGWQuotaInfo user_quota
;
907 /* construct the map */
908 int read(CephContext
*cct
, RGWSI_SysObj
*sysobj_svc
);
910 void encode(bufferlist
& bl
) const;
911 void decode(bufferlist::const_iterator
& bl
);
913 void dump(Formatter
*f
) const;
914 void decode_json(JSONObj
*obj
);
916 WRITE_CLASS_ENCODER(RGWZoneGroupMap
)
921 class RGWRealm
: public RGWSystemMetaObj
923 std::string current_period
;
924 epoch_t epoch
{0}; //< realm epoch, incremented for each new period
926 int create_control(bool exclusive
);
927 int delete_control();
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
){}
934 void encode(bufferlist
& bl
) const override
{
935 ENCODE_START(1, 1, bl
);
936 RGWSystemMetaObj::encode(bl
);
937 encode(current_period
, bl
);
942 void decode(bufferlist::const_iterator
& bl
) override
{
944 RGWSystemMetaObj::decode(bl
);
945 decode(current_period
, bl
);
950 int create(bool exclusive
= true) override
;
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
;
958 using RGWSystemMetaObj::read_id
; // expose as public for radosgw-admin
960 void dump(Formatter
*f
) const;
961 void decode_json(JSONObj
*obj
);
962 static void generate_test_instances(list
<RGWRealm
*>& o
);
964 const std::string
& get_current_period() const {
965 return current_period
;
967 int set_current_period(RGWPeriod
& period
);
968 void clear_current_period_and_epoch() {
969 current_period
.clear();
972 epoch_t
get_epoch() const { return epoch
; }
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
);
980 WRITE_CLASS_ENCODER(RGWRealm
)
982 struct RGWPeriodLatestEpochInfo
{
985 void encode(bufferlist
& bl
) const {
986 ENCODE_START(1, 1, bl
);
991 void decode(bufferlist::const_iterator
& bl
) {
997 void dump(Formatter
*f
) const;
998 void decode_json(JSONObj
*obj
);
999 static void generate_test_instances(list
<RGWPeriodLatestEpochInfo
*>& o
);
1001 WRITE_CLASS_ENCODER(RGWPeriodLatestEpochInfo
)
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.
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
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.
1026 std::string id
; //< a uuid
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
;
1035 std::string realm_id
;
1036 std::string realm_name
;
1037 epoch_t realm_epoch
{1}; //< realm epoch when period was made current
1039 CephContext
*cct
{nullptr};
1040 RGWSI_SysObj
*sysobj_svc
{nullptr};
1043 int read_latest_epoch(RGWPeriodLatestEpochInfo
& epoch_info
,
1044 RGWObjVersionTracker
*objv
= nullptr);
1045 int use_latest_epoch();
1046 int use_current_period();
1048 const std::string
get_period_oid() const;
1049 const std::string
get_period_oid_prefix() const;
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
¤t_period
,
1054 std::ostream
& error_stream
, bool force_if_stale
);
1059 explicit RGWPeriod(const std::string
& period_id
, epoch_t _epoch
= 0)
1060 : id(period_id
), epoch(_epoch
) {}
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;
1077 void set_user_quota(RGWQuotaInfo
& user_quota
) {
1078 period_config
.user_quota
= user_quota
;
1081 void set_bucket_quota(RGWQuotaInfo
& bucket_quota
) {
1082 period_config
.bucket_quota
= bucket_quota
;
1085 void set_id(const string
& _id
) {
1087 period_map
.id
= _id
;
1089 void set_epoch(epoch_t epoch
) { this->epoch
= epoch
; }
1090 void set_realm_epoch(epoch_t epoch
) { realm_epoch
= epoch
; }
1092 void set_predecessor(const std::string
& predecessor
)
1094 predecessor_uuid
= predecessor
;
1097 void set_realm_id(const std::string
& _realm_id
) {
1098 realm_id
= _realm_id
;
1103 int get_zonegroup(RGWZoneGroup
& zonegroup
,
1104 const std::string
& zonegroup_id
) const;
1106 bool is_single_zonegroup() const
1108 return (period_map
.zonegroups
.size() <= 1);
1112 returns true if there are several zone groups with a least one zone
1114 bool is_multi_zonegroups_with_zones() const
1117 for (const auto& zg
: period_map
.zonegroups
) {
1118 if (zg
.second
.zones
.size() > 0) {
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
);
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);
1137 int create(bool exclusive
= true);
1139 int store_info(bool exclusive
);
1140 int add_zonegroup(const RGWZoneGroup
& zonegroup
);
1145 // commit a staging period; only for use on master zone
1146 int commit(rgw::sal::RGWRadosStore
*store
,
1147 RGWRealm
& realm
, const RGWPeriod
¤t_period
,
1148 std::ostream
& error_stream
, bool force_if_stale
= false);
1150 void encode(bufferlist
& bl
) const {
1151 ENCODE_START(1, 1, 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
);
1166 void decode(bufferlist::const_iterator
& bl
) {
1167 DECODE_START(1, 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
);
1181 void dump(Formatter
*f
) const;
1182 void decode_json(JSONObj
*obj
);
1183 static void generate_test_instances(list
<RGWPeriod
*>& o
);
1185 static std::string
get_staging_id(const std::string
& realm_id
) {
1186 return realm_id
+ ":staging";
1189 WRITE_CLASS_ENCODER(RGWPeriod
)