From: Casey Bodley Date: Tue, 2 Feb 2016 17:44:06 +0000 (-0500) Subject: rgw: add map of period_id -> RGWMetadataLog X-Git-Tag: v10.1.0~354^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=34ea6bcc852ca0024df7723dda8c0201f08df0c0;p=ceph.git rgw: add map of period_id -> RGWMetadataLog Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc index 3340ea49b2bb..0e213003ba05 100644 --- a/src/rgw/rgw_metadata.cc +++ b/src/rgw/rgw_metadata.cc @@ -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& 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& 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; diff --git a/src/rgw/rgw_metadata.h b/src/rgw/rgw_metadata.h index 89cd9e9097a2..5487e53f42b5 100644 --- a/src/rgw/rgw_metadata.h +++ b/src/rgw/rgw_metadata.h @@ -226,7 +226,11 @@ class RGWMetadataManager { map handlers; CephContext *cct; RGWRados *store; - RGWMetadataLog *md_log; + + // maintain a separate metadata log for each period + std::map 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& entries, int shard_id, librados::AioCompletion *completion); + int store_md_log_entries(list& 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 *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; } }; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index ada249a07830..7e91027a0c69 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -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 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 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(); }