]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools: kill ObjectCacheFile in immutable obj cache
authorYuan Zhou <yuan.zhou@intel.com>
Wed, 23 Jan 2019 15:48:44 +0000 (23:48 +0800)
committerYuan Zhou <yuan.zhou@intel.com>
Thu, 21 Mar 2019 16:16:28 +0000 (00:16 +0800)
instead we could use bufferlist::write_file/pread_file to write/read on cache

Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>
src/test/immutable_object_cache/CMakeLists.txt
src/tools/immutable_object_cache/CMakeLists.txt
src/tools/immutable_object_cache/ObjectCacheFile.cc [deleted file]
src/tools/immutable_object_cache/ObjectCacheFile.h [deleted file]
src/tools/immutable_object_cache/ObjectCacheStore.cc
src/tools/immutable_object_cache/ObjectCacheStore.h

index 7733ca2ddd6a68886859410006c6ba3b36e64df2..bd088cdf0dfcb8e7861100147eadc9fff3f66d15 100644 (file)
@@ -2,7 +2,6 @@
 add_executable(unittest_ceph_immutable_obj_cache
   test_main.cc
   test_SimplePolicy.cc
-  test_ObjectCacheFile.cc
   test_DomainSocket.cc
   test_multi_session.cc
   test_object_store.cc
index 74362c9a27d59a26b6d370a10aa1135e73833bcf..f4c165b95a2ca1509aff7285c47d3ded07da4819 100644 (file)
@@ -1,5 +1,4 @@
 set(ceph_immutable_object_cache_files
-  ObjectCacheFile.cc
   ObjectCacheStore.cc
   CacheController.cc
   CacheServer.cc
diff --git a/src/tools/immutable_object_cache/ObjectCacheFile.cc b/src/tools/immutable_object_cache/ObjectCacheFile.cc
deleted file mode 100644 (file)
index 1d7f0be..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-
-#include "ObjectCacheFile.h"
-#include "include/Context.h"
-#include "common/dout.h"
-#include "common/WorkQueue.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <aio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <utility>
-
-#define dout_subsys ceph_subsys_immutable_obj_cache
-#undef dout_prefix
-#define dout_prefix *_dout << "ceph::cache::ObjectCacheFile: " << this << " " \
-                           <<  __func__ << ": "
-
-namespace ceph {
-namespace immutable_obj_cache {
-
-ObjectCacheFile::ObjectCacheFile(CephContext *cct, const std::string &name)
-  : cct(cct), m_fd(-1) {
-  m_name = cct->_conf.get_val<std::string>("immutable_object_cache_path") + "/ceph_immutable_obj_cache/" + name;
-  ldout(cct, 20) << "file path=" << m_name << dendl;
-}
-
-ObjectCacheFile::~ObjectCacheFile() {
-  // TODO force proper cleanup
-}
-
-void ObjectCacheFile::read(uint64_t offset, uint64_t length, ceph::bufferlist *bl, Context *on_finish) {
-  on_finish->complete(read_object_from_file(bl, offset, length));
-}
-
-void ObjectCacheFile::write(uint64_t offset, ceph::bufferlist &&bl, bool fdatasync, Context *on_finish) {
-  on_finish->complete(write_object_to_file(bl, bl.length()));
-}
-
-int ObjectCacheFile::write_object_to_file(ceph::bufferlist read_buf, uint64_t object_len) {
-  ldout(cct, 20) << "cache file name:" << m_name
-                 << ", length:" << object_len <<  dendl;
-
-  int ret = read_buf.write_file(m_name.c_str()); 
-  if(ret < 0) {
-    lderr(cct)<<"write file fail:" << std::strerror(errno) << dendl;
-    return ret;
-  } 
-
-  return object_len;
-}
-
-int ObjectCacheFile::read_object_from_file(ceph::bufferlist* read_buf, uint64_t object_off, uint64_t object_len) {
-
-  ldout(cct, 20) << "offset:" << object_off
-                 << ", length:" << object_len << dendl;
-
-  std::string error_str;
-
-  int ret = read_buf->pread_file(m_name.c_str(), object_off, object_len, &error_str);
-  if (ret < 0) {
-    lderr(cct)<<"read file fail:" << error_str << dendl;
-    return -1;
-  }
-
-  return read_buf->length();
-}
-
-int ObjectCacheFile::get_file_size() {
-  struct stat buf;
-  int temp_fd = ::open(m_name.c_str(), O_RDONLY);
-  if(temp_fd < 0) {
-    lderr(cct)<<"get_file_size fail: open file is fails." << std::strerror(errno) << dendl;
-    return -1;
-  }
-
-  int ret = fstat(temp_fd, &buf);
-  if(ret == -1) {
-    lderr(cct)<<"fstat fail:" << std::strerror(errno) << dendl;
-    return -1;
-  }
-
-  ret = buf.st_size; 
-  ::close(temp_fd);
-  return ret;
-}
-
-} // namespace immutable_obj_cache
-} // namespace cache
diff --git a/src/tools/immutable_object_cache/ObjectCacheFile.h b/src/tools/immutable_object_cache/ObjectCacheFile.h
deleted file mode 100644 (file)
index 6357a1f..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-
-#ifndef CEPH_CACHE_OBJECT_CACHE_FILE_H
-#define CEPH_CACHE_OBJECT_CACHE_FILE_H
-
-#include "include/Context.h"
-#include "include/buffer_fwd.h"
-#include "common/ceph_context.h"
-#include <string>
-
-
-namespace ceph {
-namespace immutable_obj_cache {
-
-class ObjectCacheFile {
-public:
-  ObjectCacheFile(CephContext *cct, const std::string &name);
-  ~ObjectCacheFile();
-
-  // TODO use IO queue instead of individual commands so operations can be
-  // submitted in batch
-
-  // TODO use scatter/gather API
-
-  void read(uint64_t offset, uint64_t length, ceph::bufferlist *bl, Context *on_finish);
-
-  void write(uint64_t offset, ceph::bufferlist &&bl, bool fdatasync, Context *on_finish);
-
-  int write_object_to_file(ceph::bufferlist read_buf, uint64_t object_len);
-  int read_object_from_file(ceph::bufferlist* read_buf, uint64_t object_off, uint64_t object_len);
-  int get_file_size();
-
-private:
-  CephContext *cct;
-  std::string m_name;
-  int m_fd;
-};
-
-} // namespace immutable_obj_cache
-} // namespace cache
-
-#endif // CEPH_CACHE_OBJECT_CACHE_FILE_H
index e50c1da948061979a0e2e60c95ab03629577cc73..60f0917f8975159e31b3baf00b9ec38efd27779f 100644 (file)
@@ -149,9 +149,9 @@ int ObjectCacheStore::handle_promote_callback(int ret, bufferlist* read_buf,
     cache_dir = "/" + std::to_string(stoul(cache_file_name.substr(pos+1)) % m_dir_num);
   }
   // write to cache
-  ObjectCacheFile cache_file(m_cct, cache_dir + "/" + cache_file_name);
+  std::string cache_file_path = cache_dir + "/" + cache_file_name;
 
-  ret = cache_file.write_object_to_file(*read_buf, file_size);
+  ret = read_buf->write_file(cache_file_path.c_str());
   if (ret < 0) {
     lderr(m_cct) << "fail to write cache file" << dendl;
 
index f3b14289694e4144e8c3087b4aa80a1ba0aea987..908c69b08597887a06baa922a0edbd8723d7a07d 100644 (file)
@@ -8,13 +8,12 @@
 #include "common/Mutex.h"
 #include "include/rados/librados.hpp"
 
-#include "ObjectCacheFile.h"
 #include "SimplePolicy.h"
 
 
 using librados::Rados;
 using librados::IoCtx;
-class ContextWQ;
+class Context;
 
 namespace ceph {
 namespace immutable_obj_cache {
@@ -50,7 +49,6 @@ class ObjectCacheStore
     RadosRef m_rados;
     std::map<uint64_t, librados::IoCtx*> m_ioctxs;
     Mutex m_ioctxs_lock;
-    ObjectCacheFile *m_cache_file;
     Policy* m_policy;
     //TODO(): make this configurable
     int m_dir_num = 10;