diff options
author | shangdehao1 <dehao.shang@intel.com> | 2019-03-07 19:35:15 +0100 |
---|---|---|
committer | Yuan Zhou <yuan.zhou@intel.com> | 2019-03-21 17:16:31 +0100 |
commit | 0aabf138c09e8871c2b193c30ef693fdef2b6721 (patch) | |
tree | 6dc9b3f33adfd4d5f7fe41acd7260f638c3a9ae4 /src/tools/immutable_object_cache | |
parent | tools: make cache file dir number configurable (diff) | |
download | ceph-0aabf138c09e8871c2b193c30ef693fdef2b6721.tar.xz ceph-0aabf138c09e8871c2b193c30ef693fdef2b6721.zip |
tools: eliminate session_map race between CacheSession
Signed-off-by: Dehao Shang <dehao.shang@intel.com>
Diffstat (limited to 'src/tools/immutable_object_cache')
6 files changed, 8 insertions, 20 deletions
diff --git a/src/tools/immutable_object_cache/CacheController.cc b/src/tools/immutable_object_cache/CacheController.cc index 4fc2dce910c..4e406bd54c0 100644 --- a/src/tools/immutable_object_cache/CacheController.cc +++ b/src/tools/immutable_object_cache/CacheController.cc @@ -71,7 +71,7 @@ void CacheController::run() { std::remove(controller_path.c_str()); m_cache_server = new CacheServer(m_cct, controller_path, - ([&](uint64_t p, ObjectCacheRequest* s){handle_request(p, s);})); + ([&](CacheSession* p, ObjectCacheRequest* s){handle_request(p, s);})); int ret = m_cache_server->run(); if (ret != 0) { @@ -82,7 +82,7 @@ void CacheController::run() { } } -void CacheController::handle_request(uint64_t session_id, +void CacheController::handle_request(CacheSession* session, ObjectCacheRequest* req) { ldout(m_cct, 20) << dendl; @@ -92,7 +92,7 @@ void CacheController::handle_request(uint64_t session_id, ObjectCacheRequest* reply = new ObjectCacheRegReplyData( RBDSC_REGISTER_REPLY, req->seq); - m_cache_server->send(session_id, reply); + session->send(reply); break; } case RBDSC_READ: { @@ -109,7 +109,7 @@ void CacheController::handle_request(uint64_t session_id, reply = new ObjectCacheReadReplyData(RBDSC_READ_REPLY, req->seq, cache_path); } - m_cache_server->send(session_id, reply); + session->send(reply); break; } default: diff --git a/src/tools/immutable_object_cache/CacheController.h b/src/tools/immutable_object_cache/CacheController.h index ef8495f767e..6c46b37b207 100644 --- a/src/tools/immutable_object_cache/CacheController.h +++ b/src/tools/immutable_object_cache/CacheController.h @@ -26,6 +26,7 @@ class CacheController { void run(); void handle_request(uint64_t sesstion_id, ObjectCacheRequest* msg); + void handle_request(CacheSession* session, ObjectCacheRequest* msg); private: CacheServer *m_cache_server; diff --git a/src/tools/immutable_object_cache/CacheServer.cc b/src/tools/immutable_object_cache/CacheServer.cc index 0df58d55f50..d6fecb079d4 100644 --- a/src/tools/immutable_object_cache/CacheServer.cc +++ b/src/tools/immutable_object_cache/CacheServer.cc @@ -102,17 +102,5 @@ void CacheServer::handle_accept(CacheSessionPtr new_session, accept(); } -void CacheServer::send(uint64_t session_id, ObjectCacheRequest* msg) { - ldout(cct, 20) << dendl; - - auto it = m_session_map.find(session_id); - if (it != m_session_map.end()) { - it->second->send(msg); - } else { - ldout(cct, 20) << "missing reply session id" << dendl; - ceph_assert(0); - } -} - } // namespace immutable_obj_cache } // namespace ceph diff --git a/src/tools/immutable_object_cache/CacheServer.h b/src/tools/immutable_object_cache/CacheServer.h index 84cdd89e5e1..04566992178 100644 --- a/src/tools/immutable_object_cache/CacheServer.h +++ b/src/tools/immutable_object_cache/CacheServer.h @@ -25,7 +25,6 @@ class CacheServer { int run(); int start_accept(); int stop(); - void send(uint64_t session_id, ObjectCacheRequest* msg); private: void accept(); @@ -39,7 +38,6 @@ class CacheServer { stream_protocol::endpoint m_local_path; stream_protocol::acceptor m_acceptor; uint64_t m_session_id = 1; - // TODO(dehao) : need to lock it. std::map<uint64_t, CacheSessionPtr> m_session_map; }; diff --git a/src/tools/immutable_object_cache/CacheSession.cc b/src/tools/immutable_object_cache/CacheSession.cc index 6069f811259..e567f43a7c6 100644 --- a/src/tools/immutable_object_cache/CacheSession.cc +++ b/src/tools/immutable_object_cache/CacheSession.cc @@ -99,7 +99,7 @@ void CacheSession::handle_request_data(bufferptr bp, uint64_t data_len, void CacheSession::process(ObjectCacheRequest* req) { ldout(cct, 20) << dendl; - m_server_process_msg(m_session_id, req); + m_server_process_msg(this, req); } void CacheSession::send(ObjectCacheRequest* reply) { diff --git a/src/tools/immutable_object_cache/SocketCommon.h b/src/tools/immutable_object_cache/SocketCommon.h index 9cd108ca06d..4bbc2f611e6 100644 --- a/src/tools/immutable_object_cache/SocketCommon.h +++ b/src/tools/immutable_object_cache/SocketCommon.h @@ -20,8 +20,9 @@ static const int ASIO_ERROR_ACCEPT = 0X04; static const int ASIO_ERROR_MSG_INCOMPLETE = 0X05; class ObjectCacheRequest; +class CacheSession; -typedef std::function<void(uint64_t, ObjectCacheRequest*)> ProcessMsg; +typedef std::function<void(CacheSession*, ObjectCacheRequest*)> ProcessMsg; } // namespace immutable_obj_cache } // namespace ceph |