From f5348ed57c86c56dd6efb12caf0bffc5fd9473bf Mon Sep 17 00:00:00 2001 From: Xu Peng Date: Wed, 17 Apr 2019 14:25:27 +0800 Subject: [PATCH] feat(db): file name mock Former-commit-id: e99baa04809535f5f3c10d5b0c007c9c06ab159c --- cpp/src/db/DBImpl.cpp | 15 ++++++++++++--- cpp/src/db/DBMetaImpl.cpp | 9 ++++++--- cpp/src/db/DBMetaImpl.h | 8 ++++++-- cpp/src/db/Meta.h | 7 +++++-- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/cpp/src/db/DBImpl.cpp b/cpp/src/db/DBImpl.cpp index 095795dc..7fc37e67 100644 --- a/cpp/src/db/DBImpl.cpp +++ b/cpp/src/db/DBImpl.cpp @@ -167,7 +167,8 @@ Status DBImpl::background_merge_files(const std::string& group_id) { Status DBImpl::build_index(const meta::GroupFileSchema& file) { meta::GroupFileSchema group_file; - Status status = _pMeta->add_group_file(file.group_id, file.date, group_file); + Status status = _pMeta->add_group_file(file.group_id, file.date, + group_file, meta::GroupFileSchema::INDEX); if (!status.ok()) { return status; } @@ -182,8 +183,16 @@ Status DBImpl::build_index(const meta::GroupFileSchema& file) { from_index->id_map.data()); /* std::cout << "raw size=" << from_index->ntotal << " index size=" << index->ntotal << std::endl; */ // PXU TODO: Remove - auto location = group_file.location + ".index"; - write_index(index, location.c_str()); + /* auto location = group_file.location + ".index"; */ + write_index(index, group_file.location.c_str()); + group_file.file_type = meta::GroupFileSchema::INDEX; + + /* auto to_remove = file; */ + /* to_remove.file_type = TO_DELETE; */ + + /* GroupFilesSchema update_files = {to_remove, group_file}; */ + /* _pMeta->update_files(update_files); */ + return Status::OK(); } diff --git a/cpp/src/db/DBMetaImpl.cpp b/cpp/src/db/DBMetaImpl.cpp index 5ed10f7d..ff4aa75e 100644 --- a/cpp/src/db/DBMetaImpl.cpp +++ b/cpp/src/db/DBMetaImpl.cpp @@ -47,19 +47,22 @@ Status DBMetaImpl::has_group(const std::string& group_id_, bool& has_or_not_) { } Status DBMetaImpl::add_group_file(const std::string& group_id, - GroupFileSchema& group_file_info) { + GroupFileSchema& group_file_info, + GroupFileSchema::FILE_TYPE file_type) { return add_group_file(group_id, Meta::GetDate(), group_file_info); } Status DBMetaImpl::add_group_file(const std::string& group_id, DateT date, - GroupFileSchema& group_file_info) { + GroupFileSchema& group_file_info, + GroupFileSchema::FILE_TYPE file_type) { //PXU TODO std::stringstream ss; SimpleIDGenerator g; + std::string suffix = (file_type == GroupFileSchema::RAW) ? ".raw" : ".index"; ss << "/tmp/test/" << date << "/" << g.getNextIDNumber() - << ".log"; + << suffix; group_file_info.group_id = "1"; group_file_info.dimension = 64; group_file_info.location = ss.str(); diff --git a/cpp/src/db/DBMetaImpl.h b/cpp/src/db/DBMetaImpl.h index ade7ced5..1c11bc8b 100644 --- a/cpp/src/db/DBMetaImpl.h +++ b/cpp/src/db/DBMetaImpl.h @@ -21,9 +21,13 @@ public: virtual Status add_group_file(const std::string& group_id, DateT date, - GroupFileSchema& group_file_info) override; + GroupFileSchema& group_file_info, + GroupFileSchema::FILE_TYPE file_type=GroupFileSchema::RAW) override; + virtual Status add_group_file(const std::string& group_id_, - GroupFileSchema& group_file_info_) override; + GroupFileSchema& group_file_info_, + GroupFileSchema::FILE_TYPE file_type=GroupFileSchema::RAW) override; + virtual Status has_group_file(const std::string& group_id_, const std::string& file_id_, bool& has_or_not_) override; diff --git a/cpp/src/db/Meta.h b/cpp/src/db/Meta.h index 847b31be..3a301596 100644 --- a/cpp/src/db/Meta.h +++ b/cpp/src/db/Meta.h @@ -56,10 +56,13 @@ public: virtual Status has_group(const std::string& group_id_, bool& has_or_not_) = 0; virtual Status add_group_file(const std::string& group_id_, - GroupFileSchema& group_file_info_) = 0; + GroupFileSchema& group_file_info_, + GroupFileSchema::FILE_TYPE file_type=GroupFileSchema::RAW) = 0; virtual Status add_group_file(const std::string& group_id, DateT date, - GroupFileSchema& group_file_info) = 0; + GroupFileSchema& group_file_info, + GroupFileSchema::FILE_TYPE file_type=GroupFileSchema::RAW) = 0; + virtual Status has_group_file(const std::string& group_id_, const std::string& file_id_, bool& has_or_not_) = 0; -- GitLab