]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: realm id and epoch should be part of period oid
authorOrit Wasserman <owasserm@redhat.com>
Wed, 9 Sep 2015 12:53:40 +0000 (14:53 +0200)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:12:42 +0000 (16:12 -0800)
fixes period get and activate command
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 0a7a3b0742f8c75dbdd467ab1f8271b72c864339..9063787e49cdf7650460b21e1fbe7012e8f43a4b 100644 (file)
@@ -1700,10 +1700,21 @@ int main(int argc, char **argv)
     switch (opt_cmd) {
     case OPT_PERIOD_PREPARE:
       {
+       RGWRealm realm(realm_id, realm_name);
+       int ret = realm.init(g_ceph_context, store);
+       if (ret < 0) {
+         cerr << "could not init realm " << ": " << cpp_strerror(-ret) << std::endl;
+         return ret;
+       }
        RGWPeriod period(g_ceph_context, store, master_zonegroup, master_zone);
-       int ret = period.create();
+       ret = period.init(realm.get_id(), realm.get_name(), false);
+       if (ret < 0) {
+         cerr << "failed to init period " << ": " << cpp_strerror(-ret) << std::endl;
+         return ret;
+       }
+       ret = period.create();
        if (ret < 0) {
-         cerr << "ERROR: couldn't prepare new period " << ": " << cpp_strerror(-ret) << std::endl;
+         cerr << "ERROR: couldn't create period " << ": " << cpp_strerror(-ret) << std::endl;
          return ret;
        }
        encode_json("period", period, formatter);
@@ -1742,6 +1753,7 @@ int main(int argc, char **argv)
          cerr << "period init failed: " << cpp_strerror(-ret) << std::endl;
          return -ret;
        }
+       encode_json("realm", period.get_realm(), formatter);
        encode_json("period", period, formatter);
        formatter->flush(cout);
        cout << std::endl;
@@ -1778,6 +1790,7 @@ int main(int argc, char **argv)
          cerr << "Error initing realm " << cpp_strerror(-ret) << std::endl;
          return ret;
        }
