diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-06-18 23:02:05 -0700 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-06-18 23:02:05 -0700 |
commit | 8b1524be1f403f092af1c0b57e174179336ef6ef (patch) | |
tree | 4038cb04928ca3a91405cc3032d47dba00cf1805 | |
parent | 258edfca9c9360f20cf5c4f10ba4fcd1206c5c38 (diff) | |
download | ceph-8b1524be1f403f092af1c0b57e174179336ef6ef.tar.gz |
rgw: OpState internal api
Add new higher level functions to set, renew, list, and remove
logged operation state.
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r-- | src/common/config_opts.h | 2 | ||||
-rw-r--r-- | src/rgw/rgw_rados.cc | 81 | ||||
-rw-r--r-- | src/rgw/rgw_rados.h | 27 |
3 files changed, 83 insertions, 27 deletions
diff --git a/src/common/config_opts.h b/src/common/config_opts.h index d95724fce8f..b48cfd5db1e 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -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 diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 61f7b3a45ef..7ad84c44617 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -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); diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 544743dccf1..f292f47cb0e 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -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 |