]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw_admin: period update command
authorYehuda Sadeh <yehuda@redhat.com>
Thu, 15 Oct 2015 22:16:16 +0000 (15:16 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:13:14 +0000 (16:13 -0800)
A command that creates staging period data out of current local data

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 1ee62711b064d46a347512f29fd79afa26087511..e34035a5fe81d4a292ec60b2b2d23ae0649cd048 100644 (file)
@@ -356,6 +356,7 @@ enum {
   OPT_PERIOD_PULL,
   OPT_PERIOD_PUSH,
   OPT_PERIOD_LIST,
+  OPT_PERIOD_UPDATE,
 };
 
 static int get_cmd(const char *cmd, const char *prev_cmd, const char *prev_prev_cmd, bool *need_more)
@@ -532,6 +533,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, const char *prev_prev_
       return OPT_PERIOD_PUSH;
     if (strcmp(cmd, "list") == 0)
       return OPT_PERIOD_LIST;
+    if (strcmp(cmd, "update") == 0)
+      return OPT_PERIOD_UPDATE;
   } else if (strcmp(prev_cmd, "realm") == 0) {
     if (strcmp(cmd, "create") == 0)
       return OPT_REALM_CREATE;
@@ -1797,6 +1800,7 @@ int main(int argc, char **argv)
                         opt_cmd == OPT_PERIOD_PREPARE || opt_cmd == OPT_PERIOD_ACTIVATE ||
                         opt_cmd == OPT_PERIOD_DELETE || opt_cmd == OPT_PERIOD_GET ||
                         opt_cmd == OPT_PERIOD_GET_CURRENT || opt_cmd == OPT_PERIOD_LIST ||
+                        opt_cmd == OPT_PERIOD_UPDATE ||
                         opt_cmd == OPT_REALM_DELETE || opt_cmd == OPT_REALM_GET || opt_cmd == OPT_REALM_LIST ||
                         opt_cmd == OPT_REALM_LIST_PERIODS ||
                         opt_cmd == OPT_REALM_GET_DEFAULT || opt_cmd == OPT_REALM_REMOVE ||
@@ -1971,6 +1975,25 @@ int main(int argc, char **argv)
        cout << std::endl;
       }
       break;
+    case OPT_PERIOD_UPDATE:
+      {
+       RGWRealm realm(realm_id, realm_name);
+       int ret = realm.init(g_ceph_context, store);
+       if (ret < 0 ) {
+         cerr << "Error initializing realm " << cpp_strerror(-ret) << std::endl;
+         return ret;
+       }
+        RGWPeriod period(realm.get_current_period(), 0);
+       ret = period.init(g_ceph_context, store, realm.get_id(), realm.get_name());
+       if (ret < 0) {
+         cerr << "period init failed: " << cpp_strerror(-ret) << std::endl;
+         return -ret;
+       }
+        period.fork();
+        period.update();
+        period.store_info(false);
+      }
+      break;
     case OPT_REALM_CREATE:
       {
        if (realm_name.empty()) {
index 3631ab1cd80f1ab96f096e452f1f1f10da3063d0..f7e5e0e56ba9b342b19118453c392f2acc734fdf 100644 (file)
@@ -956,6 +956,9 @@ int RGWPeriod::use_next_epoch()
 
 int RGWPeriod::add_zonegroup(const RGWZoneGroup& zonegroup)
 {
+  if (zonegroup.realm_id != realm_id) {
+    return 0;
+  }
   int ret = period_map.update(zonegroup);
   if (ret < 0) {
     ldout(cct, 0) << "ERROR: updating period map: " << cpp_strerror(-ret) << dendl;
@@ -965,6 +968,46 @@ int RGWPeriod::add_zonegroup(const RGWZoneGroup& zonegroup)
   return store_info(false);
 }
 
+int RGWPeriod::update()
+{
+  list<string> zonegroups;
+  int ret = store->list_zonegroups(zonegroups);
+  if (ret < 0) {
+    ldout(cct, 0) << "ERROR: failed to list zonegroups: " << cpp_strerror(-ret) << dendl;
+    return ret;
+  }
+
+  for (auto iter : zonegroups) {
+    RGWZoneGroup zg(string(), iter);
+cerr << __FILE__ << ":" << __LINE__ << " iter=" << iter << std::endl;
+    ret = zg.init(cct, store);
+    if (ret < 0) {
+      ldout(cct, 0) << "WARNING: zg.init() failed: " << cpp_strerror(-ret) << dendl;
+      continue;
+    }
+
+    if (zg.realm_id != realm_id) {
+      ldout(cct, 20) << "skippinh zonegroup " << zg.get_name() << ", not on our realm" << dendl;
+      continue;
+    }
+    
+    int ret = period_map.update(zg);
+    if (ret < 0) {
+      ldout(cct, 0) << "ERROR: updating period map: " << cpp_strerror(-ret) << dendl;
+      return ret;
+    }
+  }
+
+  return 0;
+}
+
+void RGWPeriod::fork()
+{
+  epoch = 1;
+  id = realm_id + ":staging";
+  period_map.reset();
+}
+
 int RGWZoneParams::create_default(bool old_format)
 {
   name = default_zone_name;
index a940e420341b4a6861d8f36745c7d659bae71ce3..cea6cece0315051c66a0ec64f6f004ce6d9943ec 100644 (file)
@@ -1156,6 +1156,11 @@ struct RGWPeriodMap
 
   void dump(Formatter *f) const;
   void decode_json(JSONObj *obj);
+
+  void reset() {
+    zonegroups.clear();
+    zonegroups_by_api.clear();
+  }
 };
 WRITE_CLASS_ENCODER(RGWPeriodMap)
 
@@ -1393,6 +1398,9 @@ public:
   int store_info(bool exclusive);
   int add_zonegroup(const RGWZoneGroup& zonegroup);
 
+  void fork();
+  int update();
+
   void encode(bufferlist& bl) const {
     ENCODE_START(1, 1, bl);    
     ::encode(id, bl);