switch (opt_cmd) {
case OPT_PERIOD_PREPARE:
{
+ RGWRealm realm(realm_id, realm_name);
+ int ret = realm.init(g_ceph_context, store);
+ if (ret < 0) {
+ cerr << "could not init realm " << ": " << cpp_strerror(-ret) << std::endl;
+ return ret;
+ }
RGWPeriod period(g_ceph_context, store, master_zonegroup, master_zone);
- int ret = period.create();
+ ret = period.init(realm.get_id(), realm.get_name(), false);
+ if (ret < 0) {
+ cerr << "failed to init period " << ": " << cpp_strerror(-ret) << std::endl;
+ return ret;
+ }
+ ret = period.create();
if (ret < 0) {
- cerr << "ERROR: couldn't prepare new period " << ": " << cpp_strerror(-ret) << std::endl;
+ cerr << "ERROR: couldn't create period " << ": " << cpp_strerror(-ret) << std::endl;
return ret;
}
encode_json("period", period, formatter);
cerr << "period init failed: " << cpp_strerror(-ret) << std::endl;
return -ret;
}
+ encode_json("realm", period.get_realm(), formatter);
encode_json("period", period, formatter);
formatter->flush(cout);
cout << std::endl;
cerr << "Error initing realm " << cpp_strerror(-ret) << std::endl;
return ret;
}
+ cerr << "realm id " << realm.get_id() << " name " << realm.get_name() << std::endl;
ret = realm.set_current_period(period_id);
if (ret < 0 ) {
cerr << "Error setting current period " << period_id << ":" << cpp_strerror(-ret) << std::endl;
static string zonegroup_names_oid_prefix = "zonegroups_names.";
static RGWObjCategory main_category = RGW_OBJ_CATEGORY_MAIN;
#define RGW_USAGE_OBJ_PREFIX "usage."
-
+#define FIRST_EPOCH 1
static string RGW_DEFAULT_ZONE_ROOT_POOL = "rgw.root";
static string RGW_DEFAULT_ZONEGROUP_ROOT_POOL = "rgw.root";
static string RGW_DEFAULT_REALM_ROOT_POOL = "rgw.root";
int RGWRealm::set_current_period(const string& period_id) {
/* check to see period id is valid */
- RGWPeriod new_current(cct, store);
- int ret = new_current.init(period_id);
+ RGWPeriod new_current(cct, store, period_id);
+ int ret = new_current.init();
if (ret < 0) {
+ derr << "Error init new period id " << period_id << " : " << cpp_strerror(-ret) << dendl;
return ret;
}
- if (new_current.get_predecessor() != current_period) {
+ if (!current_period.empty() && new_current.get_predecessor() != current_period) {
ldout(cct, 0) << "set_current_period new period " << period_id <<
" is not a perdecessor of the current period "<< current_period << dendl;
return -EINVAL;
}
current_period = period_id;
- return store_info(true);
+ return update();
}
int RGWPeriod::init(const string& period_id, epoch_t period_epoch, bool setup_obj)
RGWRealm realm(realm_id, period_realm_name);
int ret = realm.init(cct, store);
if (ret < 0) {
+ derr << "failed to init realm " << period_realm_name << " id " << realm_id << " : " << cpp_strerror(-ret) <<
+ dendl;
return ret;
}
- /* update realm_id incare we used a period_name */
+ /* update realm_id in case we used a realm name */
if (realm_id.empty()) {
realm_id = realm.get_id();
}
if (!epoch) {
ret = use_latest_epoch();
if (ret < 0) {
+ derr << "failed to use_latest_epoch " << period_realm_name << " id " << realm_id << " : "
+ << cpp_strerror(-ret) << dendl;
return ret;
}
}
- return read_info(id);
+ return read_info();
}
const string& RGWPeriod::get_latest_epoch_oid()
return period_info_oid_prefix;
}
+const string RGWPeriod::get_period_oid_prefix()
+{
+ return get_info_oid_prefix() + realm_id + "." + id;
+}
+
+const string RGWPeriod::get_period_oid()
+{
+ std::ostringstream oss;
+ oss << get_period_oid_prefix() << "." << epoch;
+
+ return oss.str();;
+}
+
int RGWPeriod::read_latest_epoch(RGWPeriodLatestEpochInfo& info)
{
string pool_name = get_pool_name(cct);
- string oid = get_info_oid_prefix() + id +
- get_latest_epoch_oid();
+ string oid = get_period_oid_prefix() + get_latest_epoch_oid();
rgw_bucket pool(pool_name.c_str());
bufferlist bl;
RGWObjectCtx obj_ctx(store);
int ret = rgw_get_system_obj(store, obj_ctx, pool, oid, bl, NULL, NULL);
- if (ret < 0)
+ if (ret < 0) {
+ derr << "error read_lastest_epoch " << pool << ":" << oid << dendl;
return ret;
-
+ }
try {
bufferlist::iterator iter = bl.begin();
::decode(info, iter);
{
RGWPeriodLatestEpochInfo info;
int ret = read_latest_epoch(info);
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
epoch = info.epoch;
return 0;
}
+int RGWPeriod::set_latest_epoch(const epoch_t& epoch)
+{
+ string pool_name = get_pool_name(cct);
+ string oid = get_period_oid_prefix() + get_latest_epoch_oid();
+
+ rgw_bucket pool(pool_name.c_str());
+ bufferlist bl;
+
+ RGWPeriodLatestEpochInfo info;
+ info.epoch = epoch;
+
+ ::encode(info, bl);
+
+ int ret = rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), false, NULL, 0, NULL);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+
+}
int RGWPeriod::delete_obj()
{
string pool_name = get_pool_name(cct);
rgw_bucket pool(pool_name.c_str());
- string oid = get_info_oid_prefix() + id;
- rgw_obj object_id(pool, oid);
+ rgw_obj object_id(pool, get_period_oid());
int ret = store->delete_system_obj(object_id);
if (ret < 0) {
lderr(cct) << "Error delete object id " << id << ": " << cpp_strerror(-ret) << dendl;
return ret;
}
-int RGWPeriod::read_info(const string& obj_id)
+int RGWPeriod::read_info()
{
string pool_name = get_pool_name(cct);
rgw_bucket pool(pool_name.c_str());
bufferlist bl;
- string oid = get_info_oid_prefix() + obj_id;
RGWObjectCtx obj_ctx(store);
- int ret = rgw_get_system_obj(store, obj_ctx, pool, oid, bl, NULL, NULL);
+ int ret = rgw_get_system_obj(store, obj_ctx, pool, get_period_oid(), bl, NULL, NULL);
if (ret < 0) {
- lderr(cct) << "failed reading obj info from " << pool << ":" << oid << ": " << cpp_strerror(-ret) << dendl;
+ lderr(cct) << "failed reading obj info from " << pool << ":" << get_period_oid() << ": " << cpp_strerror(-ret) << dendl;
return ret;
}
bufferlist::iterator iter = bl.begin();
::decode(*this, iter);
} catch (buffer::error& err) {
- ldout(cct, 0) << "ERROR: failed to decode obj from " << pool << ":" << oid << dendl;
+ ldout(cct, 0) << "ERROR: failed to decode obj from " << pool << ":" << get_period_oid() << dendl;
return -EIO;
}
int RGWPeriod::create()
{
int ret;
-
+
/* create unique id */
uuid_d new_uuid;
char uuid_str[37];
new_uuid.print(uuid_str);
id = uuid_str;
+ epoch = FIRST_EPOCH;
+
ret = store_info(true);
if (ret < 0) {
ldout(cct, 0) << "ERROR: storing info for " << id << ": " << cpp_strerror(-ret) << dendl;
}
+ ret = set_latest_epoch(epoch);
+ if (ret < 0) {
+ ldout(cct, 0) << "ERROR: setting latest epoch " << id << ": " << cpp_strerror(-ret) << dendl;
+ }
+
return ret;
}
rgw_bucket pool(pool_name.c_str());
- string oid = get_info_oid_prefix() + id;
-
+ std::ostringstream oss;
+ oss << get_info_oid_prefix() << realm_id << "." << id << "." << epoch;
+ string oid = oss.str();
+ derr << " period store_info " << oid << dendl;
bufferlist bl;
::encode(*this, bl);
return rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), exclusive, NULL, 0, NULL);
CephContext *cct;
RGWRados *store;
- int read_info(const string& obj_id);
+ int read_info();
int read_latest_epoch(RGWPeriodLatestEpochInfo& epoch_info);
int use_latest_epoch();
int set_latest_epoch(const epoch_t& epoch);
int use_current_period();
+ const string get_period_oid();
+ const string get_period_oid_prefix();
+
public:
RGWPeriod(CephContext *_cct, RGWRados *_store,
const string& period_id = "", epoch_t _epoch = 0)
: id(period_id), epoch(_epoch), master_zonegroup(_master_zonegroup), master_zone(_master_zone), cct(_cct),
store(_store) {}
- string get_id() { return id;}
+ const string& get_id() { return id;}
epoch_t get_epoch() { return epoch;}
- string get_predecessor() { return predecessor_uuid;}
- string get_master_zonegroup() { return master_zonegroup;}
- string get_master_zone() { return master_zone;}
+ const string& get_predecessor() { return predecessor_uuid;}
+ const string& get_master_zonegroup() { return master_zonegroup;}
+ const string& get_master_zone() { return master_zone;}
+ const string& get_realm() { return realm_id;}
const string& get_pool_name(CephContext *cct);
const string& get_latest_epoch_oid();
int get_latest_epoch(epoch_t& epoch);
int init(const string& realm_id = "", const string &realm_name = "", bool setup_obj = true);
int init(const string& period_id, epoch_t epoch, bool setup_obj = true);
-
int create();
int delete_obj();
int store_info(bool exclusive);
int activate() { return -ENOTSUP;}
void encode(bufferlist& bl) const {
- ENCODE_START(1, 1, bl);
+ ENCODE_START(1, 1, bl);
::encode(id, bl);
::encode(epoch, bl);
::encode(predecessor_uuid, bl);