summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-02-21 15:37:57 -0800
committerYehuda Sadeh <yehuda@inktank.com>2013-02-25 15:01:19 -0800
commitea7b0bdc94a7f5dfe5e4492928c8804d38457174 (patch)
tree0a0c07540ae35ce1e4b9042ae2f83d9f5c90d71c
parent12986a23535d07fef20828f755049b528dfa7b75 (diff)
downloadceph-ea7b0bdc94a7f5dfe5e4492928c8804d38457174.tar.gz
rgw: zone list, setup changes
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/rgw/rgw_admin.cc96
-rw-r--r--src/rgw/rgw_rados.cc77
-rw-r--r--src/rgw/rgw_rados.h21
3 files changed, 132 insertions, 62 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc
index ad4c8dce916..7bfff58106b 100644
--- a/src/rgw/rgw_admin.cc
+++ b/src/rgw/rgw_admin.cc
@@ -61,10 +61,12 @@ void _usage()
cerr << " object rm remove object\n";
cerr << " object unlink unlink object from bucket index\n";
cerr << " region info show region info\n";
- cerr << " region list list all regions\n";
+ cerr << " regions list list all regions set on this cluster\n";
cerr << " region set set region info\n";
cerr << " region default set default region\n";
- cerr << " zone info show zone params info\n";
+ cerr << " zone info show zone cluster params\n";
+ cerr << " zone set set zone cluster params\n";
+ cerr << " zone list list all zones set on this cluster\n";
cerr << " pool add add an existing pool for data placement\n";
cerr << " pool rm remove an existing pool from data placement set\n";
cerr << " pools list list placement active set\n";
@@ -174,6 +176,7 @@ enum {
OPT_REGION_DEFAULT,
OPT_ZONE_INFO,
OPT_ZONE_SET,
+ OPT_ZONE_LIST,
OPT_CAPS_ADD,
OPT_CAPS_RM,
};
@@ -208,6 +211,7 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
strcmp(cmd, "usage") == 0 ||
strcmp(cmd, "object") == 0 ||
strcmp(cmd, "region") == 0 ||
+ strcmp(cmd, "regions") == 0 ||
strcmp(cmd, "zone") == 0 ||
strcmp(cmd, "temp") == 0 ||
strcmp(cmd, "caps") == 0 ||
@@ -290,6 +294,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
return OPT_POOL_ADD;
if (strcmp(cmd, "rm") == 0)
return OPT_POOL_RM;
+ if (strcmp(cmd, "list") == 0)
+ return OPT_POOLS_LIST;
} else if (strcmp(prev_cmd, "pools") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_POOLS_LIST;
@@ -307,11 +313,19 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
return OPT_REGION_SET;
if (strcmp(cmd, "default") == 0)
return OPT_REGION_DEFAULT;
+ } else if (strcmp(prev_cmd, "regions") == 0) {
+ if (strcmp(cmd, "list") == 0)
+ return OPT_REGION_LIST;
} else if (strcmp(prev_cmd, "zone") == 0) {
if (strcmp(cmd, "info") == 0)
return OPT_ZONE_INFO;
if (strcmp(cmd, "set") == 0)
return OPT_ZONE_SET;
+ if (strcmp(cmd, "list") == 0)
+ return OPT_ZONE_LIST;
+ } else if (strcmp(prev_cmd, "zones") == 0) {
+ if (strcmp(cmd, "list") == 0)
+ return OPT_ZONE_LIST;
} else if (strcmp(prev_cmd, "gc") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_GC_LIST;
@@ -993,7 +1007,9 @@ int main(int argc, char **argv)
}
bool raw_storage_op = (opt_cmd == OPT_REGION_INFO || opt_cmd == OPT_REGION_LIST ||
- opt_cmd == OPT_REGION_SET || opt_cmd == OPT_REGION_DEFAULT);
+ opt_cmd == OPT_REGION_SET || opt_cmd == OPT_REGION_DEFAULT ||
+ opt_cmd == OPT_ZONE_INFO || opt_cmd == OPT_ZONE_SET ||
+ opt_cmd == OPT_ZONE_LIST);
user_modify_op = (opt_cmd == OPT_USER_MODIFY || opt_cmd == OPT_SUBUSER_MODIFY ||
@@ -1088,6 +1104,57 @@ int main(int argc, char **argv)
}
}
+ if (opt_cmd == OPT_ZONE_INFO) {
+ RGWRegion region;
+ int ret = region.init(g_ceph_context, store);
+ if (ret < 0) {
+ cerr << "WARNING: failed to initialize region" << std::endl;
+ }
+ RGWZoneParams zone;
+ ret = zone.init(g_ceph_context, store, region);
+ if (ret < 0) {
+ cerr << "unable to initialize zone: " << cpp_strerror(-ret) << std::endl;
+ return -ret;
+ }
+ encode_json("zone", zone, formatter);
+ formatter->flush(cout);
+ }
+
+ if (opt_cmd == OPT_ZONE_SET) {
+ RGWRegion region;
+ int ret = region.init(g_ceph_context, store);
+ if (ret < 0) {
+ cerr << "WARNING: failed to initialize region" << std::endl;
+ }
+ RGWZoneParams zone;
+ zone.init_default();
+ ret = read_decode_json(infile, zone);
+ if (ret < 0) {
+ return 1;
+ }
+
+ ret = zone.store_info(g_ceph_context, store, region);
+ if (ret < 0) {
+ cerr << "ERROR: couldn't store zone info: " << cpp_strerror(-ret) << std::endl;
+ return 1;
+ }
+
+ encode_json("zone", zone, formatter);
+ formatter->flush(cout);
+ }
+ if (opt_cmd == OPT_ZONE_LIST) {
+ list<string> zones;
+ int ret = store->list_zones(zones);
+ if (ret < 0) {
+ cerr << "failed to list zones: " << cpp_strerror(-ret) << std::endl;
+ return -ret;
+ }
+ formatter->open_object_section("zones_list");
+ encode_json("zones", zones, formatter);
+ formatter->close_section();
+ formatter->flush(cout);
+ cout << std::endl;
+ }
return 0;
}
@@ -1972,29 +2039,6 @@ next:
}
}
- if (opt_cmd == OPT_ZONE_INFO) {
- encode_json("zone", store->zone, formatter);
- formatter->flush(cout);
- }
-
- if (opt_cmd == OPT_ZONE_SET) {
- RGWZoneParams zone;
- zone.init_default();
- int ret = read_decode_json(infile, zone);
- if (ret < 0) {
- return 1;
- }
-
- ret = zone.store_info(g_ceph_context, store);
- if (ret < 0) {
- cerr << "ERROR: couldn't store zone info: " << cpp_strerror(-ret) << std::endl;
- return 1;
- }
-
- encode_json("zone", store->zone, formatter);
- formatter->flush(cout);
- }
-
if (opt_cmd == OPT_USER_CHECK) {
check_bad_user_bucket_mapping(store, user_id, fix);
}
diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc
index 18bb18ddf3a..cbff6c70f18 100644
--- a/src/rgw/rgw_rados.cc
+++ b/src/rgw/rgw_rados.cc
@@ -48,8 +48,8 @@ static string dir_oid_prefix = ".dir.";
static string default_storage_pool = ".rgw.buckets";
static string avail_pools = ".pools.avail";
-static string zone_info_oid = "zone_info";
-static string region_info_oid_prefix = "region_info";
+static string zone_info_oid_prefix = "zone_info.";
+static string region_info_oid_prefix = "region_info.";
static string default_region_info_oid = "default.region";
@@ -166,7 +166,7 @@ int RGWRegion::init(CephContext *_cct, RGWRados *_store, bool setup_region)
rgw_bucket pool(pool_name.c_str());
bufferlist bl;
- string oid = region_info_oid_prefix + "." + name;
+ string oid = region_info_oid_prefix + name;
int ret = rgw_get_obj(store, NULL, pool, oid, bl);
if (ret < 0) {
@@ -196,7 +196,7 @@ int RGWRegion::create_default()
RGWZoneParams zone_params;
zone_params.name = zone_name;
zone_params.init_default();
- int r = zone_params.store_info(cct, store);
+ int r = zone_params.store_info(cct, store, *this);
if (r < 0) {
derr << "error storing zone params: " << cpp_strerror(-r) << dendl;
return r;
@@ -217,7 +217,7 @@ int RGWRegion::store_info(bool exclusive)
rgw_bucket pool(pool_name.c_str());
- string oid = region_info_oid_prefix + "." + name;
+ string oid = region_info_oid_prefix + name;
bufferlist bl;
::encode(*this, bl);
@@ -242,31 +242,39 @@ void RGWZoneParams::init_default()
user_uid_pool = ".users.uid";
}
-string RGWZoneParams::get_pool_name(CephContext *cct, const string& zone_name)
+string RGWZoneParams::get_pool_name(CephContext *cct)
{
string pool_name = cct->_conf->rgw_zone_root_pool;
if (pool_name.empty()) {
pool_name = RGW_DEFAULT_ZONE_ROOT_POOL;
- if (!zone_name.empty()) {
- pool_name.append("." + zone_name);
- }
}
return pool_name;
}
-int RGWZoneParams::init(CephContext *cct, RGWRados *store, bool create_zone)
+void RGWZoneParams::init_name(CephContext *cct, RGWRegion& region)
{
name = cct->_conf->rgw_zone;
- string pool_name = get_pool_name(cct, name);
+
+ if (name.empty()) {
+ name = region.master_zone;
+
+ if (name.empty()) {
+ name = "default";
+ }
+ }
+}
+
+int RGWZoneParams::init(CephContext *cct, RGWRados *store, RGWRegion& region)
+{
+ init_name(cct, region);
+
+ string pool_name = get_pool_name(cct);
rgw_bucket pool(pool_name.c_str());
bufferlist bl;
- int ret = rgw_get_obj(store, NULL, pool, zone_info_oid, bl);
- if (ret == -ENOENT && create_zone) {
- init_default();
- return 0; // don't try to store obj, we're not fully initialized yet
- }
+ string oid = zone_info_oid_prefix + name;
+ int ret = rgw_get_obj(store, NULL, pool, oid, bl);
if (ret < 0)
return ret;
@@ -274,22 +282,25 @@ int RGWZoneParams::init(CephContext *cct, RGWRados *store, bool create_zone)
bufferlist::iterator iter = bl.begin();
::decode(*this, iter);
} catch (buffer::error& err) {
- ldout(cct, 0) << "ERROR: failed to decode zone info from " << pool << ":" << zone_info_oid << dendl;
+ ldout(cct, 0) << "ERROR: failed to decode zone info from " << pool << ":" << oid << dendl;
return -EIO;
}
return 0;
}
-int RGWZoneParams::store_info(CephContext *cct, RGWRados *store)
+int RGWZoneParams::store_info(CephContext *cct, RGWRados *store, RGWRegion& region)
{
- string pool_name = get_pool_name(cct, name);
+ init_name(cct, region);
+
+ string pool_name = get_pool_name(cct);
rgw_bucket pool(pool_name.c_str());
+ string oid = zone_info_oid_prefix + name;
bufferlist bl;
::encode(*this, bl);
- int ret = rgw_put_system_obj(store, pool, zone_info_oid, bl.c_str(), bl.length(), false, NULL);
+ int ret = rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), false, NULL);
return ret;
}
@@ -386,7 +397,7 @@ int RGWRados::init_complete()
if (ret < 0)
return ret;
- ret = zone.init(cct, this, create_zone);
+ ret = zone.init(cct, this, region);
if (ret < 0)
return ret;
@@ -444,29 +455,43 @@ void RGWRados::finalize_watch()
delete[] watchers;
}
-int RGWRados::list_regions(list<string>& regions)
+int RGWRados::list_raw_prefixed_objs(string pool_name, const string& prefix, list<string>& result)
{
- string pool_name = RGWRegion::get_pool_name(cct);
-
rgw_bucket pool(pool_name.c_str());
bool is_truncated;
RGWListRawObjsCtx ctx;
do {
vector<string> oids;
- int r = list_raw_objects(pool, region_info_oid_prefix, 1000,
+ int r = list_raw_objects(pool, prefix, 1000,
ctx, oids, &is_truncated);
if (r < 0) {
return r;
}
vector<string>::iterator iter;
for (iter = oids.begin(); iter != oids.end(); ++iter) {
- regions.push_back(iter->substr(region_info_oid_prefix.size() + 1));
+ string& val = *iter;
+ if (val.size() > prefix.size())
+ result.push_back(val.substr(prefix.size()));
}
} while (is_truncated);
return 0;
}
+int RGWRados::list_regions(list<string>& regions)
+{
+ string pool_name = RGWRegion::get_pool_name(cct);
+
+ return list_raw_prefixed_objs(pool_name, region_info_oid_prefix, regions);
+}
+
+int RGWRados::list_zones(list<string>& zones)
+{
+ string pool_name = RGWZoneParams::get_pool_name(cct);
+
+ return list_raw_prefixed_objs(pool_name, zone_info_oid_prefix, zones);
+}
+
/**
* Open the pool used as root for this gateway
* Returns: 0 on success, -ERR# otherwise.
diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h
index 8168e6e540b..043b9844607 100644
--- a/src/rgw/rgw_rados.h
+++ b/src/rgw/rgw_rados.h
@@ -245,6 +245,8 @@ struct RGWListRawObjsCtx {
RGWListRawObjsCtx() : initialized(false) {}
};
+struct RGWRegion;
+
struct RGWZoneParams {
rgw_bucket domain_root;
rgw_bucket control_pool;
@@ -260,10 +262,11 @@ struct RGWZoneParams {
string name;
- string get_pool_name(CephContext *cct, const string& zone_name);
- int init(CephContext *cct, RGWRados *store, bool create_zone);
+ static string get_pool_name(CephContext *cct);
+ void init_name(CephContext *cct, RGWRegion& region);
+ int init(CephContext *cct, RGWRados *store, RGWRegion& region);
void init_default();
- int store_info(CephContext *cct, RGWRados *store);
+ int store_info(CephContext *cct, RGWRados *store, RGWRegion& region);
void encode(bufferlist& bl) const {
ENCODE_START(2, 1, bl);
@@ -504,28 +507,24 @@ protected:
string region_name;
string zone_name;
- bool create_zone;
-
public:
RGWRados() : lock("rados_timer_lock"), timer(NULL),
gc(NULL), use_gc_thread(false),
num_watchers(0), watchers(NULL), watch_handles(NULL),
bucket_id_lock("rados_bucket_id"), max_bucket_id(0),
cct(NULL), rados(NULL),
- pools_initialized(false),
- create_zone(false) {}
+ pools_initialized(false) {}
void set_context(CephContext *_cct) {
cct = _cct;
}
- void set_region(const string& name, bool create) {
+ void set_region(const string& name) {
region_name = name;
}
- void set_zone(const string& name, bool create) {
+ void set_zone(const string& name) {
zone_name = name;
- create_zone = create;
}
RGWRegion region;
@@ -538,7 +537,9 @@ public:
}
}
+ int list_raw_prefixed_objs(string pool_name, const string& prefix, list<string>& result);
int list_regions(list<string>& regions);
+ int list_zones(list<string>& zones);
void tick();