From 28bb55b083ded3730fe1e5cd62669f90fafc85cd Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 17 Jun 2019 20:48:34 -0700 Subject: [PATCH] rgw: meta handler provides shard id info of meta key In the future we should maybe look into providing this info differently, and without exposing data representation in this layer, but for now it will do. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_mdlog.h | 1 + src/rgw/rgw_metadata.cc | 25 +++++++++++++++++++++++++ src/rgw/rgw_metadata.h | 8 ++++++++ src/rgw/rgw_sync.cc | 2 +- src/rgw/services/svc_mdlog.cc | 6 ++++++ src/rgw/services/svc_mdlog.h | 2 ++ src/rgw/services/svc_meta_be.h | 8 ++++++++ src/rgw/services/svc_meta_be_sobj.cc | 9 +++++++++ src/rgw/services/svc_meta_be_sobj.h | 4 ++++ 9 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_mdlog.h b/src/rgw/rgw_mdlog.h index ac04ccb6a7c..cf176548764 100644 --- a/src/rgw/rgw_mdlog.h +++ b/src/rgw/rgw_mdlog.h @@ -101,6 +101,7 @@ public: } int add_entry(const string& hash_key, const string& section, const string& key, bufferlist& bl); + int get_shard_id(const string& hash_key, int *shard_id); int store_entries_in_shard(list& entries, int shard_id, librados::AioCompletion *completion); struct LogListCtx { diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc index 450de3c4092..d3f0324bdaa 100644 --- a/src/rgw/rgw_metadata.cc +++ b/src/rgw/rgw_metadata.cc @@ -116,6 +116,14 @@ int RGWMetadataLog::add_entry(const string& hash_key, const string& section, con return svc.cls->timelog.add(oid, now, section, key, bl, null_yield); } +int RGWMetadataLog::get_shard_id(const string& hash_key, int *shard_id) +{ + string oid; + + rgw_shard_name(prefix, cct->_conf->rgw_md_log_max_shards, hash_key, oid, shard_id); + return 0; +} + int RGWMetadataLog::store_entries_in_shard(list& entries, int shard_id, librados::AioCompletion *completion) { string oid; @@ -492,6 +500,13 @@ int RGWMetadataHandler_GenericMetaBE::remove(string& entry, RGWObjVersionTracker }); } +int RGWMetadataHandler_GenericMetaBE::get_shard_id(const string& entry, int *shard_id) +{ + return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { + return op->get_shard_id(entry, shard_id); + }); +} + int RGWMetadataHandler_GenericMetaBE::list_keys_init(const string& marker, void **phandle) { std::unique_ptr op(be_handler->alloc_op()); @@ -701,6 +716,16 @@ int RGWMetadataManager::remove(string& metadata_key) return handler->remove(entry, objv_tracker); } +int RGWMetadataManager::get_shard_id(const string& section, const string& entry, int *shard_id) +{ + RGWMetadataHandler *handler = get_handler(section); + if (!handler) { + return -EINVAL; + } + + return handler->get_shard_id(entry, shard_id); +} + struct list_keys_handle { void *handle; RGWMetadataHandler *handler; diff --git a/src/rgw/rgw_metadata.h b/src/rgw/rgw_metadata.h index 504906309aa..f65f3ca8105 100644 --- a/src/rgw/rgw_metadata.h +++ b/src/rgw/rgw_metadata.h @@ -78,6 +78,10 @@ public: virtual string get_marker(void *handle) = 0; + virtual int get_shard_id(const string& entry, int *shard_id) { + *shard_id = 0; + return 0; + } virtual int attach(RGWMetadataManager *manager); }; @@ -150,6 +154,8 @@ public: int put(string& entry, RGWMetadataObject *obj, RGWObjVersionTracker& objv_tracker, RGWMDLogSyncType type) override; int remove(string& entry, RGWObjVersionTracker& objv_tracker) override; + int get_shard_id(const string& entry, int *shard_id) override; + int list_keys_init(const std::string& marker, void **phandle) override; int list_keys_next(void *handle, int max, std::list& keys, bool *truncated) override; void list_keys_complete(void *handle) override; @@ -224,6 +230,8 @@ public: void get_sections(list& sections); void parse_metadata_key(const string& metadata_key, string& type, string& entry); + + int get_shard_id(const string& section, const string& key, int *shard_id); }; class RGWMetadataHandlerPut_SObj : public RGWMetadataHandler_GenericMetaBE::Put diff --git a/src/rgw/rgw_sync.cc b/src/rgw/rgw_sync.cc index efd7b23a3a9..0270a0aecef 100644 --- a/src/rgw/rgw_sync.cc +++ b/src/rgw/rgw_sync.cc @@ -957,7 +957,7 @@ public: string s = *sections_iter + ":" + *iter; int shard_id; RGWRados *store = sync_env->store; - int ret = store->ctl.meta.mgr->get_log_shard_id(*sections_iter, *iter, &shard_id); + int ret = store->ctl.meta.mgr->get_shard_id(*sections_iter, *iter, &shard_id); if (ret < 0) { tn->log(0, SSTR("ERROR: could not determine shard id for " << *sections_iter << ":" << *iter)); ret_status = ret; diff --git a/src/rgw/services/svc_mdlog.cc b/src/rgw/services/svc_mdlog.cc index d44baf81fc6..b0313534505 100644 --- a/src/rgw/services/svc_mdlog.cc +++ b/src/rgw/services/svc_mdlog.cc @@ -373,6 +373,12 @@ int RGWSI_MDLog::add_entry(const string& hash_key, const string& section, const return current_log->add_entry(hash_key, section, key, bl); } +int RGWSI_MDLog::get_shard_id(const string& hash_key, int *shard_id) +{ + ceph_assert(current_log); // must have called init() + return current_log->get_shard_id(hash_key, shard_id); +} + int RGWSI_MDLog::pull_period(const std::string& period_id, RGWPeriod& period) { return period_puller->pull(period_id, period); diff --git a/src/rgw/services/svc_mdlog.h b/src/rgw/services/svc_mdlog.h index 3fa65130bb8..7649233e7a0 100644 --- a/src/rgw/services/svc_mdlog.h +++ b/src/rgw/services/svc_mdlog.h @@ -99,6 +99,8 @@ public: int add_entry(const string& hash_key, const string& section, const string& key, bufferlist& bl); + int get_shard_id(const string& hash_key, int *shard_id); + RGWPeriodHistory *get_period_history() { return period_history.get(); } diff --git a/src/rgw/services/svc_meta_be.h b/src/rgw/services/svc_meta_be.h index f858c1e6ed4..0cc1eb6e902 100644 --- a/src/rgw/services/svc_meta_be.h +++ b/src/rgw/services/svc_meta_be.h @@ -149,6 +149,10 @@ public: virtual int call(std::function f) = 0; + virtual int get_shard_id(RGWSI_MetaBackend::Context *ctx, + const std::string& key, + int *shard_id) = 0; + /* higher level */ virtual int get(Context *ctx, const std::string& key, @@ -215,6 +219,10 @@ public: int list_get_marker(string *marker) { return be->list_get_marker(be_ctx, marker); } + + int get_shard_id(const std::string& key, int *shard_id) { + return be->get_shard_id(be_ctx, key, shard_id); + } }; class Op_ManagedCtx : public Op { diff --git a/src/rgw/services/svc_meta_be_sobj.cc b/src/rgw/services/svc_meta_be_sobj.cc index 2638190e4a8..9fc44888490 100644 --- a/src/rgw/services/svc_meta_be_sobj.cc +++ b/src/rgw/services/svc_meta_be_sobj.cc @@ -85,6 +85,15 @@ int RGWSI_MetaBackend_SObj::post_modify(RGWSI_MetaBackend::Context *_ctx, return RGWSI_MetaBackend::post_modify(ctx, key, log_data, objv_tracker, ret, y); } +int RGWSI_MetaBackend_SObj::get_shard_id(RGWSI_MetaBackend::Context *_ctx, + const std::string& key, + int *shard_id) +{ + auto ctx = static_cast(_ctx); + *shard_id = mdlog_svc->get_shard_id(ctx->module->get_hash_key(key), shard_id); + return 0; +} + int RGWSI_MetaBackend_SObj::call(std::function f) { RGWSI_MetaBackend_SObj::Context_SObj ctx(sysobj_svc); diff --git a/src/rgw/services/svc_meta_be_sobj.h b/src/rgw/services/svc_meta_be_sobj.h index 03e604f41a7..95628722dfb 100644 --- a/src/rgw/services/svc_meta_be_sobj.h +++ b/src/rgw/services/svc_meta_be_sobj.h @@ -164,6 +164,10 @@ public: int list_get_marker(RGWSI_MetaBackend::Context *ctx, string *marker) override; + int get_shard_id(RGWSI_MetaBackend::Context *ctx, + const std::string& key, + int *shard_id) override; + int call(std::function f) override; }; -- 2.39.5