]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: store cluster params in a special object
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 29 Aug 2012 22:34:17 +0000 (15:34 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Sat, 15 Sep 2012 20:30:05 +0000 (13:30 -0700)
We now have a cluster root pool that should hold the
cluster params. The cluster params are now read from
this object on startup, if object does not exist we
set its defaults and write it.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/common/config_opts.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 292507e0a3f3731b7916f7b20ad744cd919f1c21..37a477289a4cf63d5e8a621e8a13ffe1fb9e9da6 100644 (file)
@@ -411,6 +411,7 @@ OPTION(rgw_num_control_oids, OPT_INT, 8)
 OPTION(rgw_maintenance_tick_interval, OPT_DOUBLE, 10.0)
 OPTION(rgw_pools_preallocate_max, OPT_INT, 100)
 OPTION(rgw_pools_preallocate_threshold, OPT_INT, 70)
+OPTION(rgw_cluster_root_pool, OPT_STR, ".rgw.root")
 OPTION(rgw_log_nonexistent_bucket, OPT_BOOL, false)
 OPTION(rgw_log_object_name, OPT_STR, "%Y-%m-%d-%H-%i-%n")      // man date to see codes (a subset are supported)
 OPTION(rgw_log_object_name_utc, OPT_BOOL, false)
index acbd1ce285d788fb604b24fdf90a5c5939d118c3..767d8fd78733367c78f3d35ad5e4b2c8172e5601 100644 (file)
@@ -43,12 +43,16 @@ static string dir_oid_prefix = ".dir.";
 static string default_storage_pool = ".rgw.buckets";
 static string avail_pools = ".pools.avail";
 
+static string cluster_info_oid = "cluster_info";
+
 
 static RGWObjCategory shadow_category = RGW_OBJ_CATEGORY_SHADOW;
 static RGWObjCategory main_category = RGW_OBJ_CATEGORY_MAIN;
 
 #define RGW_USAGE_OBJ_PREFIX "usage."
 
+#define RGW_DEFAULT_CLUSTER_ROOT_POOL ".rgw.root"
+
 
 #define dout_subsys ceph_subsys_rgw
 
@@ -66,6 +70,35 @@ void RGWRadosParams::init_default()
   user_uid_pool = ".users.uid";
 }
 
+int RGWRadosParams::init(CephContext *cct, RGWRados *store)
+{
+  string pool_name = cct->_conf->rgw_cluster_root_pool;
+  if (pool_name.empty())
+    pool_name = RGW_DEFAULT_CLUSTER_ROOT_POOL;
+
+  rgw_bucket pool(pool_name.c_str());
+  bufferlist bl;
+
+  int ret = rgw_get_obj(store, NULL, pool, cluster_info_oid, bl);
+  if (ret == -ENOENT) {
+    init_default();
+    ::encode(*this, bl);
+    ret = rgw_put_system_obj(store, pool, cluster_info_oid, bl.c_str(), bl.length(), true, NULL);
+    return ret;
+  }
+  if (ret < 0)
+    return ret;
+
+  try {
+    bufferlist::iterator iter = bl.begin();
+    ::decode(*this, iter);
+  } catch (buffer::error& err) {
+    ldout(cct, 0) << "ERROR: failed to decode cluster info from " << pool << ":" << cluster_info_oid << dendl;
+    return -EIO;
+  }
+
+  return 0;
+}
 
 class RGWWatcher : public librados::WatchCtx {
   RGWRados *rados;
@@ -130,7 +163,7 @@ int RGWRados::initialize()
   if (ret < 0)
    return ret;
 
-  params.init_default();
+  params.init(cct, this);
 
   ret = open_root_pool_ctx();
   if (ret < 0)
index 1ca5ad97fec59df24e43306316bbc57d3d8043ca..c25a446b8b02c29104c24ef958fb97f23c592ac3 100644 (file)
@@ -195,8 +195,40 @@ struct RGWRadosParams {
   rgw_bucket user_swift_pool;
   rgw_bucket user_uid_pool;
 
+  int init(CephContext *cct, RGWRados *store);
   void init_default();
+
+  void encode(bufferlist& bl) const {
+    ENCODE_START(1, 1, bl);
+    ::encode(domain_root, bl);
+    ::encode(control_pool, bl);
+    ::encode(gc_pool, bl);
+    ::encode(log_pool, bl);
+    ::encode(intent_log_pool, bl);
+    ::encode(usage_log_pool, bl);
+    ::encode(user_keys_pool, bl);
+    ::encode(user_email_pool, bl);
+    ::encode(user_swift_pool, bl);
+    ::encode(user_uid_pool, bl);
+    ENCODE_FINISH(bl);
+  }
+
+  void decode(bufferlist::iterator& bl) {
+     DECODE_START(1, bl);
+    ::decode(domain_root, bl);
+    ::decode(control_pool, bl);
+    ::decode(gc_pool, bl);
+    ::decode(log_pool, bl);
+    ::decode(intent_log_pool, bl);
+    ::decode(usage_log_pool, bl);
+    ::decode(user_keys_pool, bl);
+    ::decode(user_email_pool, bl);
+    ::decode(user_swift_pool, bl);
+    ::decode(user_uid_pool, bl);
+    DECODE_FINISH(bl);
+  }
 };
+WRITE_CLASS_ENCODER(RGWRadosParams);
   
 class RGWRados
 {