return RGWSystemMetaObj::read_default_id(default_id, old_format);
}
-int RGWZoneGroup::set_as_default()
+int RGWZoneGroup::set_as_default(bool exclusive)
{
if (realm_id.empty()) {
/* try using default realm */
realm_id = realm.get_id();
}
- return RGWSystemMetaObj::set_as_default();
+ return RGWSystemMetaObj::set_as_default(exclusive);
}
int RGWSystemMetaObj::init(CephContext *_cct, RGWRados *_store, bool setup_obj, bool old_format)
return read_default_id(id, old_format);
}
-int RGWSystemMetaObj::set_as_default()
+int RGWSystemMetaObj::set_as_default(bool exclusive)
{
string pool_name = get_pool_name(cct);
string oid = get_default_oid();
::encode(default_info, bl);
- int ret = rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), false, NULL, real_time(), NULL);
+ int ret = rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(),
+ exclusive, NULL, real_time(), NULL);
if (ret < 0)
return ret;
int RGWRealm::create(bool exclusive)
{
- list<string> realms;
- int ret = store->list_realms(realms);
- if (ret < 0 && ret != -ENOENT) {
- ldout(cct, 0) << "ERROR: listing realms, ret=" << ret << dendl;
- return ret;
- }
-
- bool first_realm = realms.empty();
-
- ret = RGWSystemMetaObj::create(exclusive);
+ int ret = RGWSystemMetaObj::create(exclusive);
if (ret < 0) {
ldout(cct, 0) << "ERROR creating new realm object " << name << ": " << cpp_strerror(-ret) << dendl;
return ret;
ldout(cct, 0) << "ERROR: failed set current period " << current_period << dendl;
return ret;
}
-
- if (first_realm) { /* this is racy, but it's fine */
- ret = set_as_default();
- if (ret < 0) {
- ldout(cct, 0) << "WARNING: failed to set realm as default realm, ret=" << ret << dendl;
- }
+ // try to set as default. may race with another create, so pass exclusive=true
+ // so we don't override an existing default
+ ret = set_as_default(true);
+ if (ret < 0 && ret != -EEXIST) {
+ ldout(cct, 0) << "WARNING: failed to set realm as default realm, ret=" << ret << dendl;
}
return 0;
int RGWZoneParams::create(bool exclusive)
{
- list<string> zones;
- int r = store->list_zones(zones);
- if (r < 0) {
- ldout(cct, 10) << "WARNING: store->list_zones() returned r=" << r << dendl;
- }
-
/* check for old pools config */
rgw_obj obj(domain_root, avail_pools);
- r = store->raw_obj_stat(obj, NULL, NULL, NULL, NULL, NULL, NULL);
+ int r = store->raw_obj_stat(obj, NULL, NULL, NULL, NULL, NULL, NULL);
if (r < 0) {
ldout(store->ctx(), 10) << "couldn't find old data placement pools config, setting up new ones for the zone" << dendl;
/* a new system, let's set new placement info */
return r;
}
- if (zones.empty()) { /* first zone? maybe, it's a racy check */
- r = set_as_default();
- if (r < 0) {
- ldout(cct, 10) << "WARNING: failed to set zone as default, r=" << r << dendl;
- }
+ // try to set as default. may race with another create, so pass exclusive=true
+ // so we don't override an existing default
+ r = set_as_default(true);
+ if (r < 0 && r != -EEXIST) {
+ ldout(cct, 10) << "WARNING: failed to set zone as default, r=" << r << dendl;
}
return 0;
}
-int RGWZoneParams::set_as_default()
+int RGWZoneParams::set_as_default(bool exclusive)
{
if (realm_id.empty()) {
/* try using default realm */
realm_id = realm.get_id();
}
- return RGWSystemMetaObj::set_as_default();
+ return RGWSystemMetaObj::set_as_default(exclusive);
}
void RGWPeriodMap::encode(bufferlist& bl) const {
}
int init(CephContext *_cct, RGWRados *_store, bool setup_obj = true, bool old_format = false);
virtual int read_default_id(string& default_id, bool old_format = false);
- virtual int set_as_default();
+ virtual int set_as_default(bool exclusive = false);
int delete_default();
virtual int create(bool exclusive = true);
int delete_obj(bool old_format = false);
bool old_format = false);
using RGWSystemMetaObj::init;
int read_default_id(string& default_id, bool old_format = false);
- int set_as_default();
+ int set_as_default(bool exclusive = false) override;
int create_default(bool old_format = false);
int create(bool exclusive = true);
int fix_pool_names();
}
int read_default_id(string& default_id, bool old_format = false);
- int set_as_default();
+ int set_as_default(bool exclusive = false) override;
int create_default(bool old_format = false);
int equals(const string& other_zonegroup) const;
int add_zone(const RGWZoneParams& zone_params, bool *is_master, bool *read_only, const list<string>& endpoints);