From: Mykola Golub Date: Fri, 17 Jul 2020 10:32:22 +0000 (+0100) Subject: ceph-immutable-object-cache: handle DNE objects X-Git-Tag: v15.2.9~122^2~92^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=20355f1f42cace2d484ca858427b5b377cfb81b4;p=ceph.git ceph-immutable-object-cache: handle DNE objects (returning the empty path in the request) Signed-off-by: Mykola Golub (cherry picked from commit 6f6fd9983109d5ce399efd268477a8f443a5a6fd) --- diff --git a/src/tools/immutable_object_cache/CacheController.cc b/src/tools/immutable_object_cache/CacheController.cc index b8f53d3f8a0..c033ca49b61 100644 --- a/src/tools/immutable_object_cache/CacheController.cc +++ b/src/tools/immutable_object_cache/CacheController.cc @@ -116,7 +116,7 @@ void CacheController::handle_request(CacheSession* session, req_read_data->pool_namespace, req_read_data->pool_id, req_read_data->snap_id, req_read_data->oid, cache_path); ObjectCacheRequest* reply = nullptr; - if (ret != OBJ_CACHE_PROMOTED) { + if (ret != OBJ_CACHE_PROMOTED && ret != OBJ_CACHE_DNE) { reply = new ObjectCacheReadRadosData(RBDSC_READ_RADOS, req->seq); } else { reply = new ObjectCacheReadReplyData(RBDSC_READ_REPLY, diff --git a/src/tools/immutable_object_cache/ObjectCacheStore.cc b/src/tools/immutable_object_cache/ObjectCacheStore.cc index ece4127df85..aec72f3aa50 100644 --- a/src/tools/immutable_object_cache/ObjectCacheStore.cc +++ b/src/tools/immutable_object_cache/ObjectCacheStore.cc @@ -142,33 +142,34 @@ int ObjectCacheStore::handle_promote_callback(int ret, bufferlist* read_buf, return ret; } + auto state = OBJ_CACHE_PROMOTED; if (ret == -ENOENT) { // object is empty + state = OBJ_CACHE_DNE; ret = 0; - } + } else { + std::string cache_file_path = get_cache_file_path(cache_file_name, true); + if (cache_file_path == "") { + lderr(m_cct) << "fail to write cache file" << dendl; + m_policy->update_status(cache_file_name, OBJ_CACHE_NONE); + delete read_buf; + return -ENOSPC; + } - std::string cache_file_path = get_cache_file_path(cache_file_name, true); + ret = read_buf->write_file(cache_file_path.c_str()); + if (ret < 0) { + lderr(m_cct) << "fail to write cache file" << dendl; - if (cache_file_path == "") { - lderr(m_cct) << "fail to write cache file" << dendl; - m_policy->update_status(cache_file_name, OBJ_CACHE_NONE); - delete read_buf; - return -ENOSPC; - } - - ret = read_buf->write_file(cache_file_path.c_str()); - if (ret < 0) { - lderr(m_cct) << "fail to write cache file" << dendl; - - m_policy->update_status(cache_file_name, OBJ_CACHE_NONE); - delete read_buf; - return ret; + m_policy->update_status(cache_file_name, OBJ_CACHE_NONE); + delete read_buf; + return ret; + } } // update metadata ceph_assert(OBJ_CACHE_SKIP == m_policy->get_status(cache_file_name)); - m_policy->update_status(cache_file_name, OBJ_CACHE_PROMOTED, read_buf->length()); - ceph_assert(OBJ_CACHE_PROMOTED == m_policy->get_status(cache_file_name)); + m_policy->update_status(cache_file_name, state, read_buf->length()); + ceph_assert(state == m_policy->get_status(cache_file_name)); delete read_buf; @@ -200,6 +201,7 @@ int ObjectCacheStore::lookup_object(std::string pool_nspace, case OBJ_CACHE_PROMOTED: target_cache_file_path = get_cache_file_path(cache_file_name); return ret; + case OBJ_CACHE_DNE: case OBJ_CACHE_SKIP: return ret; default: diff --git a/src/tools/immutable_object_cache/Policy.h b/src/tools/immutable_object_cache/Policy.h index 3e3a0ef8787..7924a8919de 100644 --- a/src/tools/immutable_object_cache/Policy.h +++ b/src/tools/immutable_object_cache/Policy.h @@ -14,6 +14,7 @@ typedef enum { OBJ_CACHE_NONE = 0, OBJ_CACHE_PROMOTED, OBJ_CACHE_SKIP, + OBJ_CACHE_DNE, } cache_status_t; class Policy { diff --git a/src/tools/immutable_object_cache/SimplePolicy.cc b/src/tools/immutable_object_cache/SimplePolicy.cc index b24ec7d675f..7dbd9d34bd9 100644 --- a/src/tools/immutable_object_cache/SimplePolicy.cc +++ b/src/tools/immutable_object_cache/SimplePolicy.cc @@ -74,7 +74,7 @@ cache_status_t SimplePolicy::lookup_object(std::string file_name) { Entry* entry = entry_it->second; - if (entry->status == OBJ_CACHE_PROMOTED) { + if (entry->status == OBJ_CACHE_PROMOTED || entry->status == OBJ_CACHE_DNE) { // bump pos in lru on hit m_promoted_lru.lru_touch(entry); } @@ -106,7 +106,8 @@ void SimplePolicy::update_status(std::string file_name, } // promoting done - if (entry->status == OBJ_CACHE_SKIP && new_status== OBJ_CACHE_PROMOTED) { + if (entry->status == OBJ_CACHE_SKIP && (new_status== OBJ_CACHE_PROMOTED || + new_status== OBJ_CACHE_DNE)) { m_promoted_lru.lru_insert_top(entry); entry->status = new_status; entry->size = size; @@ -128,7 +129,8 @@ void SimplePolicy::update_status(std::string file_name, } // to evict - if (entry->status == OBJ_CACHE_PROMOTED && new_status== OBJ_CACHE_NONE) { + if ((entry->status == OBJ_CACHE_PROMOTED || entry->status == OBJ_CACHE_DNE) && + new_status== OBJ_CACHE_NONE) { // mark this entry as free uint64_t size = entry->size; entry->file_name = ""; diff --git a/src/tools/immutable_object_cache/main.cc b/src/tools/immutable_object_cache/main.cc index 29977f461f5..55b0d087af7 100644 --- a/src/tools/immutable_object_cache/main.cc +++ b/src/tools/immutable_object_cache/main.cc @@ -14,7 +14,7 @@ ceph::immutable_obj_cache::CacheController *cachectl = nullptr; void usage() { - std::cout << "usage: cache controller [options...]" << std::endl; + std::cout << "usage: ceph-immutable-object-cache [options...]" << std::endl; std::cout << "options:\n"; std::cout << " -m monaddress[:port] connect to specified monitor\n"; std::cout << " --keyring= path to keyring for local "