From: Yuan Zhou Date: Wed, 23 Jan 2019 15:48:44 +0000 (+0800) Subject: tools: kill ObjectCacheFile in immutable obj cache X-Git-Tag: v15.0.0~136^2~31 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7aaa3b6e476f520827e88ed14a9184ec7d3083bc;p=ceph.git tools: kill ObjectCacheFile in immutable obj cache instead we could use bufferlist::write_file/pread_file to write/read on cache Signed-off-by: Yuan Zhou --- diff --git a/src/test/immutable_object_cache/CMakeLists.txt b/src/test/immutable_object_cache/CMakeLists.txt index 7733ca2ddd6..bd088cdf0df 100644 --- a/src/test/immutable_object_cache/CMakeLists.txt +++ b/src/test/immutable_object_cache/CMakeLists.txt @@ -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 diff --git a/src/tools/immutable_object_cache/CMakeLists.txt b/src/tools/immutable_object_cache/CMakeLists.txt index 74362c9a27d..f4c165b95a2 100644 --- a/src/tools/immutable_object_cache/CMakeLists.txt +++ b/src/tools/immutable_object_cache/CMakeLists.txt @@ -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 index 1d7f0be9f9a..00000000000 --- a/src/tools/immutable_object_cache/ObjectCacheFile.cc +++ /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 -#include -#include -#include -#include -#include - -#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("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 index 6357a1f5927..00000000000 --- a/src/tools/immutable_object_cache/ObjectCacheFile.h +++ /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 - - -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 diff --git a/src/tools/immutable_object_cache/ObjectCacheStore.cc b/src/tools/immutable_object_cache/ObjectCacheStore.cc index e50c1da9480..60f0917f897 100644 --- a/src/tools/immutable_object_cache/ObjectCacheStore.cc +++ b/src/tools/immutable_object_cache/ObjectCacheStore.cc @@ -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; diff --git a/src/tools/immutable_object_cache/ObjectCacheStore.h b/src/tools/immutable_object_cache/ObjectCacheStore.h index f3b14289694..908c69b0859 100644 --- a/src/tools/immutable_object_cache/ObjectCacheStore.h +++ b/src/tools/immutable_object_cache/ObjectCacheStore.h @@ -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 m_ioctxs; Mutex m_ioctxs_lock; - ObjectCacheFile *m_cache_file; Policy* m_policy; //TODO(): make this configurable int m_dir_num = 10;