From b96459cc8b1493e9e97aa69690fd684054f0e5b3 Mon Sep 17 00:00:00 2001 From: Xu Peng Date: Sun, 26 May 2019 12:26:06 +0800 Subject: [PATCH] refactor(db): add MetaConsts Former-commit-id: 5db9dfba91c61274a8334e8daba1488fe5bead3e --- cpp/src/db/DBMetaImpl.cpp | 16 +++++----------- cpp/src/db/MetaConsts.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 cpp/src/db/MetaConsts.h diff --git a/cpp/src/db/DBMetaImpl.cpp b/cpp/src/db/DBMetaImpl.cpp index 2b997d1043..d8e4d9bfd9 100644 --- a/cpp/src/db/DBMetaImpl.cpp +++ b/cpp/src/db/DBMetaImpl.cpp @@ -12,9 +12,11 @@ #include #include #include + #include "DBMetaImpl.h" #include "IDGenerator.h" #include "Utils.h" +#include "MetaConsts.h" namespace zilliz { namespace vecwise { @@ -44,16 +46,9 @@ inline auto StoragePrototype(const std::string& path) { } -using ConnectorT = decltype(StoragePrototype("/tmp/dummy.sqlite3")); +using ConnectorT = decltype(StoragePrototype("")); static std::unique_ptr ConnectorPtr; -long GetFileSize(const std::string& filename) -{ - struct stat stat_buf; - int rc = stat(filename.c_str(), &stat_buf); - return rc == 0 ? stat_buf.st_size : -1; -} - std::string DBMetaImpl::GetGroupPath(const std::string& group_id) { return _options.path + "/" + group_id; } @@ -457,7 +452,7 @@ Status DBMetaImpl::archive_files() { auto& criteria = kv.first; auto& limit = kv.second; if (criteria == "days") { - long usecs = 3600*24*limit*1000000UL; + long usecs = limit * D_SEC * US_PS; long now = utils::GetMicroSecTimeStamp(); try { @@ -475,7 +470,6 @@ Status DBMetaImpl::archive_files() { } } if (criteria == "disk") { - size_t G = 1024*1024*1024UL; long sum = 0; size(sum); @@ -595,7 +589,7 @@ Status DBMetaImpl::cleanup_ttl_files(uint16_t seconds) { &GroupFileSchema::rows, &GroupFileSchema::date), where(c(&GroupFileSchema::file_type) == (int)GroupFileSchema::TO_DELETE and - c(&GroupFileSchema::updated_time) > now - 1000000*seconds)); + c(&GroupFileSchema::updated_time) > now - seconds*US_PS)); GroupFilesSchema updated; diff --git a/cpp/src/db/MetaConsts.h b/cpp/src/db/MetaConsts.h new file mode 100644 index 0000000000..e4247510c6 --- /dev/null +++ b/cpp/src/db/MetaConsts.h @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ +#pragma once + +namespace zilliz { +namespace vecwise { +namespace engine { +namespace meta { + +const size_t K = 1024UL; +const size_t M = K*K; +const size_t G = K*M; +const size_t T = K*G; + +const size_t S_PS = 1UL; +const size_t MS_PS = 1000*S_PS; +const size_t US_PS = 1000*MS_PS; +const size_t NS_PS = 1000*US_PS; + +const size_t SECOND = 1UL; +const size_t M_SEC = 60*SECOND; +const size_t H_SEC = 60*M_SEC; +const size_t D_SEC = 24*H_SEC; +const size_t W_SEC = 7*D_SEC; + +} // namespace meta +} // namespace engine +} // namespace vecwise +} // namespace zilliz