From: Kefu Chai Date: Sun, 7 Jul 2019 04:45:01 +0000 (+0800) Subject: tools/immutable_object_cache: s/Mutex/ceph::mutex/ X-Git-Tag: v15.1.0~1971^2~27 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=42f6597231e1c71848d390d3b1e198044fa09c75;p=ceph-ci.git tools/immutable_object_cache: s/Mutex/ceph::mutex/ Signed-off-by: Kefu Chai --- diff --git a/src/test/immutable_object_cache/test_common.h b/src/test/immutable_object_cache/test_common.h index 9fe944ffd62..9d6fd14c722 100644 --- a/src/test/immutable_object_cache/test_common.h +++ b/src/test/immutable_object_cache/test_common.h @@ -3,8 +3,7 @@ #ifndef CACHE_TEST_COMMON_H #define CACHE_TEST_COMMON_H -#include "common/Mutex.h" -#include "common/Cond.h" +#include class WaitEvent { public: diff --git a/src/tools/immutable_object_cache/CacheClient.cc b/src/tools/immutable_object_cache/CacheClient.cc index b50491ce8dd..9d883c0f7ea 100644 --- a/src/tools/immutable_object_cache/CacheClient.cc +++ b/src/tools/immutable_object_cache/CacheClient.cc @@ -2,6 +2,7 @@ // vim: ts=8 sw=2 smarttab #include "CacheClient.h" +#include "common/Cond.h" #define dout_context g_ceph_context #define dout_subsys ceph_subsys_immutable_obj_cache @@ -16,8 +17,7 @@ namespace immutable_obj_cache { : m_cct(ceph_ctx), m_io_service_work(m_io_service), m_dm_socket(m_io_service), m_ep(stream_protocol::endpoint(file)), m_io_thread(nullptr), m_session_work(false), m_writing(false), - m_reading(false), m_sequence_id(0), - m_lock("ceph::cache::cacheclient::m_lock") { + m_reading(false), m_sequence_id(0) { m_worker_thread_num = m_cct->_conf.get_val( "immutable_object_cache_client_dedicated_thread_num"); @@ -120,7 +120,7 @@ namespace immutable_obj_cache { req->encode(); { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; m_outcoming_bl.append(req->get_payload_bufferlist()); ceph_assert(m_seq_to_req.find(req->seq) == m_seq_to_req.end()); m_seq_to_req[req->seq] = req; @@ -145,7 +145,7 @@ namespace immutable_obj_cache { ldout(m_cct, 20) << dendl; bufferlist bl; { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; bl.swap(m_outcoming_bl); ceph_assert(m_outcoming_bl.length() == 0); } @@ -163,7 +163,7 @@ namespace immutable_obj_cache { ceph_assert(cb == bl.length()); { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; if (m_outcoming_bl.length() == 0) { m_writing.store(false); return; @@ -258,7 +258,7 @@ namespace immutable_obj_cache { process(reply, reply->seq); { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; if (m_seq_to_req.size() == 0 && m_outcoming_bl.length()) { m_reading.store(false); return; @@ -273,7 +273,7 @@ namespace immutable_obj_cache { ldout(m_cct, 20) << dendl; ObjectCacheRequest* current_request = nullptr; { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; ceph_assert(m_seq_to_req.find(seq_id) != m_seq_to_req.end()); current_request = m_seq_to_req[seq_id]; m_seq_to_req.erase(seq_id); @@ -360,7 +360,7 @@ namespace immutable_obj_cache { /* all pending request, which have entered into ASIO, * will be re-dispatched to RADOS.*/ { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; for (auto it : m_seq_to_req) { it.second->type = RBDSC_READ_RADOS; it.second->process_msg->complete(it.second); diff --git a/src/tools/immutable_object_cache/CacheClient.h b/src/tools/immutable_object_cache/CacheClient.h index d437ed0c9a6..3294e56048a 100644 --- a/src/tools/immutable_object_cache/CacheClient.h +++ b/src/tools/immutable_object_cache/CacheClient.h @@ -11,9 +11,8 @@ #include #include "include/ceph_assert.h" +#include "common/ceph_mutex.h" #include "include/Context.h" -#include "common/Cond.h" -#include "common/Mutex.h" #include "Types.h" #include "SocketCommon.h" @@ -74,7 +73,8 @@ class CacheClient { std::atomic m_writing; std::atomic m_reading; std::atomic m_sequence_id; - Mutex m_lock; + ceph::mutex m_lock = + ceph::make_mutex("ceph::cache::cacheclient::m_lock"); std::map m_seq_to_req; bufferlist m_outcoming_bl; bufferptr m_bp_header; diff --git a/src/tools/immutable_object_cache/ObjectCacheStore.cc b/src/tools/immutable_object_cache/ObjectCacheStore.cc index d89935424ef..33f8dc1aded 100644 --- a/src/tools/immutable_object_cache/ObjectCacheStore.cc +++ b/src/tools/immutable_object_cache/ObjectCacheStore.cc @@ -17,8 +17,7 @@ namespace ceph { namespace immutable_obj_cache { ObjectCacheStore::ObjectCacheStore(CephContext *cct) - : m_cct(cct), m_rados(new librados::Rados()), - m_ioctx_map_lock("ceph::cache::ObjectCacheStore::m_ioctx_map_lock") { + : m_cct(cct), m_rados(new librados::Rados()) { m_cache_root_dir = m_cct->_conf.get_val("immutable_object_cache_path"); @@ -103,7 +102,7 @@ int ObjectCacheStore::do_promote(std::string pool_nspace, std::string cache_file_name = get_cache_file_name(pool_nspace, pool_id, snap_id, object_name); librados::IoCtx ioctx; { - Mutex::Locker _locker(m_ioctx_map_lock); + std::lock_guard _locker{m_ioctx_map_lock}; if (m_ioctx_map.find(pool_id) == m_ioctx_map.end()) { ret = m_rados->ioctx_create2(pool_id, ioctx); if (ret < 0) { diff --git a/src/tools/immutable_object_cache/ObjectCacheStore.h b/src/tools/immutable_object_cache/ObjectCacheStore.h index 57aec63c3d0..eba003412e0 100644 --- a/src/tools/immutable_object_cache/ObjectCacheStore.h +++ b/src/tools/immutable_object_cache/ObjectCacheStore.h @@ -5,7 +5,7 @@ #define CEPH_CACHE_OBJECT_CACHE_STORE_H #include "common/ceph_context.h" -#include "common/Mutex.h" +#include "common/ceph_mutex.h" #include "include/rados/librados.hpp" #include "SimplePolicy.h" @@ -50,7 +50,8 @@ class ObjectCacheStore { CephContext *m_cct; RadosRef m_rados; std::map m_ioctx_map; - Mutex m_ioctx_map_lock; + ceph::mutex m_ioctx_map_lock = + ceph::make_mutex("ceph::cache::ObjectCacheStore::m_ioctx_map_lock"); Policy* m_policy; std::string m_cache_root_dir; }; diff --git a/src/tools/immutable_object_cache/SimplePolicy.cc b/src/tools/immutable_object_cache/SimplePolicy.cc index 6b008b17502..b24ec7d675f 100644 --- a/src/tools/immutable_object_cache/SimplePolicy.cc +++ b/src/tools/immutable_object_cache/SimplePolicy.cc @@ -16,8 +16,7 @@ namespace immutable_obj_cache { SimplePolicy::SimplePolicy(CephContext *cct, uint64_t cache_size, uint64_t max_inflight, double watermark) : cct(cct), m_watermark(watermark), m_max_inflight_ops(max_inflight), - m_max_cache_size(cache_size), - m_cache_map_lock("rbd::cache::SimplePolicy::m_cache_map_lock") { + m_max_cache_size(cache_size) { ldout(cct, 20) << "max cache size= " << m_max_cache_size << " ,watermark= " << m_watermark @@ -39,7 +38,7 @@ SimplePolicy::~SimplePolicy() { cache_status_t SimplePolicy::alloc_entry(std::string file_name) { ldout(cct, 20) << "alloc entry for: " << file_name << dendl; - RWLock::WLocker wlocker(m_cache_map_lock); + std::unique_lock wlocker{m_cache_map_lock}; // cache hit when promoting if (m_cache_map.find(file_name) != m_cache_map.end()) { @@ -64,7 +63,7 @@ cache_status_t SimplePolicy::alloc_entry(std::string file_name) { cache_status_t SimplePolicy::lookup_object(std::string file_name) { ldout(cct, 20) << "lookup: " << file_name << dendl; - RWLock::RLocker rlocker(m_cache_map_lock); + std::shared_lock rlocker{m_cache_map_lock}; auto entry_it = m_cache_map.find(file_name); // simply promote on first lookup @@ -88,7 +87,7 @@ void SimplePolicy::update_status(std::string file_name, ldout(cct, 20) << "update status for: " << file_name << " new status = " << new_status << dendl; - RWLock::WLocker locker(m_cache_map_lock); + std::unique_lock locker{m_cache_map_lock}; auto entry_it = m_cache_map.find(file_name); if (entry_it == m_cache_map.end()) { @@ -155,7 +154,7 @@ int SimplePolicy::evict_entry(std::string file_name) { cache_status_t SimplePolicy::get_status(std::string file_name) { ldout(cct, 20) << file_name << dendl; - RWLock::RLocker locker(m_cache_map_lock); + std::shared_lock locker{m_cache_map_lock}; auto entry_it = m_cache_map.find(file_name); if (entry_it == m_cache_map.end()) { return OBJ_CACHE_NONE; @@ -167,7 +166,7 @@ cache_status_t SimplePolicy::get_status(std::string file_name) { void SimplePolicy::get_evict_list(std::list* obj_list) { ldout(cct, 20) << dendl; - RWLock::WLocker locker(m_cache_map_lock); + std::unique_lock locker{m_cache_map_lock}; // check free ratio, pop entries from LRU if ((double)m_cache_size / m_max_cache_size > (1 - m_watermark)) { // TODO(dehao): make this configurable @@ -190,7 +189,7 @@ uint64_t SimplePolicy::get_free_size() { uint64_t SimplePolicy::get_promoting_entry_num() { uint64_t index = 0; - RWLock::RLocker rlocker(m_cache_map_lock); + std::shared_lock rlocker{m_cache_map_lock}; for (auto it : m_cache_map) { if (it.second->status == OBJ_CACHE_SKIP) { index++; diff --git a/src/tools/immutable_object_cache/SimplePolicy.h b/src/tools/immutable_object_cache/SimplePolicy.h index aac96519edf..671cbd51899 100644 --- a/src/tools/immutable_object_cache/SimplePolicy.h +++ b/src/tools/immutable_object_cache/SimplePolicy.h @@ -5,8 +5,7 @@ #define CEPH_CACHE_SIMPLE_POLICY_H #include "common/ceph_context.h" -#include "common/RWLock.h" -#include "common/Mutex.h" +#include "common/ceph_mutex.h" #include "include/lru.h" #include "Policy.h" @@ -56,7 +55,8 @@ class SimplePolicy : public Policy { std::atomic inflight_ops = 0; std::unordered_map m_cache_map; - RWLock m_cache_map_lock; + ceph::shared_mutex m_cache_map_lock = + ceph::make_shared_mutex("rbd::cache::SimplePolicy::m_cache_map_lock"); std::atomic m_cache_size;