]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: meta handler provides shard id info of meta key
authorYehuda Sadeh <yehuda@redhat.com>
Tue, 18 Jun 2019 03:48:34 +0000 (20:48 -0700)
committerCasey Bodley <cbodley@redhat.com>
Mon, 29 Jul 2019 19:20:49 +0000 (15:20 -0400)
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 <yehuda@redhat.com>
src/rgw/rgw_mdlog.h
src/rgw/rgw_metadata.cc
src/rgw/rgw_metadata.h
src/rgw/rgw_sync.cc
src/rgw/services/svc_mdlog.cc
src/rgw/services/svc_mdlog.h
src/rgw/services/svc_meta_be.h
src/rgw/services/svc_meta_be_sobj.cc
src/rgw/services/svc_meta_be_sobj.h

index ac04ccb6a7cb9965e2edc686d7ada13325daa48e..cf176548764f26be9c35b4e600267efd42ba110f 100644 (file)
@@ -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<cls_log_entry>& entries, int shard_id, librados::AioCompletion *completion);
 
   struct LogListCtx {
index 450de3c40929843fb1fd043365acce7333a9bd44..d3f0324bdaa05baf73fab2ebcab8e577c0dedc39 100644 (file)
@@ -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<cls_log_entry>& 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<RGWSI_MetaBackend_Handler::Op> 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;
index 504906309aae643bcd4b7d0ba159baa5ba023a82..f65f3ca810559ff37e0741de6b26f26158cb54f9 100644 (file)
@@ -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<string>& keys, bool *truncated) override;
   void list_keys_complete(void *handle) override;
@@ -224,6 +230,8 @@ public:
   void get_sections(list<string>& 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
index efd7b23a3a91dcce3c6651567b96f2306f36cc63..0270a0aecef3ffee9a2c22b63cef8c57ba439245 100644 (file)
@@ -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;
index d44baf81fc63b16de87c28b2bcb6ff5ca855ac9b..b03135345056365d80e98e417d9de0dd1a98ae76 100644 (file)
@@ -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);
index 3fa65130bb81214e34e42d1abccac4abc4628928..7649233e7a09127f83dadac3f24227e729702859 100644 (file)
@@ -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();
   }
index f858c1e6ed41b68bb7ea23b9470d6f74c38fa500..0cc1eb6e902ac80919f148b88b8da95edaf2f68a 100644 (file)
@@ -149,6 +149,10 @@ public:
 
   virtual int call(std::function<int(RGWSI_MetaBackend::Context *)> 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 {
index 2638190e4a813c2b7bd27b2d556740bde6fda712..9fc448884908f14d7ebb396db5002adabb91e76a 100644 (file)
@@ -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<Context_SObj *>(_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<int(RGWSI_MetaBackend::Context *)> f)
 {
   RGWSI_MetaBackend_SObj::Context_SObj ctx(sysobj_svc);
index 03e604f41a7365210a14853bb05a307dcef487cf..95628722dfb1f1ca54357314c8928ab8adb79d96 100644 (file)
@@ -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<int(RGWSI_MetaBackend::Context *)> f) override;
 };