From ff0f88a6ce9b68d89a60976c2dc551445ed1ef41 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 29 Aug 2012 15:34:17 -0700 Subject: [PATCH] rgw: store cluster params in a special object 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 --- src/common/config_opts.h | 1 + src/rgw/rgw_rados.cc | 35 ++++++++++++++++++++++++++++++++++- src/rgw/rgw_rados.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 292507e0a3f..37a477289a4 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -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) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index acbd1ce285d..767d8fd7873 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -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) diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 1ca5ad97fec..c25a446b8b0 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -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 {