From 36f650b45b237793055f687a3a0addd744afae32 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Mon, 3 Oct 2011 15:14:02 -0700 Subject: [PATCH] rgw: move rgw_bucket_select_host_pool behind RGWAccess as select_bucket_placement This doesn't really belong in front of the interface. Maybe later we can hide it completely, but for now we can put it behind the RGWAccess interface in a way that at least pretends to be backing-store-agnostic. Signed-off-by: Greg Farnum --- src/rgw/rgw_access.h | 1 + src/rgw/rgw_bucket.cc | 51 +------------------------------------------ src/rgw/rgw_bucket.h | 2 -- src/rgw/rgw_op.cc | 2 +- src/rgw/rgw_rados.cc | 50 ++++++++++++++++++++++++++++++++++++++++++ src/rgw/rgw_rados.h | 3 +++ 6 files changed, 56 insertions(+), 53 deletions(-) diff --git a/src/rgw/rgw_access.h b/src/rgw/rgw_access.h index 024c6a4eede8e..068df13663906 100644 --- a/src/rgw/rgw_access.h +++ b/src/rgw/rgw_access.h @@ -61,6 +61,7 @@ public: /** Create a new bucket*/ virtual int create_bucket(std::string& id, rgw_bucket& bucket, map& attrs, bool create_pool, bool assign_marker, bool exclusive = true, uint64_t auid = 0) = 0; + virtual int select_bucket_placement(string& bucket_name, rgw_bucket& bucket) { return 0; } virtual int create_pools(std::string& id, vector& names, vector& retcodes, int auid = 0) { return -ENOTSUP; } /** write an object to the storage device in the appropriate pool with the given stats */ diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index 48ad185fa883f..edbca20b957f3 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -8,13 +8,8 @@ #include "rgw_bucket.h" #include "rgw_tools.h" -#include "auth/Crypto.h" // get_random_bytes() - - static rgw_bucket pi_buckets(BUCKETS_POOL_NAME); -static string default_storage_pool(DEFAULT_BUCKET_STORE_POOL); -static string avail_pools = ".pools.avail"; static string pool_name_prefix = "p"; @@ -74,50 +69,6 @@ int rgw_get_bucket_info_id(uint64_t bucket_id, RGWBucketInfo& info) return rgw_get_bucket_info(bucket_string, info); } -int rgw_bucket_select_host_pool(string& bucket_name, rgw_bucket& bucket) -{ - bufferlist header; - map m; - string pool_name; - - rgw_obj obj(pi_buckets, avail_pools); - int ret = rgwstore->tmap_get(obj, header, m); - if (ret < 0 || !m.size()) { - string id; - vector names; - names.push_back(default_storage_pool); - vector retcodes; - bufferlist bl; - ret = rgwstore->create_pools(id, names, retcodes); - if (ret < 0) - return ret; - ret = rgwstore->tmap_set(obj, default_storage_pool, bl); - if (ret < 0) - return ret; - m[default_storage_pool] = bl; - } - - vector v; - map::iterator miter; - for (miter = m.begin(); miter != m.end(); ++miter) { - v.push_back(miter->first); - } - - uint32_t r; - ret = get_random_bytes((char *)&r, sizeof(r)); - if (ret < 0) - return ret; - - int i = r % v.size(); - pool_name = v[i]; - bucket.pool = pool_name; - bucket.name = bucket_name; - - return 0; -} - - - int rgw_create_bucket(std::string& id, string& bucket_name, rgw_bucket& bucket, map& attrs, bool exclusive, uint64_t auid) { @@ -128,7 +79,7 @@ int rgw_create_bucket(std::string& id, string& bucket_name, rgw_bucket& bucket, return rgwstore->create_bucket(id, bucket, attrs, true, false, exclusive, auid); } - int ret = rgw_bucket_select_host_pool(bucket_name, bucket); + int ret = rgwstore->select_bucket_placement(bucket_name, bucket); if (ret < 0) return ret; diff --git a/src/rgw/rgw_bucket.h b/src/rgw/rgw_bucket.h index ffa9a8e883bf8..60870d76cdf0c 100644 --- a/src/rgw/rgw_bucket.h +++ b/src/rgw/rgw_bucket.h @@ -7,12 +7,10 @@ #include "rgw_common.h" #define BUCKETS_POOL_NAME ".rgw" -#define DEFAULT_BUCKET_STORE_POOL ".rgw.buckets" extern int rgw_get_bucket_info_id(uint64_t bucket_id, RGWBucketInfo& info); extern int rgw_get_bucket_info(string& bucket_name, RGWBucketInfo& info); extern int rgw_store_bucket_info(RGWBucketInfo& info); -extern int rgw_bucket_select_host_pool(string& bucket_name, rgw_bucket& bucket); extern int rgw_create_bucket(std::string& id, string& bucket_name, rgw_bucket& bucket, map& attrs, bool exclusive = true, uint64_t auid = 0); diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index fd89cd68cedb3..ea50048eee962 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -466,7 +466,7 @@ void RGWCreateBucket::execute() attrs[RGW_ATTR_ACL] = aclbl; - ret = rgw_bucket_select_host_pool(s->bucket_name_str, s->bucket); + ret = rgwstore->select_bucket_placement(s->bucket_name_str, s->bucket); if (ret < 0) goto done; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 78c492d320c3e..ba80e6e92e613 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -18,6 +18,7 @@ using namespace librados; #include #include #include +#include "auth/Crypto.h" // get_random_bytes() using namespace std; @@ -27,6 +28,12 @@ static string notify_oid = "notify"; static string shadow_ns = "shadow"; static string bucket_marker_ver_oid = ".rgw.bucket-marker-ver"; static string dir_oid_prefix = ".dir."; +static string default_storage_pool(DEFAULT_BUCKET_STORE_POOL); +static string avail_pools = ".pools.avail"; + +#include "rgw/rgw_bucket.h" +static rgw_bucket pi_buckets_rados(BUCKETS_POOL_NAME); + static RGWObjCategory shadow_category = RGW_OBJ_CATEGORY_SHADOW; static RGWObjCategory main_category = RGW_OBJ_CATEGORY_MAIN; @@ -376,6 +383,49 @@ int RGWRados::create_bucket(std::string& id, rgw_bucket& bucket, return ret; } +int RGWRados::select_bucket_placement(string& bucket_name, rgw_bucket& bucket) +{ + bufferlist header; + map m; + string pool_name; + + rgw_obj obj(pi_buckets_rados, avail_pools); + int ret = tmap_get(obj, header, m); + if (ret < 0 || !m.size()) { + string id; + vector names; + names.push_back(default_storage_pool); + vector retcodes; + bufferlist bl; + ret = create_pools(id, names, retcodes); + if (ret < 0) + return ret; + ret = tmap_set(obj, default_storage_pool, bl); + if (ret < 0) + return ret; + m[default_storage_pool] = bl; + } + + vector v; + map::iterator miter; + for (miter = m.begin(); miter != m.end(); ++miter) { + v.push_back(miter->first); + } + + uint32_t r; + ret = get_random_bytes((char *)&r, sizeof(r)); + if (ret < 0) + return ret; + + int i = r % v.size(); + pool_name = v[i]; + bucket.pool = pool_name; + bucket.name = bucket_name; + + return 0; + +} + int RGWRados::create_pools(std::string& id, vector& names, vector& retcodes, int auid) { vector::iterator iter; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index d661ff1e9f22e..aaf399ba9eff3 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -11,6 +11,8 @@ class RGWWatcher; class SafeTimer; class ACLOwner; +#define DEFAULT_BUCKET_STORE_POOL ".rgw.buckets" + struct RGWObjState { bool is_atomic; bool has_attrs; @@ -151,6 +153,7 @@ public: * returns 0 on success, -ERR# otherwise. */ virtual int create_bucket(std::string& id, rgw_bucket& bucket, map& attrs, bool create_pool, bool assign_marker, bool exclusive = true, uint64_t auid = 0); + virtual int select_bucket_placement(std::string& bucket_name, rgw_bucket& bucket); virtual int create_pools(std::string& id, vector& names, vector& retcodes, int auid = 0); /** Write/overwrite an object to the bucket storage. */ -- 2.39.5