]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-immutable-object-cache: handle DNE objects
authorMykola Golub <mgolub@suse.com>
Fri, 17 Jul 2020 10:32:22 +0000 (11:32 +0100)
committerJason Dillaman <dillaman@redhat.com>
Thu, 27 Aug 2020 17:56:04 +0000 (13:56 -0400)
(returning the empty path in the request)

Signed-off-by: Mykola Golub <mgolub@suse.com>
(cherry picked from commit 6f6fd9983109d5ce399efd268477a8f443a5a6fd)

src/tools/immutable_object_cache/CacheController.cc
src/tools/immutable_object_cache/ObjectCacheStore.cc
src/tools/immutable_object_cache/Policy.h
src/tools/immutable_object_cache/SimplePolicy.cc
src/tools/immutable_object_cache/main.cc

index b8f53d3f8a0f4b484d40d06c1259b7fc2df4f87c..c033ca49b61158e7949b57f5fe8fb5221afc7d6e 100644 (file)
@@ -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,
index ece4127df850b7159290389f2ea30e937438599e..aec72f3aa50a78faaf06dfdfc6ecdf9cfd83f005 100644 (file)
@@ -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:
index 3e3a0ef8787087c73e2079f557672670520b5972..7924a8919de67bd75cba4ed7edf1f04775460632 100644 (file)
@@ -14,6 +14,7 @@ typedef enum {
   OBJ_CACHE_NONE = 0,
   OBJ_CACHE_PROMOTED,
   OBJ_CACHE_SKIP,
+  OBJ_CACHE_DNE,
 } cache_status_t;
 
 class Policy {
index b24ec7d675fa50253e958080af7e2c2e2efcd7a4..7dbd9d34bd9cfbb8a212debdb63505301e60fc3b 100644 (file)
@@ -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 = "";
index 29977f461f5bb631609633bddea6eef3ba115ab6..55b0d087af7c20b474f91f6f032017de8f3bf0e5 100644 (file)
@@ -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>          path to keyring for local "