]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix missing master zone for a single zone zonegroup 12315/head
authorOrit Wasserman <owasserm@redhat.com>
Thu, 10 Nov 2016 15:17:05 +0000 (16:17 +0100)
committerLoic Dachary <ldachary@redhat.com>
Mon, 5 Dec 2016 09:34:19 +0000 (10:34 +0100)
Fixes: http://tracker.ceph.com/issues/17364
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
(cherry picked from commit 0870b00c77fb4933399a082df8ffc37e51040820)

src/rgw/rgw_rados.cc

index a95a2e244a1dd52044d16f1372a57bfc21e5ccd6..3c5355465c3edbe73166c173e6fdbd04c01ddd81 100644 (file)
@@ -3596,9 +3596,29 @@ int RGWRados::init_zg_from_period(bool *initialized)
     // use endpoints from the zonegroup's master zone
     auto master = zg.zones.find(zg.master_zone);
     if (master == zg.zones.end()) {
-      ldout(cct, 0) << "zonegroup " << zg.get_name() << " missing zone for "
-          "master_zone=" << zg.master_zone << dendl;
-      return -EINVAL;
+      // fix missing master zone for a single zone zonegroup
+      if (zg.master_zone.empty() && zg.zones.size() == 1) {
+       master = zg.zones.begin();
+       ldout(cct, 0) << "zonegroup " << zg.get_name() << " missing master_zone, setting zone " <<
+         master->second.name << " id:" << master->second.id << " as master" << dendl;
+       if (zonegroup.get_id() == zg.get_id()) {
+         zonegroup.master_zone = master->second.id;
+         zonegroup.update();
+       } else {
+         RGWZoneGroup fixed_zg(zg.get_id(),zg.get_name());
+         ret = fixed_zg.init(cct, this);
+         if (ret < 0) {
+           ldout(cct, 0) << "error initializing zonegroup : " << cpp_strerror(-ret) << dendl;
+           return ret;
+         }
+         fixed_zg.master_zone = master->second.id;
+         fixed_zg.update();
+       }
+      } else {
+       ldout(cct, 0) << "zonegroup " << zg.get_name() << " missing zone for master_zone=" <<
+         zg.master_zone << dendl;
+       return -EINVAL;
+      }
     }
     const auto& endpoints = master->second.endpoints;
     add_new_connection_to_map(zonegroup_conn_map, zg, new RGWRESTConn(cct, this, zg.get_id(), endpoints));
@@ -3640,9 +3660,18 @@ int RGWRados::init_zg_from_local(bool *creating_defaults)
     // use endpoints from the zonegroup's master zone
     auto master = zonegroup.zones.find(zonegroup.master_zone);
     if (master == zonegroup.zones.end()) {
-      ldout(cct, 0) << "zonegroup " << zonegroup.get_name() << " missing zone for "
+      // fix missing master zone for a single zone zonegroup
+      if (zonegroup.master_zone.empty() && zonegroup.zones.size() == 1) {
+       master = zonegroup.zones.begin();
+       ldout(cct, 0) << "zonegroup " << zonegroup.get_name() << " missing master_zone, setting zone " <<
+         master->second.name << " id:" << master->second.id << " as master" << dendl;
+       zonegroup.master_zone = master->second.id;
+       zonegroup.update();
+      } else {
+       ldout(cct, 0) << "zonegroup " << zonegroup.get_name() << " missing zone for "
           "master_zone=" << zonegroup.master_zone << dendl;
-      return -EINVAL;
+       return -EINVAL;
+      }
     }
     const auto& endpoints = master->second.endpoints;
     rest_master_conn = new RGWRESTConn(cct, this, zonegroup.get_id(), endpoints);