]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools: fix redudent updates on cache metdata
authorYuan Zhou <yuan.zhou@intel.com>
Wed, 9 Jan 2019 14:36:27 +0000 (22:36 +0800)
committerYuan Zhou <yuan.zhou@intel.com>
Thu, 21 Mar 2019 16:16:26 +0000 (00:16 +0800)
Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>
src/tools/immutable_object_cache/ObjectCacheStore.cc
src/tools/immutable_object_cache/SimplePolicy.cc

index 3b0b19d8deb1b0a7f79231681822f64359cfef70..5a5666dbcbc188ef69d15c17b0cfea9cc3cca933 100644 (file)
@@ -155,9 +155,10 @@ int ObjectCacheStore::handle_promote_callback(int ret, bufferlist* read_buf,
   assert(OBJ_CACHE_PROMOTED == m_policy->get_status(cache_file_name));
 
   delete read_buf;
-  return ret;
 
   evict_objects();
+
+  return ret;
 }
 
 int ObjectCacheStore::lookup_object(std::string pool_name,
@@ -192,11 +193,7 @@ int ObjectCacheStore::promote_object(librados::IoCtx* ioctx,
                                      Context* on_finish) {
   ldout(m_cct, 20) << "object name = " << object_name << dendl;
 
-  auto ctx = new FunctionContext([on_finish](int ret) {
-    on_finish->complete(ret);
-  });
-
-  librados::AioCompletion* read_completion = create_rados_callback(ctx);
+  librados::AioCompletion* read_completion = create_rados_callback(on_finish);
   // issue a zero-sized read req to get full obj
   int ret = ioctx->aio_read(object_name, read_completion, read_buf, 0, 0);
   if(ret < 0) {
@@ -222,6 +219,10 @@ int ObjectCacheStore::do_evict(std::string cache_file) {
 
   //TODO(): need a better way to get file path
 
+  if (cache_file == "") {
+    return 0;
+  }
+
   std::string cache_dir = m_cache_root_dir;
 
    if (m_dir_num > 0) {
@@ -234,6 +235,7 @@ int ObjectCacheStore::do_evict(std::string cache_file) {
   int ret = std::remove(cache_file_path.c_str());
    // evict entry in policy
   if (ret == 0) {
+    m_policy->update_status(cache_file, OBJ_CACHE_SKIP);
     m_policy->evict_entry(cache_file);
   }
 
index 86936b2f3ae6a0b716e4ebe6673a5505fd495648..0131ed013a1f99650442911aea329a04391547f8 100644 (file)
@@ -42,21 +42,24 @@ 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);
+
+  // cache hit when promoting
+  if (m_cache_map.find(file_name) != m_cache_map.end()) {
+    ldout(cct, 20) << "object is under promoting: " << file_name << dendl;
+    return OBJ_CACHE_SKIP;
+  }
   m_free_list_lock.lock();
 
-  //TODO(): make the max inflight ops configurable
-  if (m_free_list.size() && (inflight_ops < 128)) {
+  if (m_free_list.size() && (inflight_ops < m_max_inflight_ops)) {
     Entry* entry = m_free_list.front();
     ceph_assert(entry != nullptr);
     m_free_list.pop_front();
     m_free_list_lock.unlock();
-
-    {
-      RWLock::WLocker wlocker(m_cache_map_lock);
-      m_cache_map[file_name] = entry;
-    }
+    m_cache_map[file_name] = entry;
+    wlocker.unlock();
     update_status(file_name, OBJ_CACHE_SKIP);
-    return OBJ_CACHE_NONE;
+    return OBJ_CACHE_NONE; // start promotion request
   }
 
   m_free_list_lock.unlock();
@@ -70,7 +73,7 @@ cache_status_t SimplePolicy::lookup_object(std::string file_name) {
   RWLock::RLocker rlocker(m_cache_map_lock);
 
   auto entry_it = m_cache_map.find(file_name);
-  // simplely promote on first lookup
+  // simply promote on first lookup
   if (entry_it == m_cache_map.end()) {
       rlocker.unlock();
       return alloc_entry(file_name);