From 778a53ab7063d4fe8ca02fd588e2da4b4fa26b34 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Tue, 20 Jan 2015 16:36:12 -0800 Subject: [PATCH] rgw-admin: add replicalog update command Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_admin.cc | 73 ++++++++++++++++++++++++++++++- src/test/cli/radosgw-admin/help.t | 1 + 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 31eb2e5100842..a20e170447589 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -109,6 +109,7 @@ void _usage() cerr << " opstate renew renew state on an entry (use client_id, op_id, object)\n"; cerr << " opstate rm remove entry (use client_id, op_id, object)\n"; cerr << " replicalog get get replica metadata log entry\n"; + cerr << " replicalog update update replica metadata log entry\n"; cerr << " replicalog delete delete replica metadata log entry\n"; cerr << "options:\n"; cerr << " --uid= user id\n"; @@ -254,6 +255,7 @@ enum { OPT_OPSTATE_RENEW, OPT_OPSTATE_RM, OPT_REPLICALOG_GET, + OPT_REPLICALOG_UPDATE, OPT_REPLICALOG_DELETE, }; @@ -460,6 +462,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more) } else if (strcmp(prev_cmd, "replicalog") == 0) { if (strcmp(cmd, "get") == 0) return OPT_REPLICALOG_GET; + if (strcmp(cmd, "update") == 0) + return OPT_REPLICALOG_UPDATE; if (strcmp(cmd, "delete") == 0) return OPT_REPLICALOG_DELETE; } @@ -626,7 +630,7 @@ static int read_decode_json(const string& infile, T& t) } try { - t.decode_json(&p); + decode_json_obj(t, &p); } catch (JSONDecoder::err& e) { cout << "failed to decode JSON input: " << e.message << std::endl; return -EINVAL; @@ -2535,7 +2539,8 @@ next: } } - if (opt_cmd == OPT_REPLICALOG_GET || opt_cmd == OPT_REPLICALOG_DELETE) { + if (opt_cmd == OPT_REPLICALOG_GET || opt_cmd == OPT_REPLICALOG_UPDATE || + opt_cmd == OPT_REPLICALOG_DELETE) { if (replica_log_type_str.empty()) { cerr << "ERROR: need to specify --replica-log-type=" << std::endl; return EINVAL; @@ -2633,6 +2638,70 @@ next: } } + if (opt_cmd == OPT_REPLICALOG_UPDATE) { + if (marker.empty()) { + cerr << "ERROR: marker was not specified" < entries; + int ret = read_decode_json(infile, entries); + if (ret < 0) { + cerr << "ERROR: failed to decode entries" << std::endl; + return EINVAL; + } + RGWReplicaBounds bounds; + if (replica_log_type == ReplicaLog_Metadata) { + if (!specified_shard_id) { + cerr << "ERROR: shard-id must be specified for get operation" << std::endl; + return EINVAL; + } + + RGWReplicaObjectLogger logger(store, pool_name, META_REPLICA_LOG_OBJ_PREFIX); + int ret = logger.update_bound(shard_id, daemon_id, marker, time, &entries); + if (ret < 0) { + cerr << "ERROR: failed to update bounds: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + } else if (replica_log_type == ReplicaLog_Data) { + if (!specified_shard_id) { + cerr << "ERROR: shard-id must be specified for get operation" << std::endl; + return EINVAL; + } + RGWReplicaObjectLogger logger(store, pool_name, DATA_REPLICA_LOG_OBJ_PREFIX); + int ret = logger.update_bound(shard_id, daemon_id, marker, time, &entries); + if (ret < 0) { + cerr << "ERROR: failed to update bounds: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + } else if (replica_log_type == ReplicaLog_Bucket) { + if (bucket_name.empty()) { + cerr << "ERROR: bucket not specified" << std::endl; + return -EINVAL; + } + RGWBucketInfo bucket_info; + int ret = init_bucket(bucket_name, bucket_id, bucket_info, bucket); + if (ret < 0) { + cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + + RGWReplicaBucketLogger logger(store); + ret = logger.update_bound(bucket, shard_id, daemon_id, marker, time, &entries, replicalog_index_by_instance); + if (ret < 0) { + cerr << "ERROR: failed to update bounds: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + } + } + bool quota_op = (opt_cmd == OPT_QUOTA_SET || opt_cmd == OPT_QUOTA_ENABLE || opt_cmd == OPT_QUOTA_DISABLE); if (quota_op) { diff --git a/src/test/cli/radosgw-admin/help.t b/src/test/cli/radosgw-admin/help.t index a46d240d54cdc..33aee1d5eb332 100644 --- a/src/test/cli/radosgw-admin/help.t +++ b/src/test/cli/radosgw-admin/help.t @@ -67,6 +67,7 @@ opstate renew renew state on an entry (use client_id, op_id, object) opstate rm remove entry (use client_id, op_id, object) replicalog get get replica metadata log entry + replicalog update update replica metadata log entry replicalog delete delete replica metadata log entry options: --uid= user id -- 2.39.5