From 31e3104b47e97327bba812418ccd9130ce3adee7 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Fri, 29 Apr 2016 17:47:07 -0400 Subject: [PATCH] rgw: check for short_zone_id collisions on period update Signed-off-by: Casey Bodley --- src/rgw/rgw_rados.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index f1d7bfcdff78..38e9ddc98e4c 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -1654,11 +1654,24 @@ int RGWPeriodMap::update(const RGWZoneGroup& zonegroup, CephContext *cct) } for (auto& i : zonegroup.zones) { - string& zone_id = i.second.id; - if (short_zone_ids.find(zone_id) == short_zone_ids.end()) { - uint32_t short_id = gen_short_zone_id(zone_id); - short_zone_ids[i.second.id] = short_id; + auto& zone = i.second; + if (short_zone_ids.find(zone.id) != short_zone_ids.end()) { + continue; } + // calculate the zone's short id + uint32_t short_id = gen_short_zone_id(zone.id); + + // search for an existing zone with the same short id + for (auto& s : short_zone_ids) { + if (s.second == short_id) { + ldout(cct, 0) << "New zone '" << zone.name << "' (" << zone.id + << ") generates the same short_zone_id " << short_id + << " as existing zone id " << s.first << dendl; + return -EEXIST; + } + } + + short_zone_ids[zone.id] = short_id; } return 0; -- 2.47.3