Skip to content

Commit

Permalink
radosgw-admin: 'period pull' reads endpoints from current period
Browse files Browse the repository at this point in the history
by finding remote endpoints from the current period, 'period pull' no
longer needs to initialize RGWRados for zone[group]_conn_map

Fixes: http://tracker.ceph.com/issues/19554

Signed-off-by: Casey Bodley <cbodley@redhat.com>
  • Loading branch information
cbodley committed Apr 8, 2017
1 parent 7a3941c commit 9f4c88c
Showing 1 changed file with 37 additions and 44 deletions.
81 changes: 37 additions & 44 deletions src/rgw/rgw_admin.cc
Expand Up @@ -1749,8 +1749,10 @@ static int init_bucket_for_sync(const string& tenant, const string& bucket_name,
return 0;
}

static int do_period_pull(const string& remote, const string& url, const string& access_key, const string& secret_key,
const string& realm_id, const string& realm_name, const string& period_id, const string& period_epoch,
static int do_period_pull(RGWRESTConn *remote_conn, const string& url,
const string& access_key, const string& secret_key,
const string& realm_id, const string& realm_name,
const string& period_id, const string& period_epoch,
RGWPeriod *period)
{
RGWEnv env;
Expand All @@ -1770,7 +1772,7 @@ static int do_period_pull(const string& remote, const string& url, const string&

bufferlist bl;
JSONParser p;
int ret = send_to_remote_or_url(nullptr, url, access_key, secret_key,
int ret = send_to_remote_or_url(remote_conn, url, access_key, secret_key,
info, bl, p);
if (ret < 0) {
cerr << "request failed: " << cpp_strerror(-ret) << std::endl;
Expand Down Expand Up @@ -2912,9 +2914,6 @@ int main(int argc, const char **argv)

// not a raw op if 'period update' needs to commit to master
bool raw_period_update = opt_cmd == OPT_PERIOD_UPDATE && !commit;
// not a raw op if 'period pull' needs to look up remotes
bool raw_period_pull = opt_cmd == OPT_PERIOD_PULL && remote.empty() && !url.empty();

std::set<int> raw_storage_ops_list = {OPT_ZONEGROUP_ADD, OPT_ZONEGROUP_CREATE, OPT_ZONEGROUP_DELETE,
OPT_ZONEGROUP_GET, OPT_ZONEGROUP_LIST,
OPT_ZONEGROUP_SET, OPT_ZONEGROUP_DEFAULT,
Expand All @@ -2930,6 +2929,7 @@ int main(int argc, const char **argv)
OPT_ZONE_PLACEMENT_MODIFY, OPT_ZONE_PLACEMENT_LIST,
OPT_REALM_CREATE,
OPT_PERIOD_DELETE, OPT_PERIOD_GET,
OPT_PERIOD_PULL,
OPT_PERIOD_GET_CURRENT, OPT_PERIOD_LIST,
OPT_GLOBAL_QUOTA_GET, OPT_GLOBAL_QUOTA_SET,
OPT_GLOBAL_QUOTA_ENABLE, OPT_GLOBAL_QUOTA_DISABLE,
Expand All @@ -2941,7 +2941,7 @@ int main(int argc, const char **argv)


bool raw_storage_op = (raw_storage_ops_list.find(opt_cmd) != raw_storage_ops_list.end() ||
raw_period_update || raw_period_pull);
raw_period_update);

if (raw_storage_op) {
store = RGWStoreManager::get_raw_storage(g_ceph_context);
Expand Down Expand Up @@ -3053,14 +3053,39 @@ int main(int argc, const char **argv)
}
}
break;
case OPT_PERIOD_PULL: // period pull --url
case OPT_PERIOD_PULL:
{
boost::optional<RGWRESTConn> conn;
RGWRESTConn *remote_conn = nullptr;
if (url.empty()) {
cerr << "A --url or --remote must be provided." << std::endl;
return EINVAL;
// load current period for endpoints
RGWRealm realm(realm_id, realm_name);
int ret = realm.init(g_ceph_context, store);
if (ret < 0) {
cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl;
return -ret;
}
RGWPeriod current_period(realm.get_current_period());
ret = current_period.init(g_ceph_context, store);
if (ret < 0) {
cerr << "failed to init current period: " << cpp_strerror(-ret) << std::endl;
return -ret;
}
if (remote.empty()) {
// use realm master zone as remote
remote = current_period.get_master_zone();
}
conn = get_remote_conn(store, current_period.get_map(), remote);
if (!conn) {
cerr << "failed to find a zone or zonegroup for remote "
<< remote << std::endl;
return -ENOENT;
}
remote_conn = &*conn;
}

RGWPeriod period;
int ret = do_period_pull(remote, url, access_key, secret_key,
int ret = do_period_pull(remote_conn, url, access_key, secret_key,
realm_id, realm_name, period_id, period_epoch,
&period);
if (ret < 0) {
Expand Down Expand Up @@ -3403,7 +3428,7 @@ int main(int argc, const char **argv)
auto& current_period = realm.get_current_period();
if (!current_period.empty()) {
// pull the latest epoch of the realm's current period
ret = do_period_pull(remote, url, access_key, secret_key,
ret = do_period_pull(nullptr, url, access_key, secret_key,
realm_id, realm_name, current_period, "",
&period);
if (ret < 0) {
Expand Down Expand Up @@ -4545,38 +4570,6 @@ int main(int argc, const char **argv)
}
}
return 0;
case OPT_PERIOD_PULL: // period pull --remote
{
if (remote.empty()) {
/* use realm master zonegroup as remote */
RGWRealm realm(realm_id, realm_name);
int ret = realm.init(g_ceph_context, store);
if (ret < 0) {
cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl;
return -ret;
}
RGWPeriod current_period(realm.get_current_period());
ret = current_period.init(g_ceph_context, store);
if (ret < 0) {
cerr << "failed to init current period: " << cpp_strerror(-ret) << std::endl;
return -ret;
}
remote = current_period.get_master_zonegroup();
}
RGWPeriod period;
int ret = do_period_pull(remote, url, access_key, secret_key,
realm_id, realm_name, period_id, period_epoch,
&period);
if (ret < 0) {
cerr << "period pull failed: " << cpp_strerror(-ret) << std::endl;
return -ret;
}

encode_json("period", period, formatter);
formatter->flush(cout);
cout << std::endl;
}
return 0;
case OPT_PERIOD_UPDATE:
{
int ret = update_period(realm_id, realm_name, period_id, period_epoch,
Expand Down

0 comments on commit 9f4c88c

Please sign in to comment.