]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw-admin: add replicalog update command
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 21 Jan 2015 00:36:12 +0000 (16:36 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Wed, 28 Jan 2015 23:56:10 +0000 (15:56 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_admin.cc
src/test/cli/radosgw-admin/help.t

index 31eb2e510084241f3a1c4c42f580d2d2e53e025c..a20e170447589d894f258d849465e72744f95a39 100644 (file)
@@ -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=<id>                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=<metadata | data | bucket>" << std::endl;
       return EINVAL;
@@ -2633,6 +2638,70 @@ next:
     }
   }
 
+  if (opt_cmd == OPT_REPLICALOG_UPDATE) {
+    if (marker.empty()) {
+      cerr << "ERROR: marker was not specified" <<std::endl;
+      return EINVAL;
+    }
+    utime_t time = ceph_clock_now(NULL);
+    if (!date.empty()) {
+      ret = parse_date_str(date, time);
+      if (ret < 0) {
+        cerr << "ERROR: failed to parse start date" << std::endl;
+        return EINVAL;
+      }
+    }
+    list<RGWReplicaItemMarker> 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) {
index a46d240d54cdc66f06219ffa072716ccda80390a..33aee1d5eb332ffa70e72407c29a208c23081bd3 100644 (file)
@@ -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=<id>                user id