+       cerr << "realm id " << realm.get_id() << " name " << realm.get_name() << std::endl;
        ret = realm.set_current_period(period_id);
        if (ret < 0 ) {
          cerr << "Error setting current period " << period_id << ":" << cpp_strerror(-ret) << std::endl;
index 46e8794f6b9691a2824ccaf0880c50c4cb67f188..e5ef88757f9066c43a4f326bebdfac97e65edb4b 100644 (file)
@@ -90,7 +90,7 @@ const string default_zone_name = "default";
 static string zonegroup_names_oid_prefix = "zonegroups_names.";
 static RGWObjCategory main_category = RGW_OBJ_CATEGORY_MAIN;
 #define RGW_USAGE_OBJ_PREFIX "usage."
-
+#define FIRST_EPOCH 1
 static string RGW_DEFAULT_ZONE_ROOT_POOL = "rgw.root";
 static string RGW_DEFAULT_ZONEGROUP_ROOT_POOL = "rgw.root";
 static string RGW_DEFAULT_REALM_ROOT_POOL = "rgw.root";
@@ -573,18 +573,19 @@ const string& RGWRealm::get_info_oid_prefix(bool old_format)
 
 int RGWRealm::set_current_period(const string& period_id) {
   /* check to see period id is valid */
-  RGWPeriod new_current(cct, store);  
-  int ret = new_current.init(period_id);
+  RGWPeriod new_current(cct, store, period_id);  
+  int ret = new_current.init();
   if (ret < 0) {
+    derr << "Error init new period id " << period_id << " : " << cpp_strerror(-ret) << dendl;
     return ret;
   }
-  if (new_current.get_predecessor() != current_period) {
+  if (!current_period.empty() && new_current.get_predecessor() != current_period) {
     ldout(cct, 0) << "set_current_period new period " << period_id <<
       " is not a perdecessor of the current period "<< current_period << dendl;
     return -EINVAL;
   }
   current_period = period_id;
-  return store_info(true);
+  return update();
 }
 
 int RGWPeriod::init(const string& period_id, epoch_t period_epoch,  bool setup_obj)
@@ -614,10 +615,12 @@ int RGWPeriod::init(const string& period_realm_id, const string& period_realm_na
   RGWRealm realm(realm_id, period_realm_name);
   int ret = realm.init(cct, store);
   if (ret < 0) {
+    derr << "failed to init realm " << period_realm_name  << " id " << realm_id << " : " << cpp_strerror(-ret) <<
+      dendl;
     return ret;
   }
 
-  /* update realm_id incare we used a period_name */
+  /* update realm_id in case we used a realm name */
   if (realm_id.empty()) {
     realm_id = realm.get_id();
   }
@@ -629,11 +632,13 @@ int RGWPeriod::init(const string& period_realm_id, const string& period_realm_na
   if (!epoch) {
     ret = use_latest_epoch();
     if (ret < 0) {
+      derr << "failed to use_latest_epoch " << period_realm_name  << " id " << realm_id << " : "
+          << cpp_strerror(-ret) << dendl;
       return ret;
     }
   }
 
-  return read_info(id);
+  return read_info();
 }
 
 const string& RGWPeriod::get_latest_epoch_oid()
@@ -649,19 +654,32 @@ const string& RGWPeriod::get_info_oid_prefix()
   return period_info_oid_prefix;
 }
 
+const string RGWPeriod::get_period_oid_prefix()
+{
+  return get_info_oid_prefix() + realm_id + "." + id;
+}
+
+const string RGWPeriod::get_period_oid()
+{
+  std::ostringstream oss;
+  oss << get_period_oid_prefix() << "." << epoch;
+
+  return oss.str();;
+}
+
 int RGWPeriod::read_latest_epoch(RGWPeriodLatestEpochInfo& info)
 {
   string pool_name = get_pool_name(cct);
-  string oid = get_info_oid_prefix() + id +
-    get_latest_epoch_oid();
+  string oid = get_period_oid_prefix() + get_latest_epoch_oid();
 
   rgw_bucket pool(pool_name.c_str());
   bufferlist bl;
   RGWObjectCtx obj_ctx(store);
   int ret = rgw_get_system_obj(store, obj_ctx, pool, oid, bl, NULL, NULL);
-  if (ret < 0)
+  if (ret < 0) {
+    derr << "error read_lastest_epoch " << pool << ":" << oid << dendl;
     return ret;
-
+  }
   try {
     bufferlist::iterator iter = bl.begin();
     ::decode(info, iter);
@@ -691,22 +709,42 @@ int RGWPeriod::use_latest_epoch()
 {
   RGWPeriodLatestEpochInfo info;
   int ret = read_latest_epoch(info);
-  if (ret < 0)
+  if (ret < 0) {
     return ret;
+  }
 
   epoch = info.epoch;
 
   return 0;
 }
 
+int RGWPeriod::set_latest_epoch(const epoch_t& epoch)
+{
+  string pool_name = get_pool_name(cct);
+  string oid = get_period_oid_prefix() + get_latest_epoch_oid();
+
+  rgw_bucket pool(pool_name.c_str());
+  bufferlist bl;
+
+  RGWPeriodLatestEpochInfo info;
+  info.epoch = epoch;
+
+  ::encode(info, bl);
+
+  int ret = rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), false, NULL, 0, NULL);
+  if (ret < 0)
+    return ret;
+
+  return 0;
 
+
+}
 int RGWPeriod::delete_obj()
 {
   string pool_name = get_pool_name(cct);
   rgw_bucket pool(pool_name.c_str());
-  string oid  = get_info_oid_prefix() + id;
 
-  rgw_obj object_id(pool, oid);
+  rgw_obj object_id(pool, get_period_oid());
   int ret = store->delete_system_obj(object_id);
   if (ret < 0) {
     lderr(cct) << "Error delete object id " << id << ": " << cpp_strerror(-ret) << dendl;
@@ -715,19 +753,18 @@ int RGWPeriod::delete_obj()
   return ret;
 }
 
-int RGWPeriod::read_info(const string& obj_id)
+int RGWPeriod::read_info()
 {
   string pool_name = get_pool_name(cct);
 
   rgw_bucket pool(pool_name.c_str());
   bufferlist bl;
 
-  string oid = get_info_oid_prefix()  + obj_id;
 
   RGWObjectCtx obj_ctx(store);
-  int ret = rgw_get_system_obj(store, obj_ctx, pool, oid, bl, NULL, NULL);
+  int ret = rgw_get_system_obj(store, obj_ctx, pool, get_period_oid(), bl, NULL, NULL);
   if (ret < 0) {
-    lderr(cct) << "failed reading obj info from " << pool << ":" << oid << ": " << cpp_strerror(-ret) << dendl;
+    lderr(cct) << "failed reading obj info from " << pool << ":" << get_period_oid() << ": " << cpp_strerror(-ret) << dendl;
     return ret;
   }
 
@@ -735,7 +772,7 @@ int RGWPeriod::read_info(const string& obj_id)
     bufferlist::iterator iter = bl.begin();
     ::decode(*this, iter);
   } catch (buffer::error& err) {
-    ldout(cct, 0) << "ERROR: failed to decode obj from " << pool << ":" << oid << dendl;
+    ldout(cct, 0) << "ERROR: failed to decode obj from " << pool << ":" << get_period_oid() << dendl;
     return -EIO;
   }
 
@@ -745,7 +782,7 @@ int RGWPeriod::read_info(const string& obj_id)
 int RGWPeriod::create()
 {
   int ret;
-
+  
   /* create unique id */
   uuid_d new_uuid;
   char uuid_str[37];
@@ -753,11 +790,18 @@ int RGWPeriod::create()
   new_uuid.print(uuid_str);
   id = uuid_str;
 
+  epoch = FIRST_EPOCH;
+  
   ret = store_info(true);
   if (ret < 0) {
     ldout(cct, 0) << "ERROR:  storing info for " << id << ": " << cpp_strerror(-ret) << dendl;
   }
 
+  ret = set_latest_epoch(epoch);
+  if (ret < 0) {
+    ldout(cct, 0) << "ERROR: setting latest epoch " << id << ": " << cpp_strerror(-ret) << dendl;
+  }
+
   return ret;
 }
 
@@ -767,8 +811,10 @@ int RGWPeriod::store_info(bool exclusive)
 
   rgw_bucket pool(pool_name.c_str());
 
-  string oid = get_info_oid_prefix() + id;
-
+  std::ostringstream oss;
+  oss << get_info_oid_prefix() << realm_id << "." << id << "." << epoch;
+  string oid = oss.str();
+  derr << " period store_info " << oid << dendl;
   bufferlist bl;
   ::encode(*this, bl);
   return rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), exclusive, NULL, 0, NULL);
index 3e57f168d3586c5c4fe1d5f2b215ee6aaf36fb84..1de2403f05db7027725f563fd4e528719f794aa9 100644 (file)
@@ -1263,12 +1263,15 @@ class RGWPeriod
   CephContext *cct;
   RGWRados *store;
 
-  int read_info(const string& obj_id);
+  int read_info();
   int read_latest_epoch(RGWPeriodLatestEpochInfo& epoch_info);
   int use_latest_epoch();
   int set_latest_epoch(const epoch_t& epoch);
   int use_current_period();
 
+  const string get_period_oid();
+  const string get_period_oid_prefix();
+
 public:
   RGWPeriod(CephContext *_cct, RGWRados *_store,
            const string& period_id = "", epoch_t _epoch = 0)
@@ -1280,11 +1283,12 @@ public:
     : id(period_id), epoch(_epoch), master_zonegroup(_master_zonegroup), master_zone(_master_zone), cct(_cct),
       store(_store) {}
 
-  string get_id() { return id;}
+  const string& get_id() { return id;}
   epoch_t get_epoch() { return epoch;}
-  string get_predecessor() { return predecessor_uuid;}
-  string get_master_zonegroup() { return master_zonegroup;}
-  string get_master_zone() { return master_zone;}
+  const string& get_predecessor() { return predecessor_uuid;}
+  const string& get_master_zonegroup() { return master_zonegroup;}
+  const string& get_master_zone() { return master_zone;}
+  const string& get_realm() { return realm_id;}
 
   const string& get_pool_name(CephContext *cct);
   const string& get_latest_epoch_oid();
@@ -1293,14 +1297,13 @@ public:
   int get_latest_epoch(epoch_t& epoch);
   int init(const string& realm_id = "", const string &realm_name = "", bool setup_obj = true);
   int init(const string& period_id, epoch_t epoch, bool setup_obj = true);
-
   int create();
   int delete_obj();
   int store_info(bool exclusive);
   int activate() { return -ENOTSUP;}
 
   void encode(bufferlist& bl) const {
-    ENCODE_START(1, 1, bl);
+    ENCODE_START(1, 1, bl);    
     ::encode(id, bl);
     ::encode(epoch, bl);
     ::encode(predecessor_uuid, bl);