]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: OpState internal api
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 19 Jun 2013 06:02:05 +0000 (23:02 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Wed, 19 Jun 2013 06:02:05 +0000 (23:02 -0700)
Add new higher level functions to set, renew, list, and remove
logged operation state.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/common/config_opts.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index d95724fce8ff4e1ccef5e2b9f6055d3b105487d8..b48cfd5db1e0ef835a1fe6d1fe2fe68298172619 100644 (file)
@@ -602,7 +602,7 @@ OPTION(rgw_get_obj_max_req_size, OPT_INT, 4 << 20) // max length of a single get
 OPTION(rgw_relaxed_s3_bucket_names, OPT_BOOL, false) // enable relaxed bucket name rules for US region buckets
 OPTION(rgw_list_buckets_max_chunk, OPT_INT, 1000) // max buckets to retrieve in a single op when listing user buckets
 OPTION(rgw_md_log_max_shards, OPT_INT, 64) // max shards for metadata log
-OPTION(rgw_num_zone_copy_state_shards, OPT_INT, 128) // max shards for keeping inter-region copy progress info
+OPTION(rgw_num_zone_opstate_shards, OPT_INT, 128) // max shards for keeping inter-region copy progress info
 
 OPTION(rgw_data_log_window, OPT_INT, 30) // data log entries window (in seconds)
 OPTION(rgw_data_log_changes_size, OPT_INT, 1000) // number of in-memory entries to hold for data changes log
index 61f7b3a45efba8c991ac6c6b0ec39c6cf72fc9fd..7ad84c44617aad02e0b5f7458ca53754a8adb612 100644 (file)
@@ -5188,7 +5188,7 @@ void RGWStateLog::oid_str(int shard, string& oid) {
 
 int RGWStateLog::get_shard_num(const string& object) {
   uint32_t val = ceph_str_hash_linux(object.c_str(), object.length());
-  return val & num_shards;
+  return val % num_shards;
 }
 
 string RGWStateLog::get_oid(const string& object) {
@@ -5240,6 +5240,31 @@ int RGWStateLog::store_entry(const string& client_id, const string& op_id, const
   return 0;
 }
 
+int RGWStateLog::remove_entry(const string& client_id, const string& op_id, const string& object)
+{
+  if (client_id.empty() ||
+      op_id.empty() ||
+      object.empty()) {
+    ldout(store->ctx(), 0) << "client_id / op_id / object is empty" << dendl;
+  }
+
+  librados::IoCtx ioctx;
+  int r = open_ioctx(ioctx);
+  if (r < 0)
+    return r;
+
+  string oid = get_oid(object);
+
+  librados::ObjectWriteOperation op;
+  cls_statelog_remove_by_object(op, object, op_id);
+  r = ioctx.operate(oid, &op);
+  if (r < 0) {
+    return r;
+  }
+
+  return 0;
+}
+
 void RGWStateLog::init_list_entries(const string& client_id, const string& op_id, const string& object,
                                     void **handle)
 {
@@ -5257,7 +5282,8 @@ void RGWStateLog::init_list_entries(const string& client_id, const string& op_id
 }
 
 int RGWStateLog::list_entries(void *handle, int max_entries,
-                              list<cls_statelog_entry>& entries)
+                              list<cls_statelog_entry>& entries,
+                              bool *done)
 {
   list_state *state = (list_state *)handle;
 
@@ -5266,6 +5292,8 @@ int RGWStateLog::list_entries(void *handle, int max_entries,
   if (r < 0)
     return r;
 
+  entries.clear();
+
   for (; state->cur_shard <= state->max_shard && max_entries > 0; ++state->cur_shard) {
     string oid;
     oid_str(state->cur_shard, oid);
@@ -5288,14 +5316,18 @@ int RGWStateLog::list_entries(void *handle, int max_entries,
 
     if (!truncated) {
       state->marker.clear();
-      state->cur_shard++;
     }
 
     max_entries -= ents.size();
 
     entries.splice(entries.end(), ents);
+
+    if (truncated)
+      break;
   }
 
+  *done = (state->cur_shard > state->max_shard);
+
   return 0;
 }
 
@@ -5318,30 +5350,30 @@ void RGWStateLog::dump_entry(const cls_statelog_entry& entry, Formatter *f)
   f->close_section();
 }
 
-RGWObjZoneCopyState::RGWObjZoneCopyState(RGWRados *_store) : RGWStateLog(_store, _store->ctx()->_conf->rgw_num_zone_copy_state_shards, string("obj_zone_copy"))
+RGWOpState::RGWOpState(RGWRados *_store) : RGWStateLog(_store, _store->ctx()->_conf->rgw_num_zone_opstate_shards, string("obj_opstate"))
 {
 }
 
-bool RGWObjZoneCopyState::dump_entry_internal(const cls_statelog_entry& entry, Formatter *f)
+bool RGWOpState::dump_entry_internal(const cls_statelog_entry& entry, Formatter *f)
 {
   string s;
-  switch ((CopyState)entry.state) {
-    case CS_UNKNOWN:
+  switch ((OpState)entry.state) {
+    case OPSTATE_UNKNOWN:
       s = "unknown";
       break;
-    case CS_IN_PROGRESS:
+    case OPSTATE_IN_PROGRESS:
       s = "in-progress";
       break;
-    case CS_COMPLETE:
+    case OPSTATE_COMPLETE:
       s = "complete";
       break;
-    case CS_ERROR:
+    case OPSTATE_ERROR:
       s = "error";
       break;
-    case CS_ABORT:
+    case OPSTATE_ABORT:
       s = "abort";
       break;
-    case CS_CANCELLED:
+    case OPSTATE_CANCELLED:
       s = "cancelled";
       break;
     default:
@@ -5351,13 +5383,34 @@ bool RGWObjZoneCopyState::dump_entry_internal(const cls_statelog_entry& entry, F
   return true;
 }
 
-int RGWObjZoneCopyState::set_state(const string& client_id, const string& op_id, const string& object, CopyState state)
+int RGWOpState::state_from_str(const string& s, OpState *state)
+{
+  if (s == "unknown") {
+    *state = OPSTATE_UNKNOWN;
+  } else if (s == "in-progress") {
+    *state = OPSTATE_IN_PROGRESS;
+  } else if (s == "complete") {
+    *state = OPSTATE_COMPLETE;
+  } else if (s == "error") {
+    *state = OPSTATE_ERROR;
+  } else if (s == "abort") {
+    *state = OPSTATE_ABORT;
+  } else if (s == "cancelled") {
+    *state = OPSTATE_CANCELLED;
+  } else {
+    return -EINVAL;
+  }
+
+  return 0;
+}
+
+int RGWOpState::set_state(const string& client_id, const string& op_id, const string& object, OpState state)
 {
   uint32_t s = (uint32_t)state;
   return store_entry(client_id, op_id, object, s, NULL, NULL);
 }
 
-int RGWObjZoneCopyState::renew_state(const string& client_id, const string& op_id, const string& object, CopyState state)
+int RGWOpState::renew_state(const string& client_id, const string& op_id, const string& object, OpState state)
 {
   uint32_t s = (uint32_t)state;
   return store_entry(client_id, op_id, object, s, NULL, &s);
index 544743dccf109219bf722de21205293f9a1b0b2b..f292f47cb0e0ec2a9613c02b27c8010316f0762c 100644 (file)
@@ -598,10 +598,12 @@ public:
   int store_entry(const string& client_id, const string& op_id, const string& object,
                   uint32_t state, bufferlist *bl, uint32_t *check_state);
 
+  int remove_entry(const string& client_id, const string& op_id, const string& object);
+
   void init_list_entries(const string& client_id, const string& op_id, const string& object,
                          void **handle);
 
-  int list_entries(void *handle, int max_entries, list<cls_statelog_entry>& entries);
+  int list_entries(void *handle, int max_entries, list<cls_statelog_entry>& entries, bool *done);
 
   void finish_list_entries(void *handle);
 
@@ -626,24 +628,25 @@ public:
  *
  */
 
-class RGWObjZoneCopyState : public RGWStateLog {
+class RGWOpState : public RGWStateLog {
 protected:
   bool dump_entry_internal(const cls_statelog_entry& entry, Formatter *f);
 public:
 
-  enum CopyState {
-    CS_UNKNOWN     = 0,
-    CS_IN_PROGRESS = 1,
-    CS_COMPLETE    = 2,
-    CS_ERROR       = 3,
-    CS_ABORT       = 4,
-    CS_CANCELLED   = 5,
+  enum OpState {
+    OPSTATE_UNKNOWN     = 0,
+    OPSTATE_IN_PROGRESS = 1,
+    OPSTATE_COMPLETE    = 2,
+    OPSTATE_ERROR       = 3,
+    OPSTATE_ABORT       = 4,
+    OPSTATE_CANCELLED   = 5,
   };
 
-  RGWObjZoneCopyState(RGWRados *_store);
+  RGWOpState(RGWRados *_store);
 
-  int set_state(const string& client_id, const string& op_id, const string& object, CopyState state);
-  int renew_state(const string& client_id, const string& op_id, const string& object, CopyState state);
+  int state_from_str(const string& s, OpState *state);
+  int set_state(const string& client_id, const string& op_id, const string& object, OpState state);
+  int renew_state(const string& client_id, const string& op_id, const string& object, OpState state);
 };
 
 class RGWRados