From 874eeb8f7a13c0cca0e6af6040ae9fe7c675f4c0 Mon Sep 17 00:00:00 2001 From: Xu Peng Date: Mon, 27 May 2019 19:10:49 +0800 Subject: [PATCH] refactor(db): FilesToIndex Former-commit-id: fe5bd8ca372d0a4d5bf257f3f10853179d2356ce --- cpp/src/db/DBImpl.cpp | 2 +- cpp/src/db/DBMetaImpl.cpp | 28 ++++++++++++++-------------- cpp/src/db/DBMetaImpl.h | 2 +- cpp/src/db/Meta.h | 2 +- cpp/unittest/db/meta_tests.cpp | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cpp/src/db/DBImpl.cpp b/cpp/src/db/DBImpl.cpp index 057573be..57cd8863 100644 --- a/cpp/src/db/DBImpl.cpp +++ b/cpp/src/db/DBImpl.cpp @@ -360,7 +360,7 @@ void DBImpl::background_build_index() { std::lock_guard lock(build_index_mutex_); assert(bg_build_index_started_); meta::TableFilesSchema to_index_files; - _pMeta->files_to_index(to_index_files); + _pMeta->FilesToIndex(to_index_files); Status status; for (auto& file : to_index_files) { /* LOG(DEBUG) << "Buiding index for " << file.location; */ diff --git a/cpp/src/db/DBMetaImpl.cpp b/cpp/src/db/DBMetaImpl.cpp index 4871d5a5..1993992f 100644 --- a/cpp/src/db/DBMetaImpl.cpp +++ b/cpp/src/db/DBMetaImpl.cpp @@ -259,7 +259,7 @@ Status DBMetaImpl::CreateTableFile(TableFileSchema& file_schema) { return Status::OK(); } -Status DBMetaImpl::files_to_index(TableFilesSchema& files) { +Status DBMetaImpl::FilesToIndex(TableFilesSchema& files) { files.clear(); try { @@ -272,28 +272,28 @@ Status DBMetaImpl::files_to_index(TableFilesSchema& files) { where(c(&TableFileSchema::file_type) == (int)TableFileSchema::TO_INDEX)); std::map groups; + TableFileSchema table_file; for (auto& file : selected) { - TableFileSchema group_file; - group_file.id = std::get<0>(file); - group_file.table_id = std::get<1>(file); - group_file.file_id = std::get<2>(file); - group_file.file_type = std::get<3>(file); - group_file.size = std::get<4>(file); - group_file.date = std::get<5>(file); - GetGroupFilePath(group_file); - auto groupItr = groups.find(group_file.table_id); + table_file.id = std::get<0>(file); + table_file.table_id = std::get<1>(file); + table_file.file_id = std::get<2>(file); + table_file.file_type = std::get<3>(file); + table_file.size = std::get<4>(file); + table_file.date = std::get<5>(file); + GetGroupFilePath(table_file); + auto groupItr = groups.find(table_file.table_id); if (groupItr == groups.end()) { TableSchema table_schema; - table_schema.table_id = group_file.table_id; + table_schema.table_id = table_file.table_id; auto status = DescribeTable(table_schema); if (!status.ok()) { return status; } - groups[group_file.table_id] = table_schema; + groups[table_file.table_id] = table_schema; } - group_file.dimension = groups[group_file.table_id].dimension; - files.push_back(group_file); + table_file.dimension = groups[table_file.table_id].dimension; + files.push_back(table_file); } } catch (std::exception & e) { LOG(DEBUG) << e.what(); diff --git a/cpp/src/db/DBMetaImpl.h b/cpp/src/db/DBMetaImpl.h index 8832c30a..9993ace9 100644 --- a/cpp/src/db/DBMetaImpl.h +++ b/cpp/src/db/DBMetaImpl.h @@ -40,7 +40,7 @@ public: virtual Status FilesToMerge(const std::string& table_id, DatePartionedTableFilesSchema& files) override; - virtual Status files_to_index(TableFilesSchema&) override; + virtual Status FilesToIndex(TableFilesSchema&) override; virtual Status Archive() override; diff --git a/cpp/src/db/Meta.h b/cpp/src/db/Meta.h index 6a0993a9..d5206d65 100644 --- a/cpp/src/db/Meta.h +++ b/cpp/src/db/Meta.h @@ -46,7 +46,7 @@ public: virtual Status Archive() = 0; - virtual Status files_to_index(TableFilesSchema&) = 0; + virtual Status FilesToIndex(TableFilesSchema&) = 0; virtual Status cleanup() = 0; virtual Status cleanup_ttl_files(uint16_t) = 0; diff --git a/cpp/unittest/db/meta_tests.cpp b/cpp/unittest/db/meta_tests.cpp index 8051d2eb..1e849812 100644 --- a/cpp/unittest/db/meta_tests.cpp +++ b/cpp/unittest/db/meta_tests.cpp @@ -224,7 +224,7 @@ TEST_F(MetaTest, TABLE_FILES_TEST) { meta::TableFilesSchema files; - status = impl_->files_to_index(files); + status = impl_->FilesToIndex(files); ASSERT_TRUE(status.ok()); ASSERT_EQ(files.size(), to_index_files_cnt); @@ -233,7 +233,7 @@ TEST_F(MetaTest, TABLE_FILES_TEST) { ASSERT_TRUE(status.ok()); ASSERT_EQ(dated_files[table_file.date].size(), raw_files_cnt); - status = impl_->files_to_index(files); + status = impl_->FilesToIndex(files); ASSERT_TRUE(status.ok()); ASSERT_EQ(files.size(), to_index_files_cnt); -- GitLab