From: Yehuda Sadeh Date: Fri, 19 Jul 2013 16:44:43 +0000 (-0700) Subject: rgw: replace logic that compares regions X-Git-Tag: v0.67-rc1~16^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4e05786a58a1218e1b68d5fbcddefa7a72ac03ce;p=ceph.git rgw: replace logic that compares regions The logic was a bit broken. Basically, we want to make sure that region names are the same. However, if region name is not set then we need to check whether it's the master region. This can happen in upgrade cases where originally we didn't have a region name set. Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 644f8a8921d4..6a9d2319de78 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -334,8 +334,7 @@ static int rgw_build_policies(RGWRados *store, struct req_state *s, bool only_bu ret = store->get_bucket_info(s->obj_ctx, copy_source_str, source_info, NULL); if (ret == 0) { string& region = source_info.region; - s->local_source = (region.empty() && store->region.is_master) || - (region == store->region.name); + s->local_source = store->region.equals(region); } } @@ -362,8 +361,7 @@ static int rgw_build_policies(RGWRados *store, struct req_state *s, bool only_bu s->bucket_owner = s->bucket_acl->get_owner(); string& region = s->bucket_info.region; - if (s->bucket_exists && ((region.empty() && !store->region.is_master) || - (region != store->region.name))) { + if (s->bucket_exists && !store->region.equals(region)) { ldout(s->cct, 0) << "NOTICE: request for data in a different region (" << region << " != " << store->region.name << ")" << dendl; /* we now need to make sure that the operation actually requires copy source, that is * it's a copy operation diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index a8061e99bf1a..e3312d9d3735 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -259,6 +259,13 @@ int RGWRegion::store_info(bool exclusive) return ret; } +int RGWRegion::equals(const string& other_region) +{ + if (is_master && other_region.empty()) + return true; + + return (name == other_region); +} void RGWZoneParams::init_default(RGWRados *store) { @@ -429,8 +436,7 @@ int RGWRegionMap::update(RGWRegion& region) { Mutex::Locker l(lock); - if (region.is_master && !master_region.empty() && - master_region.compare(region.name) != 0) { + if (region.is_master && !region.equals(master_region)) { derr << "cannot update region map, master_region conflict" << dendl; return -EINVAL; } @@ -1938,8 +1944,7 @@ int RGWRados::set_bucket_location_by_rule(const string& location_rule, const std map::iterator piter = zone.placement_pools.find(location_rule); if (piter == zone.placement_pools.end()) { /* couldn't find, means we cannot really place data for this bucket in this zone */ - if ((region_name.empty() && region.is_master) || - region_name == region.name) { + if (region.equals(region_name)) { /* that's a configuration error, zone should have that rule, as we're within the requested * region */ return -EINVAL; @@ -2486,11 +2491,8 @@ int RGWRados::copy_obj(void *ctx, append_rand_alpha(cct, dest_obj.object, shadow_oid, 32); shadow_obj.init_ns(dest_obj.bucket, shadow_oid, shadow_ns); - remote_dest = ((dest_bucket_info.region.empty() && !region.is_master) || - (dest_bucket_info.region != region.name)); - - remote_src = ((src_bucket_info.region.empty() && !region.is_master) || - (src_bucket_info.region != region.name)); + remote_dest = !region.equals(dest_bucket_info.region); + remote_src = !region.equals(src_bucket_info.region); if (remote_src && remote_dest) { ldout(cct, 0) << "ERROR: can't copy object when both src and dest buckets are remote" << dendl; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 99e66a91b1cf..e083879b5825 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -619,6 +619,7 @@ struct RGWRegion { int read_info(const string& region_name); int read_default(RGWDefaultRegionInfo& default_region); int set_as_default(); + int equals(const string& other_region); static string get_pool_name(CephContext *cct);