]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: move rgw_bucket_select_host_pool behind RGWAccess as select_bucket_placement
authorGreg Farnum <gregory.farnum@dreamhost.com>
Mon, 3 Oct 2011 22:14:02 +0000 (15:14 -0700)
committerGreg Farnum <gregory.farnum@dreamhost.com>
Mon, 3 Oct 2011 22:14:02 +0000 (15:14 -0700)
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 <gregory.farnum@dreamhost.com>
src/rgw/rgw_access.h
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h
src/rgw/rgw_op.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 024c6a4eede8e1408584a477d22798bb206556f2..068df13663906cf64a67f6e5c9702c1885ff2bae 100644 (file)
@@ -61,6 +61,7 @@ public:
 
   /** Create a new bucket*/
   virtual int create_bucket(std::string& id, rgw_bucket& bucket, map<std::string, bufferlist>& 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<string>& names, vector<int>& retcodes, int auid = 0) { return -ENOTSUP; }
   /** write an object to the storage device in the appropriate pool
     with the given stats */
index 48ad185fa883f7176eabcf41e760db6ca0ba6ce2..edbca20b957f351db2c81dea74054a76b12444ae 100644 (file)
@@ -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<string, bufferlist> 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<string> names;
-    names.push_back(default_storage_pool);
-    vector<int> 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<string> v;
-  map<string, bufferlist>::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<std::string, bufferlist>& 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;
 
index ffa9a8e883bf8c7203349e80857907d24b325e73..60870d76cdf0c226d2e8ba1d8e44298d8c2bd985 100644 (file)
@@ -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<std::string, bufferlist>& attrs, bool exclusive = true, uint64_t auid = 0);
 
index fd89cd68cedb3c2c6d4d03e065faa22fda3bda34..ea50048eee962da5e6cab5c9ba63390f23c933e1 100644 (file)
@@ -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;
 
index 78c492d320c3e4a08fdd42c32d0caa4a275f9840..ba80e6e92e61395b9b01b2731116a616682fc89a 100644 (file)
@@ -18,6 +18,7 @@ using namespace librados;
 #include <vector>
 #include <list>
 #include <map>
+#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<string, bufferlist> 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<string> names;
+    names.push_back(default_storage_pool);
+    vector<int> 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<string> v;
+  map<string, bufferlist>::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<string>& names, vector<int>& retcodes, int auid)
 {
   vector<string>::iterator iter;
index d661ff1e9f22e2b2efdf3dc1e29aedf5b4091101..aaf399ba9eff3cb7a8f54f184064ec8181d6d2bc 100644 (file)
@@ -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<std::string,bufferlist>& 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<string>& names, vector<int>& retcodes, int auid = 0);
 
   /** Write/overwrite an object to the bucket storage. */