diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-09-19 11:13:50 -0700 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-09-19 11:13:50 -0700 |
commit | 2a46738d3d4983a545e7d1aaea0342cc28f48923 (patch) | |
tree | 4cf951ef25895e56767ce86696fb33c294f22776 | |
parent | f22ef1e65977b86d90f990bceecdda5c06d36fe8 (diff) | |
download | ceph-2a46738d3d4983a545e7d1aaea0342cc28f48923.tar.gz |
radosgw-admin: new 'bucket rewrite' command
Iterates through objects and rewrites them.
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r-- | src/rgw/rgw_admin.cc | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 58b83790d97..43dcbe46f90 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -147,6 +147,7 @@ enum { OPT_BUCKET_STATS, OPT_BUCKET_CHECK, OPT_BUCKET_RM, + OPT_BUCKET_REWRITE, OPT_POLICY, OPT_POOL_ADD, OPT_POOL_RM, @@ -293,6 +294,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more) return OPT_BUCKET_STATS; if (strcmp(cmd, "rm") == 0) return OPT_BUCKET_RM; + if (strcmp(cmd, "rewrite") == 0) + return OPT_BUCKET_REWRITE; if (strcmp(cmd, "check") == 0) return OPT_BUCKET_CHECK; } else if (strcmp(prev_cmd, "log") == 0) { @@ -1774,11 +1777,66 @@ next: int ret = store->rewrite_obj(obj); if (ret < 0) { - cerr << "ERROR: object remove returned: " << cpp_strerror(-ret) << std::endl; + cerr << "ERROR: object rewrite returned: " << cpp_strerror(-ret) << std::endl; return -ret; } } + if (opt_cmd == OPT_BUCKET_REWRITE) { + if (bucket_name.empty()) { + cerr << "ERROR: bucket not specified" << std::endl; + return EINVAL; + } + + bool is_truncated = true; + + string marker; + string prefix; + + formatter->open_object_section("result"); + formatter->dump_string("bucket", bucket_name); + formatter->open_array_section("objects"); + while (is_truncated) { + map<string, RGWObjEnt> result; + string ns; + int r = store->cls_bucket_list(bucket, marker, prefix, 1000, + result, &is_truncated, &marker, + bucket_object_check_filter); + + if (r < 0 && r != -ENOENT) { + cerr << "ERROR: failed operation r=" << r << std::endl; + } + + if (r == -ENOENT) + break; + + map<string, RGWObjEnt>::iterator iter; + for (iter = result.begin(); iter != result.end(); ++iter) { + string name = iter->first; + + formatter->open_object_section("object"); + formatter->dump_string("name", iter->first); + formatter->dump_int("size", iter->second.size); + utime_t ut(iter->second.mtime, 0); + ut.gmtime(formatter->dump_stream("mtime")); + + rgw_obj obj(bucket, name); + r = store->rewrite_obj(obj); + if (r == 0) { + formatter->dump_string("status", "Success"); + } else { + formatter->dump_string("status", cpp_strerror(-r)); + } + + formatter->close_section(); + formatter->flush(cout); + } + } + formatter->close_section(); + formatter->close_section(); + formatter->flush(cout); + } + if (opt_cmd == OPT_OBJECT_UNLINK) { list<string> oid_list; oid_list.push_back(object); |