diff --git a/cpp/src/db/DBMetaImpl.cpp b/cpp/src/db/DBMetaImpl.cpp index a0a3cdb3cd..194570d13b 100644 --- a/cpp/src/db/DBMetaImpl.cpp +++ b/cpp/src/db/DBMetaImpl.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include "DBMetaImpl.h" @@ -48,6 +49,14 @@ 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; @@ -167,7 +176,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.updated_time = ConnectorPtr->select(datetime("now", "localtime")).front(); + group_file.updated_time = GetMicroSecTimeStamp(); //ConnectorPtr->select(datetime("now", "localtime +1 hour")).front(); GetGroupFilePath(group_file); { @@ -332,7 +341,7 @@ Status DBMetaImpl::get_group_files(const std::string& group_id_, } Status DBMetaImpl::update_group_file(GroupFileSchema& group_file) { - group_file.updated_time = ConnectorPtr->select(datetime("now", "localtime")).front(); + group_file.updated_time = GetMicroSecTimeStamp(); auto commited = ConnectorPtr->transaction([&] () mutable { ConnectorPtr->update(group_file); return true; @@ -346,7 +355,7 @@ Status DBMetaImpl::update_group_file(GroupFileSchema& group_file) { Status DBMetaImpl::update_files(GroupFilesSchema& files) { auto commited = ConnectorPtr->transaction([&] () mutable { for (auto& file : files) { - file.updated_time = ConnectorPtr->select(datetime("now", "localtime")).front(); + file.updated_time = GetMicroSecTimeStamp(); ConnectorPtr->update(file); } return true; diff --git a/cpp/src/db/DBMetaImpl.h b/cpp/src/db/DBMetaImpl.h index 7cfed9d2e6..726ce15bec 100644 --- a/cpp/src/db/DBMetaImpl.h +++ b/cpp/src/db/DBMetaImpl.h @@ -50,6 +50,7 @@ public: private: + 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/Meta.h b/cpp/src/db/Meta.h index ad76ebddd1..c630ab2101 100644 --- a/cpp/src/db/Meta.h +++ b/cpp/src/db/Meta.h @@ -42,7 +42,7 @@ struct GroupFileSchema { DateT date = EmptyDate; uint16_t dimension; std::string location = ""; - std::string updated_time = ""; + long updated_time; }; // GroupFileSchema typedef std::vector GroupFilesSchema;