Skip to content

Commit

Permalink
Merge pull request #5717: rgw: create a tool for orphaned objects cle…
Browse files Browse the repository at this point in the history
…anup

Reviewed-by: Loic Dachary <ldachary@redhat.com>
  • Loading branch information
ldachary committed Aug 30, 2015
2 parents c120d8c + f1c7c62 commit 6af2660
Show file tree
Hide file tree
Showing 11 changed files with 1,393 additions and 73 deletions.
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,8 @@ if(${WITH_RADOSGW})
rgw/rgw_main.cc)

set(radosgw_admin_srcs
rgw/rgw_admin.cc)
rgw/rgw_admin.cc
rgw/rgw_orphan.cc)

add_executable(radosgw ${radosgw_srcs} $<TARGET_OBJECTS:heap_profiler_objs>)
target_link_libraries(radosgw rgw_a librados
Expand Down
1 change: 1 addition & 0 deletions src/common/config_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ OPTION(rgw_op_thread_timeout, OPT_INT, 10*60)
OPTION(rgw_op_thread_suicide_timeout, OPT_INT, 0)
OPTION(rgw_thread_pool_size, OPT_INT, 100)
OPTION(rgw_num_control_oids, OPT_INT, 8)
OPTION(rgw_num_rados_handles, OPT_U32, 1)

OPTION(rgw_zone, OPT_STR, "") // zone name
OPTION(rgw_zone_root_pool, OPT_STR, ".rgw.root") // pool where zone specific info is stored
Expand Down
3 changes: 2 additions & 1 deletion src/rgw/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ radosgw_CFLAGS = -I$(srcdir)/civetweb/include
radosgw_LDADD = $(LIBRGW) $(LIBCIVETWEB) $(LIBRGW_DEPS) $(RESOLV_LIBS) $(CEPH_GLOBAL)
bin_PROGRAMS += radosgw

radosgw_admin_SOURCES = rgw/rgw_admin.cc
radosgw_admin_SOURCES = rgw/rgw_admin.cc rgw/rgw_orphan.cc
radosgw_admin_LDADD = $(LIBRGW) $(LIBRGW_DEPS) $(CEPH_GLOBAL)
bin_PROGRAMS += radosgw-admin

Expand Down Expand Up @@ -141,6 +141,7 @@ noinst_HEADERS += \
rgw/rgw_metadata.h \
rgw/rgw_multi_del.h \
rgw/rgw_op.h \
rgw/rgw_orphan.h \
rgw/rgw_http_client.h \
rgw/rgw_swift.h \
rgw/rgw_swift_auth.h \
Expand Down
72 changes: 72 additions & 0 deletions src/rgw/rgw_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ using namespace std;
#include "rgw_formats.h"
#include "rgw_usage.h"
#include "rgw_replica_log.h"
#include "rgw_orphan.h"

#define dout_subsys ceph_subsys_rgw

Expand Down Expand Up @@ -232,6 +233,8 @@ enum {
OPT_QUOTA_DISABLE,
OPT_GC_LIST,
OPT_GC_PROCESS,
OPT_ORPHANS_FIND,
OPT_ORPHANS_FINISH,
OPT_REGION_GET,
OPT_REGION_LIST,
OPT_REGION_SET,
Expand Down Expand Up @@ -281,6 +284,7 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
strcmp(cmd, "object") == 0 ||
strcmp(cmd, "olh") == 0 ||
strcmp(cmd, "opstate") == 0 ||
strcmp(cmd, "orphans") == 0 ||
strcmp(cmd, "pool") == 0 ||
strcmp(cmd, "pools") == 0 ||
strcmp(cmd, "quota") == 0 ||
Expand Down Expand Up @@ -441,6 +445,11 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
return OPT_GC_LIST;
if (strcmp(cmd, "process") == 0)
return OPT_GC_PROCESS;
} else if (strcmp(prev_cmd, "orphans") == 0) {
if (strcmp(cmd, "find") == 0)
return OPT_ORPHANS_FIND;
if (strcmp(cmd, "finish") == 0)
return OPT_ORPHANS_FINISH;
} else if (strcmp(prev_cmd, "metadata") == 0) {
if (strcmp(cmd, "get") == 0)
return OPT_METADATA_GET;
Expand Down Expand Up @@ -1059,6 +1068,7 @@ int do_check_object_locator(const string& bucket_name, bool fix, bool remove_bad
return 0;
}


int main(int argc, char **argv)
{
vector<const char*> args;
Expand Down Expand Up @@ -1140,6 +1150,11 @@ int main(int argc, char **argv)

BIIndexType bi_index_type = PlainIdx;

string job_id;
int num_shards = 0;
int max_concurrent_ios = 32;
uint64_t orphan_stale_secs = (24 * 3600);

std::string val;
std::ostringstream errs;
string err;
Expand Down Expand Up @@ -1189,6 +1204,8 @@ int main(int argc, char **argv)
cerr << "bad key type: " << key_type_str << std::endl;
return usage();
}
} else if (ceph_argparse_witharg(args, i, &val, "--job-id", (char*)NULL)) {
job_id = val;
} else if (ceph_argparse_binary_flag(args, i, &gen_access_key, NULL, "--gen-access-key", (char*)NULL)) {
// do nothing
} else if (ceph_argparse_binary_flag(args, i, &gen_secret_key, NULL, "--gen-secret", (char*)NULL)) {
Expand Down Expand Up @@ -1238,6 +1255,12 @@ int main(int argc, char **argv)
start_date = val;
} else if (ceph_argparse_witharg(args, i, &val, "--end-date", "--end-time", (char*)NULL)) {
end_date = val;
} else if (ceph_argparse_witharg(args, i, &val, "--num-shards", (char*)NULL)) {
num_shards = atoi(val.c_str());
} else if (ceph_argparse_witharg(args, i, &val, "--max-concurrent-ios", (char*)NULL)) {
max_concurrent_ios = atoi(val.c_str());
} else if (ceph_argparse_witharg(args, i, &val, "--orphan-stale-secs", (char*)NULL)) {
orphan_stale_secs = (uint64_t)atoi(val.c_str());
} else if (ceph_argparse_witharg(args, i, &val, "--shard-id", (char*)NULL)) {
shard_id = atoi(val.c_str());
specified_shard_id = true;
Expand Down Expand Up @@ -2557,6 +2580,55 @@ int main(int argc, char **argv)
}
}

