]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: realm pull also pulls period
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 4 Dec 2015 03:44:24 +0000 (19:44 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:13:41 +0000 (16:13 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_rados.cc

index 63ebd03d55ee82910ee3e690f3d3c2a53e883cfc..9dc26084378a9eaec645f8b7a78c62e6e4da5c2c 100644 (file)
@@ -1489,6 +1489,52 @@ static int init_bucket_for_sync(const string& bucket_name, string& bucket_id)
   return 0;
 }
 
+static int do_period_pull(const string& remote, const string& url, const string& access_key, const string& secret_key,
+                          const string& realm_id, const string& realm_name, const string& period_id, const string& period_epoch,
+                          RGWPeriod *period)
+{
+  RGWEnv env;
+  req_info info(g_ceph_context, &env);
+  info.method = "GET";
+  info.request_uri = "/admin/realm/period";
+
+  map<string, string> &params = info.args.get_params();
+  if (!realm_id.empty())
+    params["realm_id"] = realm_id;
+  if (!realm_name.empty())
+    params["realm_name"] = realm_name;
+  if (!period_id.empty())
+    params["period_id"] = period_id;
+  if (!period_epoch.empty())
+    params["epoch"] = period_epoch;
+
+  bufferlist bl;
+  JSONParser p;
+  int ret = send_to_remote_or_url(remote, url, access_key, secret_key,
+                                  info, bl, p);
+  if (ret < 0) {
+    cerr << "request failed: " << cpp_strerror(-ret) << std::endl;
+    return ret;
+  }
+  ret = period->init(g_ceph_context, store, false);
+  if (ret < 0) {
+    cerr << "faile to init period " << cpp_strerror(-ret) << std::endl;
+    return ret;
+  }
+  try {
+    decode_json_obj(*period, &p);
+  } catch (JSONDecoder::err& e) {
+    cout << "failed to decode JSON input: " << e.message << std::endl;
+    return -EINVAL;
+  }
+  ret = period->store_info(false);
+  if (ret < 0) {
+    cerr << "Error storing period " << period->get_id() << ": " << cpp_strerror(ret) << std::endl;
+  }
+
+  return 0;
+}
+
 int main(int argc, char **argv) 
 {
   vector<const char*> args;
@@ -3146,6 +3192,16 @@ int main(int argc, char **argv)
         cout << "failed to decode JSON response: " << e.message << std::endl;
         return -EINVAL;
       }
+      RGWPeriod period;
+      if (!realm.get_current_period().empty()) {
+        ret = do_period_pull(remote, url, access_key, secret_key,
+                             realm_id, realm_name, period_id, period_epoch,
+                             &period);
+        if (ret < 0) {
+          cerr << "could not fetch period " << realm.get_current_period() << std::endl;
+          return -ret;
+        }
+      }
       ret = realm.create(false);
       if (ret < 0) {
         cerr << "Error storing realm " << realm.get_id() << ": "
@@ -3199,40 +3255,12 @@ int main(int argc, char **argv)
     return 0;
   case OPT_PERIOD_PULL:
     {
-      RGWEnv env;
-      req_info info(g_ceph_context, &env);
-      info.method = "GET";
-      info.request_uri = "/admin/realm/period";
-
-      map<string, string> &params = info.args.get_params();
-      if (!period_id.empty())
-        params["period_id"] = period_id;
-      if (!period_epoch.empty())
-        params["epoch"] = period_epoch;
-
-      bufferlist bl;
-      JSONParser p;
-      int ret = send_to_remote_or_url(remote, url, access_key, secret_key,
-                                      info, bl, p);
-      if (ret < 0) {
-        cerr << "request failed: " << cpp_strerror(-ret) << std::endl;
-        return ret;
-      }
       RGWPeriod period;
-      ret = period.init(g_ceph_context, store, false);
-      if (ret < 0) {
-       cerr << "faile to init period " << cpp_strerror(-ret) << std::endl;
-       return ret;
-      }
-      try {
-        decode_json_obj(period, &p);
-      } catch (JSONDecoder::err& e) {
-        cout << "failed to decode JSON input: " << e.message << std::endl;
-        return -EINVAL;
-      }
-      ret = period.store_info(false);
+      int ret = do_period_pull(remote, url, access_key, secret_key,
+                               realm_id, realm_name, period_id, period_epoch,
+                               &period);
       if (ret < 0) {
-        cerr << "Error storing period " << period.get_id() << ": " << cpp_strerror(ret) << std::endl;
+        cerr << "period pull failed: " << cpp_strerror(-ret) << std::endl;
       }
 
       encode_json("period", period, formatter);
index 5cd3e8c21e1aee6e82f2336c9b635c297fbebf4c..a8e364d2c0966dd08bc585d096d2a4d9be2470ea 100644 (file)
@@ -672,16 +672,25 @@ int RGWRealm::create(bool exclusive)
   if (ret < 0) {
     return ret;
   }
-  /* create new period for the realm */
   RGWPeriod period;
-  ret = period.init(cct, store, id, name, false);
-  if (ret < 0 ) {
-    return ret;
-  }
-  ret = period.create(true);
-  if (ret < 0) {
-    ldout(cct, 0) << "ERROR creating new period for realm " << name << ": " << cpp_strerror(-ret) << dendl;
-    return ret;
+  if (current_period.empty()) {
+    /* create new period for the realm */
+    ret = period.init(cct, store, id, name, false);
+    if (ret < 0 ) {
+      return ret;
+    }
+    ret = period.create(true);
+    if (ret < 0) {
+      ldout(cct, 0) << "ERROR: creating new period for realm " << name << ": " << cpp_strerror(-ret) << dendl;
+      return ret;
+    }
+  } else {
+    period = RGWPeriod(current_period, 0);
+    int ret = period.init(cct, store, id, name);
+    if (ret < 0) {
+      lderr(cct) << "ERROR: failed to init period " << current_period << dendl;
+      return ret;
+    }
   }
   ret = set_current_period(period.get_id());
   if (ret < 0) {
@@ -1037,6 +1046,12 @@ int RGWPeriod::create(bool exclusive)
 
 int RGWPeriod::store_info(bool exclusive)
 {
+  epoch_t latest_epoch = FIRST_EPOCH;
+  int ret = get_latest_epoch(latest_epoch);
+  if (ret < 0 && ret != -ENOENT) {
+    ldout(cct, 0) << "ERROR: RGWPeriod::get_latest_epoch() returned " << cpp_strerror(-ret) << dendl;
+    return ret;
+  }
   string pool_name = get_pool_name(cct);
 
   rgw_bucket pool(pool_name.c_str());
@@ -1044,7 +1059,19 @@ int RGWPeriod::store_info(bool exclusive)
   string oid = get_period_oid();
   bufferlist bl;
   ::encode(*this, bl);
-  return rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), exclusive, NULL, 0, NULL);
+  ret = rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), exclusive, NULL, 0, NULL);
+  if (ret < 0) {
+    ldout(cct, 0) << "ERROR: rgw_put_system_obj(" << pool << ":" << oid << "): " << cpp_strerror(-ret) << dendl;
+    return ret;
+  }
+  if (latest_epoch < epoch) {
+    ret = set_latest_epoch(epoch);
+    if (ret < 0) {
+      ldout(cct, 0) << "ERROR: RGWPeriod::set_latest_epoch() returned " << cpp_strerror(-ret) << dendl;
+      return ret;
+    }
+  }
+  return 0;
 }
 
 const string& RGWPeriod::get_pool_name(CephContext *cct)