]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add map of period_id -> RGWMetadataLog
authorCasey Bodley <cbodley@redhat.com>
Tue, 2 Feb 2016 17:44:06 +0000 (12:44 -0500)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 18 Feb 2016 22:04:20 +0000 (14:04 -0800)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_metadata.cc
src/rgw/rgw_metadata.h
src/rgw/rgw_rados.cc

index 3340ea49b2bb94bc5be48fe5c3ba063e900f6fdf..0e213003ba05b92bfa66b49e0fdf567a57dce5e0 100644 (file)
@@ -355,7 +355,7 @@ public:
 static RGWMetadataTopHandler md_top_handler;
 
 RGWMetadataManager::RGWMetadataManager(CephContext *_cct, RGWRados *_store)
-  : cct(_cct), store(_store), md_log(nullptr)
+  : cct(_cct), store(_store)
 {
 }
 
@@ -368,17 +368,28 @@ RGWMetadataManager::~RGWMetadataManager()
   }
 
   handlers.clear();
-  delete md_log;
 }
 
 int RGWMetadataManager::init(const std::string& current_period)
 {
-  md_log = new RGWMetadataLog(cct, store, current_period);
+  current_log = get_log(current_period);
   return 0;
 }
 
-int RGWMetadataManager::store_md_log_entries(list<cls_log_entry>& entries, int shard_id, librados::AioCompletion *completion)
+RGWMetadataLog* RGWMetadataManager::get_log(const std::string& period)
 {
+  // construct the period's log in place if it doesn't exist
+  auto insert = md_logs.emplace(std::piecewise_construct,
+                                std::forward_as_tuple(period),
+                                std::forward_as_tuple(cct, store, period));
+  return &insert.first->second;
+}
+
+int RGWMetadataManager::store_md_log_entries(list<cls_log_entry>& entries,
+                                             const std::string& period, int shard_id,
+                                             librados::AioCompletion *completion)
+{
+  auto md_log = get_log(period);
   return md_log->store_entries_in_shard(entries, shard_id, completion);
 }
 
@@ -669,7 +680,8 @@ int RGWMetadataManager::pre_modify(RGWMetadataHandler *handler, string& section,
   bufferlist logbl;
   ::encode(log_data, logbl);
 
-  int ret = md_log->add_entry(handler, section, key, logbl);
+  assert(current_log); // must have called init()
+  int ret = current_log->add_entry(handler, section, key, logbl);
   if (ret < 0)
     return ret;
 
@@ -687,7 +699,8 @@ int RGWMetadataManager::post_modify(RGWMetadataHandler *handler, const string& s
   bufferlist logbl;
   ::encode(log_data, logbl);
 
-  int r = md_log->add_entry(handler, section, key, logbl);
+  assert(current_log); // must have called init()
+  int r = current_log->add_entry(handler, section, key, logbl);
   if (ret < 0)
     return ret;
 
index 89cd9e9097a2825c6ed8a6c2ebd55a4e8d6295f0..5487e53f42b52ae19b70d66eb747e4be24d4df46 100644 (file)
@@ -226,7 +226,11 @@ class RGWMetadataManager {
   map<string, RGWMetadataHandler *> handlers;
   CephContext *cct;
   RGWRados *store;
-  RGWMetadataLog *md_log;
+
+  // maintain a separate metadata log for each period
+  std::map<std::string, RGWMetadataLog> md_logs;
+  // use the current period's log for mutating operations
+  RGWMetadataLog* current_log = nullptr;
 
   void parse_metadata_key(const string& metadata_key, string& type, string& entry);
 
@@ -248,11 +252,15 @@ public:
 
   int init(const std::string& current_period);
 
+  /// find or create the metadata log for the given period
+  RGWMetadataLog* get_log(const std::string& period);
+
   int register_handler(RGWMetadataHandler *handler);
 
   RGWMetadataHandler *get_handler(const string& type);
 
-  int store_md_log_entries(list<cls_log_entry>& entries, int shard_id, librados::AioCompletion *completion);
+  int store_md_log_entries(list<cls_log_entry>& entries, const std::string& period,
+                           int shard_id, librados::AioCompletion *completion);
 
   int put_entry(RGWMetadataHandler *handler, const string& key, bufferlist& bl, bool exclusive,
                 RGWObjVersionTracker *objv_tracker, time_t mtime, map<string, bufferlist> *pattrs = NULL);
@@ -273,16 +281,14 @@ public:
   int lock_exclusive(string& metadata_key, utime_t duration, string& owner_id);
   int unlock(string& metadata_key, string& owner_id);
 
-  RGWMetadataLog *get_log() { return md_log; }
-
-  int get_log_shard_id(const string& section, const string& key, int *shard_id) {
+  int get_log_shard_id(const string& section, const std::string& period,
+                       const string& key, int *shard_id) {
     RGWMetadataHandler *handler = get_handler(section);
     if (!handler) {
       return -EINVAL;
     }
-
+    auto md_log = get_log(period);
     *shard_id = md_log->get_log_shard_id(handler, section, key);
-
     return 0;
   }
 };
index ada249a0783072c2468bb146fcd0c26f23c2e659..7e91027a0c69eb9498015d1c1e620459bfc16ac2 100644 (file)
@@ -1250,7 +1250,7 @@ int RGWPeriod::update_sync_status()
     return -EINVAL;
   }
 
-  auto mdlog = store->meta_mgr->get_log();
+  auto mdlog = store->meta_mgr->get_log(get_id());
   const auto num_shards = cct->_conf->rgw_md_log_max_shards;
 
   std::vector<std::string> markers;
@@ -2819,12 +2819,14 @@ void *RGWRadosThread::Worker::entry() {
 
 class RGWMetaNotifier : public RGWRadosThread {
   RGWMetaNotifierManager notify_mgr;
+  RGWMetadataLog *const log;
 
   uint64_t interval_msec() {
     return cct->_conf->rgw_md_notify_interval_msec;
   }
 public:
-  RGWMetaNotifier(RGWRados *_store) : RGWRadosThread(_store), notify_mgr(_store) {}
+  RGWMetaNotifier(RGWRados *_store, RGWMetadataLog* log)
+    : RGWRadosThread(_store), notify_mgr(_store), log(log) {}
 
   int process();
 };
@@ -2833,8 +2835,6 @@ int RGWMetaNotifier::process()
 {
   set<int> shards;
 
-  RGWMetadataLog *log = store->meta_mgr->get_log();
-
   log->read_clear_modified(shards);
 
   if (shards.empty()) {
@@ -3615,13 +3615,6 @@ int RGWRados::init_complete()
   period_history.reset(new RGWPeriodHistory(cct, period_puller.get(),
                                             current_period));
 
-  ret = meta_mgr->init(current_period.get_id());
-  if (ret < 0) {
-    lderr(cct) << "ERROR: failed to initialize metadata log: "
-        << cpp_strerror(-ret) << dendl;
-    return ret;
-  }
-
   if (need_watch_notify()) {
     ret = init_watch();
     if (ret < 0) {
@@ -3672,7 +3665,15 @@ int RGWRados::init_complete()
     obj_expirer->start_processor();
   }
 
-  meta_notifier = new RGWMetaNotifier(this);
+  ret = meta_mgr->init(current_period.get_id());
+  if (ret < 0) {
+    lderr(cct) << "ERROR: failed to initialize metadata log: "
+        << cpp_strerror(-ret) << dendl;
+    return ret;
+  }
+  auto md_log = meta_mgr->get_log(current_period.get_id());
+
+  meta_notifier = new RGWMetaNotifier(this, md_log);
   if (is_meta_master()) {
     meta_notifier->start();
   }