if (opt_cmd == OPT_ORPHANS_FIND) {
RGWOrphanSearch search(store, max_concurrent_ios, orphan_stale_secs);

if (job_id.empty()) {
cerr << "ERROR: --job-id not specified" << std::endl;
return EINVAL;
}
if (pool_name.empty()) {
cerr << "ERROR: --pool not specified" << std::endl;
return EINVAL;
}

RGWOrphanSearchInfo info;

info.pool = pool_name;
info.job_name = job_id;
info.num_shards = num_shards;

int ret = search.init(job_id, &info);
if (ret < 0) {
cerr << "could not init search, ret=" << ret << std::endl;
return -ret;
}
ret = search.run();
if (ret < 0) {
return -ret;
}
}

if (opt_cmd == OPT_ORPHANS_FINISH) {
RGWOrphanSearch search(store, max_concurrent_ios, orphan_stale_secs);

if (job_id.empty()) {
cerr << "ERROR: --job-id not specified" << std::endl;
return EINVAL;
}
int ret = search.init(job_id, NULL);
if (ret < 0) {
if (ret == -ENOENT) {
cerr << "job not found" << std::endl;
}
return -ret;
}
ret = search.finish();
if (ret < 0) {
return -ret;
}
}

if (opt_cmd == OPT_USER_CHECK) {
check_bad_user_bucket_mapping(store, user_id, fix);
}
Expand Down
43 changes: 29 additions & 14 deletions src/rgw/rgw_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1316,31 +1316,46 @@ class rgw_obj {
* part of the given namespace, it returns false.
*/
static bool translate_raw_obj_to_obj_in_ns(string& obj, string& instance, string& ns) {
if (ns.empty()) {
if (obj[0] != '_')
return true;

if (obj.size() >= 2 && obj[1] == '_') {
obj = obj.substr(1);
if (obj[0] != '_') {
if (ns.empty()) {
return true;
}

return false;
}

if (obj[0] != '_' || obj.size() < 3) // for namespace, min size would be 3: _x_
string obj_ns;
bool ret = parse_raw_oid(obj, &obj, &instance, &obj_ns);
if (!ret) {
return ret;
}

return (ns == obj_ns);
}

static bool parse_raw_oid(const string& oid, string *obj_name, string *obj_instance, string *obj_ns) {
obj_instance->clear();
obj_ns->clear();
if (oid[0] != '_') {
*obj_name = oid;
return true;
}

if (oid.size() >= 2 && oid[1] == '_') {
*obj_name = oid.substr(1);
return true;
}

if (oid[0] != '_' || oid.size() < 3) // for namespace, min size would be 3: _x_
return false;

int pos = obj.find('_', 1);
int pos = oid.find('_', 1);
if (pos <= 1) // if it starts with __, it's not in our namespace
return false;

string obj_ns = obj.substr(1, pos - 1);
parse_ns_field(obj_ns, instance);
if (obj_ns.compare(ns) != 0)
return false;
*obj_ns = oid.substr(1, pos - 1);
parse_ns_field(*obj_ns, *obj_instance);

obj = obj.substr(pos + 1);
*obj_name = oid.substr(pos + 1);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ int RGWGC::process(int index, int max_secs)
if (obj.pool != last_pool) {
delete ctx;
ctx = new IoCtx;
ret = store->rados->ioctx_create(obj.pool.c_str(), *ctx);
ret = store->get_rados_handle()->ioctx_create(obj.pool.c_str(), *ctx);
if (ret < 0) {
dout(0) << "ERROR: failed to create ioctx pool=" << obj.pool << dendl;
continue;
Expand Down
Loading

0 comments on commit 6af2660

Please sign in to comment.