diff options
author | Mykola Golub <mgolub@suse.com> | 2020-07-20 14:14:47 +0200 |
---|---|---|
committer | Mykola Golub <mgolub@suse.com> | 2020-07-23 16:54:18 +0200 |
commit | 955a185f410152c87c52377153c397e845edbf1d (patch) | |
tree | d153b3d44e8f4301350365a4b25c218814de5d72 /src/tools/immutable_object_cache | |
parent | librbd: handle DNE from immutable-object-cache (diff) | |
download | ceph-955a185f410152c87c52377153c397e845edbf1d.tar.xz ceph-955a185f410152c87c52377153c397e845edbf1d.zip |
ceph-immutable-object-cache: don't return empty path for older clients
They would crash. Now they will try to read a non-existing file.
Signed-off-by: Mykola Golub <mgolub@suse.com>
Diffstat (limited to 'src/tools/immutable_object_cache')
-rw-r--r-- | src/tools/immutable_object_cache/CacheClient.cc | 4 | ||||
-rw-r--r-- | src/tools/immutable_object_cache/CacheController.cc | 7 | ||||
-rw-r--r-- | src/tools/immutable_object_cache/CacheSession.cc | 8 | ||||
-rw-r--r-- | src/tools/immutable_object_cache/CacheSession.h | 5 | ||||
-rw-r--r-- | src/tools/immutable_object_cache/ObjectCacheStore.cc | 5 | ||||
-rw-r--r-- | src/tools/immutable_object_cache/ObjectCacheStore.h | 1 | ||||
-rw-r--r-- | src/tools/immutable_object_cache/Types.cc | 16 | ||||
-rw-r--r-- | src/tools/immutable_object_cache/Types.h | 4 |
8 files changed, 45 insertions, 5 deletions
diff --git a/src/tools/immutable_object_cache/CacheClient.cc b/src/tools/immutable_object_cache/CacheClient.cc index bbacf5e208f..e31713cd507 100644 --- a/src/tools/immutable_object_cache/CacheClient.cc +++ b/src/tools/immutable_object_cache/CacheClient.cc @@ -4,6 +4,7 @@ #include <boost/bind/bind.hpp> #include "CacheClient.h" #include "common/Cond.h" +#include "common/version.h" #define dout_context g_ceph_context #define dout_subsys ceph_subsys_immutable_obj_cache @@ -378,7 +379,8 @@ namespace immutable_obj_cache { // TODO : re-implement this method int CacheClient::register_client(Context* on_finish) { ObjectCacheRequest* reg_req = new ObjectCacheRegData(RBDSC_REGISTER, - m_sequence_id++); + m_sequence_id++, + ceph_version_to_str()); reg_req->encode(); bufferlist bl; diff --git a/src/tools/immutable_object_cache/CacheController.cc b/src/tools/immutable_object_cache/CacheController.cc index c033ca49b61..1fade8f84b4 100644 --- a/src/tools/immutable_object_cache/CacheController.cc +++ b/src/tools/immutable_object_cache/CacheController.cc @@ -102,6 +102,9 @@ void CacheController::handle_request(CacheSession* session, case RBDSC_REGISTER: { // TODO(dehao): skip register and allow clients to lookup directly + auto req_reg_data = reinterpret_cast <ObjectCacheRegData*> (req); + session->set_client_version(req_reg_data->version); + ObjectCacheRequest* reply = new ObjectCacheRegReplyData( RBDSC_REGISTER_REPLY, req->seq); session->send(reply); @@ -112,9 +115,11 @@ void CacheController::handle_request(CacheSession* session, std::string cache_path; ObjectCacheReadData* req_read_data = reinterpret_cast <ObjectCacheReadData*> (req); + bool return_dne_path = session->client_version().empty(); int ret = m_object_cache_store->lookup_object( req_read_data->pool_namespace, req_read_data->pool_id, - req_read_data->snap_id, req_read_data->oid, cache_path); + req_read_data->snap_id, req_read_data->oid, return_dne_path, + cache_path); ObjectCacheRequest* reply = nullptr; if (ret != OBJ_CACHE_PROMOTED && ret != OBJ_CACHE_DNE) { reply = new ObjectCacheReadRadosData(RBDSC_READ_RADOS, req->seq); diff --git a/src/tools/immutable_object_cache/CacheSession.cc b/src/tools/immutable_object_cache/CacheSession.cc index 6d8daf05be1..38c38c97d44 100644 --- a/src/tools/immutable_object_cache/CacheSession.cc +++ b/src/tools/immutable_object_cache/CacheSession.cc @@ -32,6 +32,14 @@ stream_protocol::socket& CacheSession::socket() { return m_dm_socket; } +void CacheSession::set_client_version(const std::string &version) { + m_client_version = version; +} + +const std::string &CacheSession::client_version() const { + return m_client_version; +} + void CacheSession::close() { if (m_dm_socket.is_open()) { boost::system::error_code close_ec; diff --git a/src/tools/immutable_object_cache/CacheSession.h b/src/tools/immutable_object_cache/CacheSession.h index 3cc4d9ed800..0826e8a2b9a 100644 --- a/src/tools/immutable_object_cache/CacheSession.h +++ b/src/tools/immutable_object_cache/CacheSession.h @@ -35,11 +35,16 @@ class CacheSession : public std::enable_shared_from_this<CacheSession> { void fault(const boost::system::error_code& ec); void send(ObjectCacheRequest* msg); + void set_client_version(const std::string &version); + const std::string &client_version() const; + private: stream_protocol::socket m_dm_socket; ProcessMsg m_server_process_msg; CephContext* m_cct; + std::string m_client_version; + bufferptr m_bp_header; }; diff --git a/src/tools/immutable_object_cache/ObjectCacheStore.cc b/src/tools/immutable_object_cache/ObjectCacheStore.cc index aec72f3aa50..a0b2b27ce16 100644 --- a/src/tools/immutable_object_cache/ObjectCacheStore.cc +++ b/src/tools/immutable_object_cache/ObjectCacheStore.cc @@ -181,6 +181,7 @@ int ObjectCacheStore::handle_promote_callback(int ret, bufferlist* read_buf, int ObjectCacheStore::lookup_object(std::string pool_nspace, uint64_t pool_id, uint64_t snap_id, std::string object_name, + bool return_dne_path, std::string& target_cache_file_path) { ldout(m_cct, 20) << "object name = " << object_name << " in pool ID : " << pool_id << dendl; @@ -202,6 +203,10 @@ int ObjectCacheStore::lookup_object(std::string pool_nspace, target_cache_file_path = get_cache_file_path(cache_file_name); return ret; case OBJ_CACHE_DNE: + if (return_dne_path) { + target_cache_file_path = get_cache_file_path(cache_file_name); + } + return ret; case OBJ_CACHE_SKIP: return ret; default: diff --git a/src/tools/immutable_object_cache/ObjectCacheStore.h b/src/tools/immutable_object_cache/ObjectCacheStore.h index eba003412e0..270a93be452 100644 --- a/src/tools/immutable_object_cache/ObjectCacheStore.h +++ b/src/tools/immutable_object_cache/ObjectCacheStore.h @@ -31,6 +31,7 @@ class ObjectCacheStore { int lookup_object(std::string pool_nspace, uint64_t pool_id, uint64_t snap_id, std::string object_name, + bool return_dne_path, std::string& target_cache_file_path); private: diff --git a/src/tools/immutable_object_cache/Types.cc b/src/tools/immutable_object_cache/Types.cc index a0a4c6352aa..e65e94bee1e 100644 --- a/src/tools/immutable_object_cache/Types.cc +++ b/src/tools/immutable_object_cache/Types.cc @@ -40,12 +40,24 @@ void ObjectCacheRequest::decode(bufferlist& bl) { ObjectCacheRegData::ObjectCacheRegData() {} ObjectCacheRegData::ObjectCacheRegData(uint16_t t, uint64_t s) : ObjectCacheRequest(t, s) {} +ObjectCacheRegData::ObjectCacheRegData(uint16_t t, uint64_t s, + const std::string &version) + : ObjectCacheRequest(t, s), + version(version) { +} ObjectCacheRegData::~ObjectCacheRegData() {} -void ObjectCacheRegData::encode_payload() {} +void ObjectCacheRegData::encode_payload() { + ceph::encode(version, payload); +} -void ObjectCacheRegData::decode_payload(bufferlist::const_iterator i) {} +void ObjectCacheRegData::decode_payload(bufferlist::const_iterator i) { + if (i.end()) { + return; + } + ceph::decode(version, i); +} ObjectCacheRegReplyData::ObjectCacheRegReplyData() {} ObjectCacheRegReplyData::ObjectCacheRegReplyData(uint16_t t, uint64_t s) diff --git a/src/tools/immutable_object_cache/Types.h b/src/tools/immutable_object_cache/Types.h index 7967d16564f..5fab1ec4897 100644 --- a/src/tools/immutable_object_cache/Types.h +++ b/src/tools/immutable_object_cache/Types.h @@ -57,13 +57,15 @@ class ObjectCacheRequest { class ObjectCacheRegData : public ObjectCacheRequest { public: + std::string version; ObjectCacheRegData(); + ObjectCacheRegData(uint16_t t, uint64_t s, const std::string &version); ObjectCacheRegData(uint16_t t, uint64_t s); ~ObjectCacheRegData() override; void encode_payload() override; void decode_payload(bufferlist::const_iterator bl) override; uint16_t get_request_type() override { return RBDSC_REGISTER; } - bool payload_empty() override { return true; } + bool payload_empty() override { return false; } }; class ObjectCacheRegReplyData : public ObjectCacheRequest { |