diff --git a/cpp/src/db/DBMetaImpl.cpp b/cpp/src/db/DBMetaImpl.cpp index 2d11379d1a..ef46abbab0 100644 --- a/cpp/src/db/DBMetaImpl.cpp +++ b/cpp/src/db/DBMetaImpl.cpp @@ -1,5 +1,4 @@ /******************************************************************************* - * long rows = 3*1024*1024*1024; * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved * Unauthorized copying of this file, via any medium is strictly prohibited. * Proprietary and confidential. @@ -15,6 +14,7 @@ #include #include "DBMetaImpl.h" #include "IDGenerator.h" +#include "Utils.h" namespace zilliz { namespace vecwise { @@ -56,14 +56,6 @@ std::string DBMetaImpl::GetGroupPath(const std::string& group_id) { return _options.path + "/" + group_id; } -long DBMetaImpl::GetMicroSecTimeStamp() { - auto now = std::chrono::system_clock::now(); - auto micros = std::chrono::duration_cast( - now.time_since_epoch()).count(); - - return micros; -} - std::string DBMetaImpl::GetGroupDatePartitionPath(const std::string& group_id, DateT& date) { std::stringstream ss; ss << GetGroupPath(group_id) << "/" << date; @@ -152,7 +144,7 @@ Status DBMetaImpl::add_group(GroupSchema& group_info) { } group_info.files_cnt = 0; group_info.id = -1; - group_info.created_on = GetMicroSecTimeStamp(); + group_info.created_on = utils::GetMicroSecTimeStamp(); { try { @@ -239,7 +231,7 @@ Status DBMetaImpl::add_group_file(GroupFileSchema& group_file) { group_file.file_id = ss.str(); group_file.dimension = group_info.dimension; group_file.rows = 0; - group_file.created_on = GetMicroSecTimeStamp(); + group_file.created_on = utils::GetMicroSecTimeStamp(); group_file.updated_time = group_file.created_on; GetGroupFilePath(group_file); @@ -464,7 +456,7 @@ Status DBMetaImpl::archive_files() { auto& limit = kv.second; if (criteria == "days") { auto usecs = 3600*24*limit*1000000; - auto now = GetMicroSecTimeStamp(); + auto now = utils::GetMicroSecTimeStamp(); try { ConnectorPtr->update_all( @@ -546,7 +538,7 @@ Status DBMetaImpl::discard_files_of_size(long to_discard_size) { } Status DBMetaImpl::update_group_file(GroupFileSchema& group_file) { - group_file.updated_time = GetMicroSecTimeStamp(); + group_file.updated_time = utils::GetMicroSecTimeStamp(); try { ConnectorPtr->update(group_file); } catch (std::exception & e) { @@ -561,7 +553,7 @@ Status DBMetaImpl::update_files(GroupFilesSchema& files) { try { auto commited = ConnectorPtr->transaction([&] () mutable { for (auto& file : files) { - file.updated_time = GetMicroSecTimeStamp(); + file.updated_time = utils::GetMicroSecTimeStamp(); ConnectorPtr->update(file); } return true; @@ -577,7 +569,7 @@ Status DBMetaImpl::update_files(GroupFilesSchema& files) { } Status DBMetaImpl::cleanup_ttl_files(uint16_t seconds) { - auto now = GetMicroSecTimeStamp(); + auto now = utils::GetMicroSecTimeStamp(); try { auto selected = ConnectorPtr->select(columns(&GroupFileSchema::id, &GroupFileSchema::group_id, diff --git a/cpp/src/db/DBMetaImpl.h b/cpp/src/db/DBMetaImpl.h index e2fd051b42..6433361d7a 100644 --- a/cpp/src/db/DBMetaImpl.h +++ b/cpp/src/db/DBMetaImpl.h @@ -65,7 +65,6 @@ public: private: Status discard_files_of_size(long to_discard_size); - long GetMicroSecTimeStamp(); Status get_group_no_lock(GroupSchema& group_info); std::string GetGroupPath(const std::string& group_id); std::string GetGroupDatePartitionPath(const std::string& group_id, DateT& date); diff --git a/cpp/src/db/Utils.cpp b/cpp/src/db/Utils.cpp new file mode 100644 index 0000000000..e459bab4bb --- /dev/null +++ b/cpp/src/db/Utils.cpp @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ + +#include +#include "Utils.h" + +namespace zilliz { +namespace vecwise { +namespace engine { +namespace utils { + +long GetMicroSecTimeStamp() { + auto now = std::chrono::system_clock::now(); + auto micros = std::chrono::duration_cast( + now.time_since_epoch()).count(); + + return micros; +} + +} // namespace utils +} // namespace engine +} // namespace vecwise +} // namespace zilliz diff --git a/cpp/src/db/Utils.h b/cpp/src/db/Utils.h new file mode 100644 index 0000000000..cdcd37b832 --- /dev/null +++ b/cpp/src/db/Utils.h @@ -0,0 +1,19 @@ +/******************************************************************************* + * 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 utils { + +long GetMicroSecTimeStamp(); + +} // namespace utils +} // namespace engine +} // namespace vecwise +} // namespace zilliz