From 8d0295cbb60d510cc8bc280e6d0724f805e1e218 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 12 May 2014 14:46:18 -0700 Subject: [PATCH] rgw: extend replica log api (purge-all) Adding a new purge-all option for the replica log api, which completely removes a replica log object. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_admin.cc | 6 +++--- src/rgw/rgw_replica_log.cc | 6 +++++- src/rgw/rgw_replica_log.h | 10 +++++----- src/rgw/rgw_rest_replica_log.cc | 19 +++++++++++++------ 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index cc893fd9b509f..31eb2e5100842 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -2598,7 +2598,7 @@ next: return EINVAL; } RGWReplicaObjectLogger logger(store, pool_name, META_REPLICA_LOG_OBJ_PREFIX); - int ret = logger.delete_bound(shard_id, daemon_id); + int ret = logger.delete_bound(shard_id, daemon_id, false); if (ret < 0) return -ret; } else if (replica_log_type == ReplicaLog_Data) { @@ -2611,7 +2611,7 @@ next: return EINVAL; } RGWReplicaObjectLogger logger(store, pool_name, DATA_REPLICA_LOG_OBJ_PREFIX); - int ret = logger.delete_bound(shard_id, daemon_id); + int ret = logger.delete_bound(shard_id, daemon_id, false); if (ret < 0) return -ret; } else if (replica_log_type == ReplicaLog_Bucket) { @@ -2627,7 +2627,7 @@ next: } RGWReplicaBucketLogger logger(store); - ret = logger.delete_bound(bucket, shard_id, daemon_id, replicalog_index_by_instance); + ret = logger.delete_bound(bucket, shard_id, daemon_id, replicalog_index_by_instance, false); if (ret < 0) return -ret; } diff --git a/src/rgw/rgw_replica_log.cc b/src/rgw/rgw_replica_log.cc index a9a3b711ee72b..f88b132bd29f8 100644 --- a/src/rgw/rgw_replica_log.cc +++ b/src/rgw/rgw_replica_log.cc @@ -76,7 +76,7 @@ int RGWReplicaLogger::update_bound(const string& oid, const string& pool, } int RGWReplicaLogger::delete_bound(const string& oid, const string& pool, - const string& daemon_id) + const string& daemon_id, bool purge_all) { librados::IoCtx ioctx; int r = open_ioctx(ioctx, pool); @@ -84,6 +84,10 @@ int RGWReplicaLogger::delete_bound(const string& oid, const string& pool, return r; } + if (purge_all) { + return ioctx.remove(oid); + } + librados::ObjectWriteOperation opw; cls_replica_log_delete_bound(opw, daemon_id); return ioctx.operate(oid, &opw); diff --git a/src/rgw/rgw_replica_log.h b/src/rgw/rgw_replica_log.h index 544030a2ae0d3..16209a08a7b12 100644 --- a/src/rgw/rgw_replica_log.h +++ b/src/rgw/rgw_replica_log.h @@ -52,7 +52,7 @@ protected: const utime_t& time, const list *entries); int delete_bound(const string& oid, const string& pool, - const string& daemon_id); + const string& daemon_id, bool purge_all); int get_bounds(const string& oid, const string& pool, RGWReplicaBounds& bounds); }; @@ -81,11 +81,11 @@ public: return RGWReplicaLogger::update_bound(oid, pool, daemon_id, marker, time, entries); } - int delete_bound(int shard, const string& daemon_id) { + int delete_bound(int shard, const string& daemon_id, bool purge_all) { string oid; get_shard_oid(shard, oid); return RGWReplicaLogger::delete_bound(oid, pool, - daemon_id); + daemon_id, purge_all); } int get_bounds(int shard, RGWReplicaBounds& bounds) { string oid; @@ -105,9 +105,9 @@ public: int update_bound(const rgw_bucket& bucket, int shard_id, const string& daemon_id, const string& marker, const utime_t& time, const list *entries); - int delete_bound(const rgw_bucket& bucket, int shard_id, const string& daemon_id, bool index_by_instance) { + int delete_bound(const rgw_bucket& bucket, int shard_id, const string& daemon_id, bool index_by_instance, bool purge_all) { return RGWReplicaLogger::delete_bound(obj_name(bucket, shard_id, index_by_instance), pool, - daemon_id); + daemon_id, purge_all); } int get_bounds(const rgw_bucket& bucket, int shard_id, RGWReplicaBounds& bounds, bool index_by_instance) { return RGWReplicaLogger::get_bounds(obj_name(bucket, shard_id, index_by_instance), pool, diff --git a/src/rgw/rgw_rest_replica_log.cc b/src/rgw/rgw_rest_replica_log.cc index f842d90bff8c3..2f6d760fddbf0 100644 --- a/src/rgw/rgw_rest_replica_log.cc +++ b/src/rgw/rgw_rest_replica_log.cc @@ -121,9 +121,12 @@ void RGWOp_OBJLog_GetBounds::send_response() { void RGWOp_OBJLog_DeleteBounds::execute() { string id = s->info.args.get("id"), daemon_id = s->info.args.get("daemon_id"); + bool purge_all; + + s->info.args.get_bool("purge-all", &purge_all, false); if (id.empty() || - daemon_id.empty()) { + (!purge_all && daemon_id.empty())) { dout(5) << "Error - invalid parameter list" << dendl; http_ret = -EINVAL; return; @@ -137,10 +140,10 @@ void RGWOp_OBJLog_DeleteBounds::execute() { dout(5) << "Error parsing id parameter - " << id << ", err " << err << dendl; http_ret = -EINVAL; } - + string pool; RGWReplicaObjectLogger rl(store, pool, prefix); - http_ret = rl.delete_bound(shard, daemon_id); + http_ret = rl.delete_bound(shard, daemon_id, purge_all); } static int bucket_instance_to_bucket(RGWRados *store, string& bucket_instance, rgw_bucket& bucket) { @@ -286,8 +289,11 @@ void RGWOp_BILog_GetBounds::send_response() { void RGWOp_BILog_DeleteBounds::execute() { string bucket_instance = s->info.args.get("bucket-instance"); string daemon_id = s->info.args.get("daemon_id"); + bool purge_all; - if (daemon_id.empty()) { + s->info.args.get_bool("purge-all", &purge_all, false); + + if (daemon_id.empty() && !purge_all) { dout(5) << "Error - invalid parameter list" << dendl; http_ret = -EINVAL; return; @@ -306,9 +312,10 @@ void RGWOp_BILog_DeleteBounds::execute() { if ((http_ret = get_bucket_for_bounds(store, s->info.args, bucket, &index_by_instance)) < 0) { return; } - + + RGWReplicaBucketLogger rl(store); - http_ret = rl.delete_bound(bucket, shard_id, daemon_id, index_by_instance); + http_ret = rl.delete_bound(bucket, shard_id, daemon_id, index_by_instance, purge_all); } RGWOp *RGWHandler_ReplicaLog::op_get() { -- 2.39.5