From 930097128b8067e925d7cd84d1f48b16aafec869 Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 29 Nov 2019 10:30:10 +0800 Subject: [PATCH 01/17] #596 Frequently insert operation cost too much disk space --- CHANGELOG.md | 1 + core/src/db/DBImpl.cpp | 126 ++++++--------------------- core/src/db/DBImpl.h | 30 ++----- core/src/db/IndexFailedChecker.cpp | 109 +++++++++++++++++++++++ core/src/db/IndexFailedChecker.h | 56 ++++++++++++ core/src/db/OngoingFileChecker.cpp | 98 +++++++++++++++++++++ core/src/db/OngoingFileChecker.h | 61 +++++++++++++ core/src/db/meta/Meta.h | 4 +- core/src/db/meta/MetaTypes.h | 4 + core/src/db/meta/MySQLMetaImpl.cpp | 73 ++++++++-------- core/src/db/meta/MySQLMetaImpl.h | 4 +- core/src/db/meta/SqliteMetaImpl.cpp | 29 +++++- core/src/db/meta/SqliteMetaImpl.h | 4 +- core/unittest/db/test_meta.cpp | 3 +- core/unittest/db/test_meta_mysql.cpp | 3 +- 15 files changed, 434 insertions(+), 171 deletions(-) create mode 100644 core/src/db/IndexFailedChecker.cpp create mode 100644 core/src/db/IndexFailedChecker.h create mode 100644 core/src/db/OngoingFileChecker.cpp create mode 100644 core/src/db/OngoingFileChecker.h diff --git a/CHANGELOG.md b/CHANGELOG.md index fab5bf3bd0..7c44e9cbe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Please mark all change in change log and use the ticket from JIRA. - \#545 - Avoid dead circle of build index thread when error occurs - \#552 - Server down during building index_type: IVF_PQ using GPU-edition - \#561 - Milvus server should report exception/error message or terminate on mysql metadata backend error +- \#596 - Frequently insert operation cost too much disk space - \#599 - Build index log is incorrect ## Feature diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index 8e08a850f8..c9ebed6378 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -52,8 +52,6 @@ constexpr uint64_t METRIC_ACTION_INTERVAL = 1; constexpr uint64_t COMPACT_ACTION_INTERVAL = 1; constexpr uint64_t INDEX_ACTION_INTERVAL = 1; -constexpr uint64_t INDEX_FAILED_RETRY_TIME = 1; - static const Status SHUTDOWN_ERROR = Status(DB_ERROR, "Milsvus server is shutdown!"); void @@ -370,7 +368,7 @@ DBImpl::CreateIndex(const std::string& table_id, const TableIndex& index) { WaitMergeFileFinish(); // step 4: wait and build index - status = CleanFailedIndexFileOfTable(table_id); + status = index_failed_checker_.CleanFailedIndexFileOfTable(table_id); status = BuildTableIndexRecursively(table_id, index); return status; @@ -504,7 +502,9 @@ DBImpl::QueryAsync(const std::string& table_id, const meta::TableFilesSchema& fi TimeRecorder rc(""); - // step 1: get files to search + // step 1: construct search job + auto status = ongoing_files_checker_.MarkOngoingFiles(files); + ENGINE_LOG_DEBUG << "Engine query begin, index file count: " << files.size(); scheduler::SearchJobPtr job = std::make_shared(k, nq, nprobe, vectors); for (auto& file : files) { @@ -512,9 +512,11 @@ DBImpl::QueryAsync(const std::string& table_id, const meta::TableFilesSchema& fi job->AddIndexFile(file_ptr); } - // step 2: put search task to scheduler + // step 2: put search job to scheduler and wait result scheduler::JobMgrInst::GetInstance()->Put(job); job->WaitResult(); + + status = ongoing_files_checker_.UnmarkOngoingFiles(files); if (!job->GetStatus().ok()) { return job->GetStatus(); } @@ -751,13 +753,15 @@ DBImpl::BackgroundMergeFiles(const std::string& table_id) { } for (auto& kv : raw_files) { - auto files = kv.second; + meta::TableFilesSchema& files = kv.second; if (files.size() < options_.merge_trigger_number_) { ENGINE_LOG_TRACE << "Files number not greater equal than merge trigger number, skip merge action"; continue; } + status = ongoing_files_checker_.MarkOngoingFiles(files); MergeFiles(table_id, kv.first, kv.second); + status = ongoing_files_checker_.UnmarkOngoingFiles(files); if (shutting_down_.load(std::memory_order_acquire)) { ENGINE_LOG_DEBUG << "Server will shutdown, skip merge action for table: " << table_id; @@ -787,17 +791,18 @@ DBImpl::BackgroundCompaction(std::set table_ids) { meta_ptr_->Archive(); + meta::Table2FileIDs ignore_files = ongoing_files_checker_.GetOngoingFiles(); { uint64_t ttl = 10 * meta::SECOND; // default: file data will be erase from cache after few seconds - meta_ptr_->CleanUpCacheWithTTL(ttl); + meta_ptr_->CleanUpCacheWithTTL(ttl, ignore_files); } { - uint64_t ttl = 5 * meta::M_SEC; // default: file will be deleted after few minutes + uint64_t ttl = 20 * meta::SECOND; // default: file will be deleted after few seconds if (options_.mode_ == DBOptions::MODE::CLUSTER_WRITABLE) { - ttl = meta::D_SEC; + ttl = meta::H_SEC; } - meta_ptr_->CleanUpFilesWithTTL(ttl); + meta_ptr_->CleanUpFilesWithTTL(ttl, ignore_files); } // ENGINE_LOG_TRACE << " Background compaction thread exit"; @@ -838,9 +843,11 @@ DBImpl::BackgroundBuildIndex() { std::unique_lock lock(build_index_mutex_); meta::TableFilesSchema to_index_files; meta_ptr_->FilesToIndex(to_index_files); - Status status = IgnoreFailedIndexFiles(to_index_files); + Status status = index_failed_checker_.IgnoreFailedIndexFiles(to_index_files); if (!to_index_files.empty()) { + status = ongoing_files_checker_.MarkOngoingFiles(to_index_files); + // step 2: put build index task to scheduler std::map job2file_map; for (auto& file : to_index_files) { @@ -859,13 +866,15 @@ DBImpl::BackgroundBuildIndex() { Status status = job->GetStatus(); ENGINE_LOG_ERROR << "Building index job " << job->id() << " failed: " << status.ToString(); - MarkFailedIndexFile(file_schema); + index_failed_checker_.MarkFailedIndexFile(file_schema); } else { - MarkSucceedIndexFile(file_schema); + index_failed_checker_.MarkSucceedIndexFile(file_schema); ENGINE_LOG_DEBUG << "Building index job " << job->id() << " succeed."; } } + status = ongoing_files_checker_.UnmarkOngoingFiles(to_index_files); + ENGINE_LOG_DEBUG << "Background build index thread finished"; } @@ -894,6 +903,8 @@ DBImpl::GetFilesToBuildIndex(const std::string& table_id, const std::vector Status DBImpl::GetFilesToSearch(const std::string& table_id, const std::vector& file_ids, const meta::DatesT& dates, meta::TableFilesSchema& files) { + ENGINE_LOG_DEBUG << "Collect files from table: " << table_id; + meta::DatePartionedTableFilesSchema date_files; auto status = meta_ptr_->FilesToSearch(table_id, file_ids, dates, date_files); if (!status.ok()) { @@ -934,7 +945,7 @@ DBImpl::DropTableRecursively(const std::string& table_id, const meta::DatesT& da if (dates.empty()) { status = mem_mgr_->EraseMemVector(table_id); // not allow insert status = meta_ptr_->DropTable(table_id); // soft delete table - CleanFailedIndexFileOfTable(table_id); + index_failed_checker_.CleanFailedIndexFileOfTable(table_id); // scheduler will determine when to delete table files auto nres = scheduler::ResMgrInst::GetInstance()->GetNumOfComputeResource(); @@ -1014,7 +1025,7 @@ DBImpl::BuildTableIndexRecursively(const std::string& table_id, const TableIndex GetFilesToBuildIndex(table_id, file_types, table_files); times++; - IgnoreFailedIndexFiles(table_files); + index_failed_checker_.IgnoreFailedIndexFiles(table_files); } // build index for partition @@ -1029,7 +1040,7 @@ DBImpl::BuildTableIndexRecursively(const std::string& table_id, const TableIndex // failed to build index for some files, return error std::vector failed_files; - GetFailedIndexFileOfTable(table_id, failed_files); + index_failed_checker_.GetFailedIndexFileOfTable(table_id, failed_files); if (!failed_files.empty()) { std::string msg = "Failed to build index for " + std::to_string(failed_files.size()) + ((failed_files.size() == 1) ? " file" : " files"); @@ -1047,7 +1058,7 @@ DBImpl::BuildTableIndexRecursively(const std::string& table_id, const TableIndex Status DBImpl::DropTableIndexRecursively(const std::string& table_id) { ENGINE_LOG_DEBUG << "Drop index for table: " << table_id; - CleanFailedIndexFileOfTable(table_id); + index_failed_checker_.CleanFailedIndexFileOfTable(table_id); auto status = meta_ptr_->DropTableIndex(table_id); if (!status.ok()) { return status; @@ -1090,86 +1101,5 @@ DBImpl::GetTableRowCountRecursively(const std::string& table_id, uint64_t& row_c return Status::OK(); } -Status -DBImpl::CleanFailedIndexFileOfTable(const std::string& table_id) { - std::lock_guard lck(index_failed_mutex_); - index_failed_files_.erase(table_id); // rebuild failed index files for this table - - return Status::OK(); -} - -Status -DBImpl::GetFailedIndexFileOfTable(const std::string& table_id, std::vector& failed_files) { - failed_files.clear(); - std::lock_guard lck(index_failed_mutex_); - auto iter = index_failed_files_.find(table_id); - if (iter != index_failed_files_.end()) { - FileID2FailedTimes& failed_map = iter->second; - for (auto it_file = failed_map.begin(); it_file != failed_map.end(); ++it_file) { - failed_files.push_back(it_file->first); - } - } - - return Status::OK(); -} - -Status -DBImpl::MarkFailedIndexFile(const meta::TableFileSchema& file) { - std::lock_guard lck(index_failed_mutex_); - - auto iter = index_failed_files_.find(file.table_id_); - if (iter == index_failed_files_.end()) { - FileID2FailedTimes failed_files; - failed_files.insert(std::make_pair(file.file_id_, 1)); - index_failed_files_.insert(std::make_pair(file.table_id_, failed_files)); - } else { - auto it_failed_files = iter->second.find(file.file_id_); - if (it_failed_files != iter->second.end()) { - it_failed_files->second++; - } else { - iter->second.insert(std::make_pair(file.file_id_, 1)); - } - } - - return Status::OK(); -} - -Status -DBImpl::MarkSucceedIndexFile(const meta::TableFileSchema& file) { - std::lock_guard lck(index_failed_mutex_); - - auto iter = index_failed_files_.find(file.table_id_); - if (iter != index_failed_files_.end()) { - iter->second.erase(file.file_id_); - } - - return Status::OK(); -} - -Status -DBImpl::IgnoreFailedIndexFiles(meta::TableFilesSchema& table_files) { - std::lock_guard lck(index_failed_mutex_); - - // there could be some failed files belong to different table. - // some files may has failed for several times, no need to build index for these files. - // thus we can avoid dead circle for build index operation - for (auto it_file = table_files.begin(); it_file != table_files.end();) { - auto it_failed_files = index_failed_files_.find((*it_file).table_id_); - if (it_failed_files != index_failed_files_.end()) { - auto it_failed_file = it_failed_files->second.find((*it_file).file_id_); - if (it_failed_file != it_failed_files->second.end()) { - if (it_failed_file->second >= INDEX_FAILED_RETRY_TIME) { - it_file = table_files.erase(it_file); - continue; - } - } - } - - ++it_file; - } - - return Status::OK(); -} - } // namespace engine } // namespace milvus diff --git a/core/src/db/DBImpl.h b/core/src/db/DBImpl.h index 3baac92c0a..5091160d63 100644 --- a/core/src/db/DBImpl.h +++ b/core/src/db/DBImpl.h @@ -18,8 +18,10 @@ #pragma once #include "DB.h" -#include "Types.h" -#include "src/db/insert/MemManager.h" +#include "db/IndexFailedChecker.h" +#include "db/OngoingFileChecker.h" +#include "db/Types.h" +#include "db/insert/MemManager.h" #include "utils/ThreadPool.h" #include @@ -178,21 +180,6 @@ class DBImpl : public DB { Status GetTableRowCountRecursively(const std::string& table_id, uint64_t& row_count); - Status - CleanFailedIndexFileOfTable(const std::string& table_id); - - Status - GetFailedIndexFileOfTable(const std::string& table_id, std::vector& failed_files); - - Status - MarkFailedIndexFile(const meta::TableFileSchema& file); - - Status - MarkSucceedIndexFile(const meta::TableFileSchema& file); - - Status - IgnoreFailedIndexFiles(meta::TableFilesSchema& table_files); - private: const DBOptions options_; @@ -214,11 +201,10 @@ class DBImpl : public DB { std::list> index_thread_results_; std::mutex build_index_mutex_; - std::mutex index_failed_mutex_; - using FileID2FailedTimes = std::map; - using Table2FailedFiles = std::map; - Table2FailedFiles index_failed_files_; // file id mapping to failed times -}; // DBImpl + + IndexFailedChecker index_failed_checker_; + OngoingFileChecker ongoing_files_checker_; +}; // DBImpl } // namespace engine } // namespace milvus diff --git a/core/src/db/IndexFailedChecker.cpp b/core/src/db/IndexFailedChecker.cpp new file mode 100644 index 0000000000..f3667996a5 --- /dev/null +++ b/core/src/db/IndexFailedChecker.cpp @@ -0,0 +1,109 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "db/IndexFailedChecker.h" + +#include + +namespace milvus { +namespace engine { + +constexpr uint64_t INDEX_FAILED_RETRY_TIME = 1; + +Status +IndexFailedChecker::CleanFailedIndexFileOfTable(const std::string& table_id) { + std::lock_guard lck(mutex_); + index_failed_files_.erase(table_id); // rebuild failed index files for this table + + return Status::OK(); +} + +Status +IndexFailedChecker::GetFailedIndexFileOfTable(const std::string& table_id, std::vector& failed_files) { + failed_files.clear(); + std::lock_guard lck(mutex_); + auto iter = index_failed_files_.find(table_id); + if (iter != index_failed_files_.end()) { + FileID2FailedTimes& failed_map = iter->second; + for (auto it_file = failed_map.begin(); it_file != failed_map.end(); ++it_file) { + failed_files.push_back(it_file->first); + } + } + + return Status::OK(); +} + +Status +IndexFailedChecker::MarkFailedIndexFile(const meta::TableFileSchema& file) { + std::lock_guard lck(mutex_); + + auto iter = index_failed_files_.find(file.table_id_); + if (iter == index_failed_files_.end()) { + FileID2FailedTimes failed_files; + failed_files.insert(std::make_pair(file.file_id_, 1)); + index_failed_files_.insert(std::make_pair(file.table_id_, failed_files)); + } else { + auto it_failed_files = iter->second.find(file.file_id_); + if (it_failed_files != iter->second.end()) { + it_failed_files->second++; + } else { + iter->second.insert(std::make_pair(file.file_id_, 1)); + } + } + + return Status::OK(); +} + +Status +IndexFailedChecker::MarkSucceedIndexFile(const meta::TableFileSchema& file) { + std::lock_guard lck(mutex_); + + auto iter = index_failed_files_.find(file.table_id_); + if (iter != index_failed_files_.end()) { + iter->second.erase(file.file_id_); + } + + return Status::OK(); +} + +Status +IndexFailedChecker::IgnoreFailedIndexFiles(meta::TableFilesSchema& table_files) { + std::lock_guard lck(mutex_); + + // there could be some failed files belong to different table. + // some files may has failed for several times, no need to build index for these files. + // thus we can avoid dead circle for build index operation + for (auto it_file = table_files.begin(); it_file != table_files.end();) { + auto it_failed_files = index_failed_files_.find((*it_file).table_id_); + if (it_failed_files != index_failed_files_.end()) { + auto it_failed_file = it_failed_files->second.find((*it_file).file_id_); + if (it_failed_file != it_failed_files->second.end()) { + if (it_failed_file->second >= INDEX_FAILED_RETRY_TIME) { + it_file = table_files.erase(it_file); + continue; + } + } + } + + ++it_file; + } + + return Status::OK(); +} + +} // namespace engine +} // namespace milvus diff --git a/core/src/db/IndexFailedChecker.h b/core/src/db/IndexFailedChecker.h new file mode 100644 index 0000000000..cdcc34a76d --- /dev/null +++ b/core/src/db/IndexFailedChecker.h @@ -0,0 +1,56 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include "meta/Meta.h" +#include "utils/Status.h" + +#include +#include +#include +#include + +namespace milvus { +namespace engine { + +class IndexFailedChecker { + public: + Status + CleanFailedIndexFileOfTable(const std::string& table_id); + + Status + GetFailedIndexFileOfTable(const std::string& table_id, std::vector& failed_files); + + Status + MarkFailedIndexFile(const meta::TableFileSchema& file); + + Status + MarkSucceedIndexFile(const meta::TableFileSchema& file); + + Status + IgnoreFailedIndexFiles(meta::TableFilesSchema& table_files); + + private: + std::mutex mutex_; + using FileID2FailedTimes = std::map; + using Table2FailedFiles = std::map; + Table2FailedFiles index_failed_files_; // file id mapping to failed times +}; + +} // namespace engine +} // namespace milvus diff --git a/core/src/db/OngoingFileChecker.cpp b/core/src/db/OngoingFileChecker.cpp new file mode 100644 index 0000000000..6bf966ba73 --- /dev/null +++ b/core/src/db/OngoingFileChecker.cpp @@ -0,0 +1,98 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "db/OngoingFileChecker.h" + +#include + +namespace milvus { +namespace engine { + +Status +OngoingFileChecker::MarkOngoingFile(const meta::TableFileSchema& table_file) { + std::lock_guard lck(mutex_); + return MarkOngoingFileNoLock(table_file); +} + +Status +OngoingFileChecker::MarkOngoingFiles(const meta::TableFilesSchema& table_files) { + std::lock_guard lck(mutex_); + + for (auto& table_file : table_files) { + MarkOngoingFileNoLock(table_file); + } + + return Status::OK(); +} + +Status +OngoingFileChecker::UnmarkOngoingFile(const meta::TableFileSchema& table_file) { + std::lock_guard lck(mutex_); + return UnmarkOngoingFileNoLock(table_file); +} + +Status +OngoingFileChecker::UnmarkOngoingFiles(const meta::TableFilesSchema& table_files) { + std::lock_guard lck(mutex_); + + for (auto& table_file : table_files) { + UnmarkOngoingFileNoLock(table_file); + } + + return Status::OK(); +} + +meta::Table2FileIDs +OngoingFileChecker::GetOngoingFiles() { + // return copy + // don't return reference(avoid multi-threads conflict) + return ongoing_files_; +} + +Status +OngoingFileChecker::MarkOngoingFileNoLock(const meta::TableFileSchema& table_file) { + if (table_file.table_id_.empty() || table_file.file_id_.empty()) { + return Status(DB_ERROR, "Invalid table files"); + } + + auto iter = ongoing_files_.find(table_file.table_id_); + if (iter == ongoing_files_.end()) { + meta::FileIDArray file_ids = {table_file.file_id_}; + ongoing_files_.insert(std::make_pair(table_file.table_id_, file_ids)); + } else { + iter->second.insert(table_file.file_id_); + } + + return Status::OK(); +} + +Status +OngoingFileChecker::UnmarkOngoingFileNoLock(const meta::TableFileSchema& table_file) { + if (table_file.table_id_.empty() || table_file.file_id_.empty()) { + return Status(DB_ERROR, "Invalid table files"); + } + + auto iter = ongoing_files_.find(table_file.table_id_); + if (iter != ongoing_files_.end()) { + iter->second.erase(table_file.file_id_); + } + + return Status::OK(); +} + +} // namespace engine +} // namespace milvus diff --git a/core/src/db/OngoingFileChecker.h b/core/src/db/OngoingFileChecker.h new file mode 100644 index 0000000000..8f21a45045 --- /dev/null +++ b/core/src/db/OngoingFileChecker.h @@ -0,0 +1,61 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include "meta/Meta.h" +#include "utils/Status.h" + +#include +#include +#include +#include + +namespace milvus { +namespace engine { + +class OngoingFileChecker { + public: + Status + MarkOngoingFile(const meta::TableFileSchema& table_file); + + Status + MarkOngoingFiles(const meta::TableFilesSchema& table_files); + + Status + UnmarkOngoingFile(const meta::TableFileSchema& table_file); + + Status + UnmarkOngoingFiles(const meta::TableFilesSchema& table_files); + + meta::Table2FileIDs + GetOngoingFiles(); + + private: + Status + MarkOngoingFileNoLock(const meta::TableFileSchema& table_file); + + Status + UnmarkOngoingFileNoLock(const meta::TableFileSchema& table_file); + + private: + std::mutex mutex_; + meta::Table2FileIDs ongoing_files_; +}; + +} // namespace engine +} // namespace milvus diff --git a/core/src/db/meta/Meta.h b/core/src/db/meta/Meta.h index bf46f02fea..f620087ad5 100644 --- a/core/src/db/meta/Meta.h +++ b/core/src/db/meta/Meta.h @@ -121,10 +121,10 @@ class Meta { CleanUpShadowFiles() = 0; virtual Status - CleanUpCacheWithTTL(uint64_t seconds) = 0; + CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) = 0; virtual Status - CleanUpFilesWithTTL(uint64_t seconds) = 0; + CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) = 0; virtual Status DropAll() = 0; diff --git a/core/src/db/meta/MetaTypes.h b/core/src/db/meta/MetaTypes.h index d98b74be7d..3e28658983 100644 --- a/core/src/db/meta/MetaTypes.h +++ b/core/src/db/meta/MetaTypes.h @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -97,6 +98,9 @@ using TableFileSchemaPtr = std::shared_ptr; using TableFilesSchema = std::vector; using DatePartionedTableFilesSchema = std::map; +using FileIDArray = std::set; +using Table2FileIDs = std::map; + } // namespace meta } // namespace engine } // namespace milvus diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index 7b53e6361a..d9ca892341 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -1639,7 +1639,8 @@ MySQLMetaImpl::FilesByType(const std::string& table_id, const std::vector& case (int)TableFileSchema::BACKUP: msg = msg + " backup files:" + std::to_string(backup_count); break; - default:break; + default: + break; } } ENGINE_LOG_DEBUG << msg; @@ -1782,7 +1783,7 @@ MySQLMetaImpl::CleanUpShadowFiles() { } Status -MySQLMetaImpl::CleanUpCacheWithTTL(uint64_t seconds) { +MySQLMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) { auto now = utils::GetMicroSecTimeStamp(); // erase deleted/backup files from cache @@ -1795,14 +1796,13 @@ MySQLMetaImpl::CleanUpCacheWithTTL(uint64_t seconds) { return Status(DB_ERROR, "Failed to connect to meta server(mysql)"); } - mysqlpp::Query cleanUpFilesWithTTLQuery = connectionPtr->query(); - cleanUpFilesWithTTLQuery << "SELECT id, table_id, file_id, date" - << " FROM " << META_TABLEFILES << " WHERE file_type IN (" - << std::to_string(TableFileSchema::TO_DELETE) << "," - << std::to_string(TableFileSchema::BACKUP) << ")" - << " AND updated_time < " << std::to_string(now - seconds * US_PS) << ";"; + mysqlpp::Query query = connectionPtr->query(); + query << "SELECT id, table_id, file_id, date" + << " FROM " << META_TABLEFILES << " WHERE file_type IN (" << std::to_string(TableFileSchema::TO_DELETE) + << "," << std::to_string(TableFileSchema::BACKUP) << ")" + << " AND updated_time < " << std::to_string(now - seconds * US_PS) << ";"; - mysqlpp::StoreQueryResult res = cleanUpFilesWithTTLQuery.store(); + mysqlpp::StoreQueryResult res = query.store(); TableFileSchema table_file; std::vector idsToDelete; @@ -1824,7 +1824,7 @@ MySQLMetaImpl::CleanUpCacheWithTTL(uint64_t seconds) { } Status -MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds) { +MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) { auto now = utils::GetMicroSecTimeStamp(); std::set table_ids; @@ -1839,15 +1839,14 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds) { return Status(DB_ERROR, "Failed to connect to meta server(mysql)"); } - mysqlpp::Query cleanUpFilesWithTTLQuery = connectionPtr->query(); - cleanUpFilesWithTTLQuery << "SELECT id, table_id, file_id, date" - << " FROM " << META_TABLEFILES - << " WHERE file_type = " << std::to_string(TableFileSchema::TO_DELETE) - << " AND updated_time < " << std::to_string(now - seconds * US_PS) << ";"; + mysqlpp::Query query = connectionPtr->query(); + query << "SELECT id, table_id, file_id, date" + << " FROM " << META_TABLEFILES << " WHERE file_type = " << std::to_string(TableFileSchema::TO_DELETE) + << " AND updated_time < " << std::to_string(now - seconds * US_PS) << ";"; - ENGINE_LOG_DEBUG << "MySQLMetaImpl::CleanUpFilesWithTTL: " << cleanUpFilesWithTTLQuery.str(); + ENGINE_LOG_DEBUG << "MySQLMetaImpl::CleanUpFilesWithTTL: " << query.str(); - mysqlpp::StoreQueryResult res = cleanUpFilesWithTTLQuery.store(); + mysqlpp::StoreQueryResult res = query.store(); TableFileSchema table_file; std::vector idsToDelete; @@ -1874,13 +1873,12 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds) { std::string idsToDeleteStr = idsToDeleteSS.str(); idsToDeleteStr = idsToDeleteStr.substr(0, idsToDeleteStr.size() - 4); // remove the last " OR " - cleanUpFilesWithTTLQuery << "DELETE FROM " << META_TABLEFILES << " WHERE " << idsToDeleteStr << ";"; + query << "DELETE FROM " << META_TABLEFILES << " WHERE " << idsToDeleteStr << ";"; - ENGINE_LOG_DEBUG << "MySQLMetaImpl::CleanUpFilesWithTTL: " << cleanUpFilesWithTTLQuery.str(); + ENGINE_LOG_DEBUG << "MySQLMetaImpl::CleanUpFilesWithTTL: " << query.str(); - if (!cleanUpFilesWithTTLQuery.exec()) { - return HandleException("QUERY ERROR WHEN CLEANING UP FILES WITH TTL", - cleanUpFilesWithTTLQuery.error()); + if (!query.exec()) { + return HandleException("QUERY ERROR WHEN CLEANING UP FILES WITH TTL", query.error()); } } @@ -1903,14 +1901,13 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds) { return Status(DB_ERROR, "Failed to connect to meta server(mysql)"); } - mysqlpp::Query cleanUpFilesWithTTLQuery = connectionPtr->query(); - cleanUpFilesWithTTLQuery << "SELECT id, table_id" - << " FROM " << META_TABLES - << " WHERE state = " << std::to_string(TableSchema::TO_DELETE) << ";"; + mysqlpp::Query query = connectionPtr->query(); + query << "SELECT id, table_id" + << " FROM " << META_TABLES << " WHERE state = " << std::to_string(TableSchema::TO_DELETE) << ";"; - ENGINE_LOG_DEBUG << "MySQLMetaImpl::CleanUpFilesWithTTL: " << cleanUpFilesWithTTLQuery.str(); + ENGINE_LOG_DEBUG << "MySQLMetaImpl::CleanUpFilesWithTTL: " << query.str(); - mysqlpp::StoreQueryResult res = cleanUpFilesWithTTLQuery.store(); + mysqlpp::StoreQueryResult res = query.store(); int64_t remove_tables = 0; if (!res.empty()) { @@ -1926,13 +1923,12 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds) { } std::string idsToDeleteStr = idsToDeleteSS.str(); idsToDeleteStr = idsToDeleteStr.substr(0, idsToDeleteStr.size() - 4); // remove the last " OR " - cleanUpFilesWithTTLQuery << "DELETE FROM " << META_TABLES << " WHERE " << idsToDeleteStr << ";"; + query << "DELETE FROM " << META_TABLES << " WHERE " << idsToDeleteStr << ";"; - ENGINE_LOG_DEBUG << "MySQLMetaImpl::CleanUpFilesWithTTL: " << cleanUpFilesWithTTLQuery.str(); + ENGINE_LOG_DEBUG << "MySQLMetaImpl::CleanUpFilesWithTTL: " << query.str(); - if (!cleanUpFilesWithTTLQuery.exec()) { - return HandleException("QUERY ERROR WHEN CLEANING UP TABLES WITH TTL", - cleanUpFilesWithTTLQuery.error()); + if (!query.exec()) { + return HandleException("QUERY ERROR WHEN CLEANING UP TABLES WITH TTL", query.error()); } } @@ -1957,14 +1953,13 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds) { } for (auto& table_id : table_ids) { - mysqlpp::Query cleanUpFilesWithTTLQuery = connectionPtr->query(); - cleanUpFilesWithTTLQuery << "SELECT file_id" - << " FROM " << META_TABLEFILES << " WHERE table_id = " << mysqlpp::quote - << table_id << ";"; + mysqlpp::Query query = connectionPtr->query(); + query << "SELECT file_id" + << " FROM " << META_TABLEFILES << " WHERE table_id = " << mysqlpp::quote << table_id << ";"; - ENGINE_LOG_DEBUG << "MySQLMetaImpl::CleanUpFilesWithTTL: " << cleanUpFilesWithTTLQuery.str(); + ENGINE_LOG_DEBUG << "MySQLMetaImpl::CleanUpFilesWithTTL: " << query.str(); - mysqlpp::StoreQueryResult res = cleanUpFilesWithTTLQuery.store(); + mysqlpp::StoreQueryResult res = query.store(); if (res.empty()) { utils::DeleteTablePath(options_, table_id); diff --git a/core/src/db/meta/MySQLMetaImpl.h b/core/src/db/meta/MySQLMetaImpl.h index e7697316af..d13ed7e043 100644 --- a/core/src/db/meta/MySQLMetaImpl.h +++ b/core/src/db/meta/MySQLMetaImpl.h @@ -120,10 +120,10 @@ class MySQLMetaImpl : public Meta { CleanUpShadowFiles() override; Status - CleanUpCacheWithTTL(uint64_t seconds) override; + CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) override; Status - CleanUpFilesWithTTL(uint64_t seconds) override; + CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) override; Status DropAll() override; diff --git a/core/src/db/meta/SqliteMetaImpl.cpp b/core/src/db/meta/SqliteMetaImpl.cpp index 07f890d50a..e751b14555 100644 --- a/core/src/db/meta/SqliteMetaImpl.cpp +++ b/core/src/db/meta/SqliteMetaImpl.cpp @@ -1294,7 +1294,7 @@ SqliteMetaImpl::CleanUpShadowFiles() { } Status -SqliteMetaImpl::CleanUpCacheWithTTL(uint64_t seconds) { +SqliteMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) { auto now = utils::GetMicroSecTimeStamp(); // erase deleted/backup files from cache @@ -1309,6 +1309,7 @@ SqliteMetaImpl::CleanUpCacheWithTTL(uint64_t seconds) { (int)TableFileSchema::BACKUP, }; + // collect files to be erased auto files = ConnectorPtr->select(columns(&TableFileSchema::id_, &TableFileSchema::table_id_, &TableFileSchema::file_id_, @@ -1326,6 +1327,15 @@ SqliteMetaImpl::CleanUpCacheWithTTL(uint64_t seconds) { table_file.file_id_ = std::get<2>(file); table_file.date_ = std::get<3>(file); + // check if the file can be deleted + auto iter = ignore_files.find(table_file.table_id_); + if (iter != ignore_files.end()) { + if (iter->second.find(table_file.file_id_) != iter->second.end()) { + continue; // ignore this file, don't delete it + } + } + + // erase file data from cache utils::GetTableFilePath(options_, table_file); server::CommonUtil::EraseFromCache(table_file.location_); } @@ -1338,7 +1348,7 @@ SqliteMetaImpl::CleanUpCacheWithTTL(uint64_t seconds) { } Status -SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds) { +SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) { auto now = utils::GetMicroSecTimeStamp(); std::set table_ids; @@ -1349,6 +1359,7 @@ SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds) { // multi-threads call sqlite update may get exception('bad logic', etc), so we add a lock here std::lock_guard meta_lock(meta_mutex_); + // collect files to be deleted auto files = ConnectorPtr->select(columns(&TableFileSchema::id_, &TableFileSchema::table_id_, &TableFileSchema::file_id_, @@ -1368,10 +1379,20 @@ SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds) { table_file.file_id_ = std::get<2>(file); table_file.date_ = std::get<3>(file); - utils::DeleteTableFilePath(options_, table_file); - ENGINE_LOG_DEBUG << "Removing file id:" << table_file.file_id_ << " location:" << table_file.location_; + // check if the file can be deleted + auto iter = ignore_files.find(table_file.table_id_); + if (iter != ignore_files.end()) { + if (iter->second.find(table_file.file_id_) != iter->second.end()) { + continue; // ignore this file, don't delete it + } + } + + // delete file from meta ConnectorPtr->remove(table_file.id_); + // delete file from disk storage + utils::DeleteTableFilePath(options_, table_file); + ENGINE_LOG_DEBUG << "Removing file id:" << table_file.file_id_ << " location:" << table_file.location_; table_ids.insert(table_file.table_id_); } return true; diff --git a/core/src/db/meta/SqliteMetaImpl.h b/core/src/db/meta/SqliteMetaImpl.h index 5581efe361..4ef4542022 100644 --- a/core/src/db/meta/SqliteMetaImpl.h +++ b/core/src/db/meta/SqliteMetaImpl.h @@ -120,10 +120,10 @@ class SqliteMetaImpl : public Meta { CleanUpShadowFiles() override; Status - CleanUpCacheWithTTL(uint64_t seconds) override; + CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) override; Status - CleanUpFilesWithTTL(uint64_t seconds) override; + CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) override; Status DropAll() override; diff --git a/core/unittest/db/test_meta.cpp b/core/unittest/db/test_meta.cpp index b89c73c296..c2a9f8e8bc 100644 --- a/core/unittest/db/test_meta.cpp +++ b/core/unittest/db/test_meta.cpp @@ -335,7 +335,8 @@ TEST_F(MetaTest, TABLE_FILES_TEST) { status = impl_->DropTable(table_id); ASSERT_TRUE(status.ok()); - status = impl_->CleanUpFilesWithTTL(1UL); + milvus::engine::meta::Table2FileIDs ignore_files; + status = impl_->CleanUpFilesWithTTL(1UL, ignore_files); ASSERT_TRUE(status.ok()); } diff --git a/core/unittest/db/test_meta_mysql.cpp b/core/unittest/db/test_meta_mysql.cpp index 9a52a01b7b..cdd8aa32a8 100644 --- a/core/unittest/db/test_meta_mysql.cpp +++ b/core/unittest/db/test_meta_mysql.cpp @@ -349,7 +349,8 @@ TEST_F(MySqlMetaTest, TABLE_FILES_TEST) { status = impl_->DropTable(table_id); ASSERT_TRUE(status.ok()); - status = impl_->CleanUpFilesWithTTL(0UL); + milvus::engine::meta::Table2FileIDs ignore_files; + status = impl_->CleanUpFilesWithTTL(0UL, ignore_files); ASSERT_TRUE(status.ok()); } From 50cd6dd8d291eb9fd1bec2c35dbd2e9b9713b2a3 Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 29 Nov 2019 10:47:23 +0800 Subject: [PATCH 02/17] add unittest case --- core/src/db/IndexFailedChecker.cpp | 3 ++ core/src/db/OngoingFileChecker.cpp | 3 ++ core/unittest/db/test_misc.cpp | 64 ++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/core/src/db/IndexFailedChecker.cpp b/core/src/db/IndexFailedChecker.cpp index f3667996a5..d1bb753294 100644 --- a/core/src/db/IndexFailedChecker.cpp +++ b/core/src/db/IndexFailedChecker.cpp @@ -75,6 +75,9 @@ IndexFailedChecker::MarkSucceedIndexFile(const meta::TableFileSchema& file) { auto iter = index_failed_files_.find(file.table_id_); if (iter != index_failed_files_.end()) { iter->second.erase(file.file_id_); + if (iter->second.empty()) { + index_failed_files_.erase(file.table_id_); + } } return Status::OK(); diff --git a/core/src/db/OngoingFileChecker.cpp b/core/src/db/OngoingFileChecker.cpp index 6bf966ba73..3462621d3c 100644 --- a/core/src/db/OngoingFileChecker.cpp +++ b/core/src/db/OngoingFileChecker.cpp @@ -89,6 +89,9 @@ OngoingFileChecker::UnmarkOngoingFileNoLock(const meta::TableFileSchema& table_f auto iter = ongoing_files_.find(table_file.table_id_); if (iter != ongoing_files_.end()) { iter->second.erase(table_file.file_id_); + if (iter->second.empty()) { + ongoing_files_.erase(table_file.table_id_); + } } return Status::OK(); diff --git a/core/unittest/db/test_misc.cpp b/core/unittest/db/test_misc.cpp index c044dde8da..1ed02afb53 100644 --- a/core/unittest/db/test_misc.cpp +++ b/core/unittest/db/test_misc.cpp @@ -15,6 +15,8 @@ // specific language governing permissions and limitations // under the License. +#include "db/IndexFailedChecker.h" +#include "db/OngoingFileChecker.h" #include "db/Options.h" #include "db/Utils.h" #include "db/engine/EngineFactory.h" @@ -119,3 +121,65 @@ TEST(DBMiscTest, UTILS_TEST) { status = milvus::engine::utils::DeleteTableFilePath(options, file); ASSERT_TRUE(status.ok()); } + +TEST(DBMiscTest, CHECKER_TEST) { + { + milvus::engine::IndexFailedChecker checker; + milvus::engine::meta::TableFileSchema schema; + schema.table_id_ = "aaa"; + schema.file_id_ = "5000"; + checker.MarkFailedIndexFile(schema); + schema.table_id_ = "bbb"; + schema.file_id_ = "5001"; + checker.MarkFailedIndexFile(schema); + + std::vector failed_files; + checker.GetFailedIndexFileOfTable("aaa", failed_files); + ASSERT_EQ(failed_files.size(), 1UL); + + schema.table_id_ = "bbb"; + schema.file_id_ = "5002"; + checker.MarkFailedIndexFile(schema); + checker.MarkFailedIndexFile(schema); + + milvus::engine::meta::TableFilesSchema table_files = {schema}; + checker.IgnoreFailedIndexFiles(table_files); + ASSERT_TRUE(table_files.empty()); + + checker.GetFailedIndexFileOfTable("bbb", failed_files); + ASSERT_EQ(failed_files.size(), 2UL); + + checker.MarkSucceedIndexFile(schema); + checker.GetFailedIndexFileOfTable("bbb", failed_files); + ASSERT_EQ(failed_files.size(), 1UL); + } + + { + milvus::engine::OngoingFileChecker checker; + milvus::engine::meta::TableFileSchema schema; + schema.table_id_ = "aaa"; + schema.file_id_ = "5000"; + checker.MarkOngoingFile(schema); + + auto ongoing_files = checker.GetOngoingFiles(); + ASSERT_EQ(ongoing_files.size(), 1UL); + + schema.table_id_ = "bbb"; + schema.file_id_ = "5001"; + milvus::engine::meta::TableFilesSchema table_files = {schema}; + checker.MarkOngoingFiles(table_files); + + ongoing_files = checker.GetOngoingFiles(); + ASSERT_EQ(ongoing_files.size(), 2UL); + + checker.UnmarkOngoingFile(schema); + ongoing_files = checker.GetOngoingFiles(); + ASSERT_EQ(ongoing_files.size(), 1UL); + + schema.table_id_ = "aaa"; + schema.file_id_ = "5000"; + checker.UnmarkOngoingFile(schema); + ongoing_files = checker.GetOngoingFiles(); + ASSERT_EQ(ongoing_files.size(), 0UL); + } +} From cc5c0bf2f21f6d8b362b6105bd96130c44ce1d15 Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 29 Nov 2019 10:55:59 +0800 Subject: [PATCH 03/17] mysql ongoing files --- core/src/db/meta/MySQLMetaImpl.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index d9ca892341..559e0d5a11 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -1813,6 +1813,15 @@ MySQLMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore resRow["file_id"].to_string(table_file.file_id_); table_file.date_ = resRow["date"]; + // check if the file can be deleted + auto iter = ignore_files.find(table_file.table_id_); + if (iter != ignore_files.end()) { + if (iter->second.find(table_file.file_id_) != iter->second.end()) { + continue; // ignore this file, don't delete it + } + } + + // erase file data from cache utils::GetTableFilePath(options_, table_file); server::CommonUtil::EraseFromCache(table_file.location_); } @@ -1857,14 +1866,23 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore resRow["file_id"].to_string(table_file.file_id_); table_file.date_ = resRow["date"]; - utils::DeleteTableFilePath(options_, table_file); + // check if the file can be deleted + auto iter = ignore_files.find(table_file.table_id_); + if (iter != ignore_files.end()) { + if (iter->second.find(table_file.file_id_) != iter->second.end()) { + continue; // ignore this file, don't delete it + } + } + // delete file from disk storage + utils::DeleteTableFilePath(options_, table_file); ENGINE_LOG_DEBUG << "Removing file id:" << table_file.id_ << " location:" << table_file.location_; idsToDelete.emplace_back(std::to_string(table_file.id_)); table_ids.insert(table_file.table_id_); } + // delete file from meta if (!idsToDelete.empty()) { std::stringstream idsToDeleteSS; for (auto& id : idsToDelete) { From 095b1243e6cf0870583d1c434167bed3004d23d3 Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 29 Nov 2019 11:37:31 +0800 Subject: [PATCH 04/17] add more log --- core/src/db/DBImpl.cpp | 5 +++-- core/src/db/meta/MySQLMetaImpl.cpp | 8 ++++++-- core/src/db/meta/SqliteMetaImpl.cpp | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index c9ebed6378..e96b921fb7 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -849,15 +849,16 @@ DBImpl::BackgroundBuildIndex() { status = ongoing_files_checker_.MarkOngoingFiles(to_index_files); // step 2: put build index task to scheduler - std::map job2file_map; + std::vector> job2file_map; for (auto& file : to_index_files) { scheduler::BuildIndexJobPtr job = std::make_shared(meta_ptr_, options_); scheduler::TableFileSchemaPtr file_ptr = std::make_shared(file); job->AddToIndexFiles(file_ptr); scheduler::JobMgrInst::GetInstance()->Put(job); - job2file_map.insert(std::make_pair(job, file_ptr)); + job2file_map.push_back(std::make_pair(job, file_ptr)); } + // step 3: wait build index finished and mark failed files for (auto iter = job2file_map.begin(); iter != job2file_map.end(); ++iter) { scheduler::BuildIndexJobPtr job = iter->first; meta::TableFileSchema& file_schema = *(iter->second.get()); diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index 559e0d5a11..4e2f3b47e1 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -1817,7 +1817,9 @@ MySQLMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore auto iter = ignore_files.find(table_file.table_id_); if (iter != ignore_files.end()) { if (iter->second.find(table_file.file_id_) != iter->second.end()) { - continue; // ignore this file, don't delete it + ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ + << " currently is in use, not able to erase from cache now"; + continue; // ignore this file, don't delete it } } @@ -1870,7 +1872,9 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore auto iter = ignore_files.find(table_file.table_id_); if (iter != ignore_files.end()) { if (iter->second.find(table_file.file_id_) != iter->second.end()) { - continue; // ignore this file, don't delete it + ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ + << " currently is in use, not able to delete now"; + continue; // ignore this file, don't delete it } } diff --git a/core/src/db/meta/SqliteMetaImpl.cpp b/core/src/db/meta/SqliteMetaImpl.cpp index e751b14555..b2f4102dde 100644 --- a/core/src/db/meta/SqliteMetaImpl.cpp +++ b/core/src/db/meta/SqliteMetaImpl.cpp @@ -1331,6 +1331,8 @@ SqliteMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignor auto iter = ignore_files.find(table_file.table_id_); if (iter != ignore_files.end()) { if (iter->second.find(table_file.file_id_) != iter->second.end()) { + ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ + << " currently is in use, not able to erase from cache now"; continue; // ignore this file, don't delete it } } @@ -1383,6 +1385,8 @@ SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignor auto iter = ignore_files.find(table_file.table_id_); if (iter != ignore_files.end()) { if (iter->second.find(table_file.file_id_) != iter->second.end()) { + ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ + << " currently is in use, not able to delete now"; continue; // ignore this file, don't delete it } } From 85211d537f7b8a579c4ce3b3450536f35b351f10 Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 29 Nov 2019 12:38:18 +0800 Subject: [PATCH 05/17] reconstruct code --- core/src/db/DBImpl.cpp | 9 +++---- core/src/db/IndexFailedChecker.cpp | 4 +-- core/src/db/IndexFailedChecker.h | 4 +-- core/src/db/OngoingFileChecker.cpp | 39 ++++++++++++++++++++++------ core/src/db/OngoingFileChecker.h | 8 +++--- core/src/db/meta/Meta.h | 11 ++++++-- core/src/db/meta/MetaTypes.h | 4 +-- core/src/db/meta/MySQLMetaImpl.cpp | 28 ++++++++------------ core/src/db/meta/MySQLMetaImpl.h | 4 +-- core/src/db/meta/SqliteMetaImpl.cpp | 28 ++++++++------------ core/src/db/meta/SqliteMetaImpl.h | 4 +-- core/unittest/db/test_meta.cpp | 3 +-- core/unittest/db/test_meta_mysql.cpp | 3 +-- core/unittest/db/test_misc.cpp | 13 ++++------ 14 files changed, 86 insertions(+), 76 deletions(-) diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index e96b921fb7..c88936a08e 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -791,18 +791,17 @@ DBImpl::BackgroundCompaction(std::set table_ids) { meta_ptr_->Archive(); - meta::Table2FileIDs ignore_files = ongoing_files_checker_.GetOngoingFiles(); { - uint64_t ttl = 10 * meta::SECOND; // default: file data will be erase from cache after few seconds - meta_ptr_->CleanUpCacheWithTTL(ttl, ignore_files); + uint64_t ttl = 1 * meta::SECOND; // default: file data will be erase from cache after few seconds + meta_ptr_->CleanUpCacheWithTTL(ttl, &ongoing_files_checker_); } { - uint64_t ttl = 20 * meta::SECOND; // default: file will be deleted after few seconds + uint64_t ttl = 1 * meta::SECOND; // default: file will be deleted after few seconds if (options_.mode_ == DBOptions::MODE::CLUSTER_WRITABLE) { ttl = meta::H_SEC; } - meta_ptr_->CleanUpFilesWithTTL(ttl, ignore_files); + meta_ptr_->CleanUpFilesWithTTL(ttl, &ongoing_files_checker_); } // ENGINE_LOG_TRACE << " Background compaction thread exit"; diff --git a/core/src/db/IndexFailedChecker.cpp b/core/src/db/IndexFailedChecker.cpp index d1bb753294..bdd152dc4b 100644 --- a/core/src/db/IndexFailedChecker.cpp +++ b/core/src/db/IndexFailedChecker.cpp @@ -38,7 +38,7 @@ IndexFailedChecker::GetFailedIndexFileOfTable(const std::string& table_id, std:: std::lock_guard lck(mutex_); auto iter = index_failed_files_.find(table_id); if (iter != index_failed_files_.end()) { - FileID2FailedTimes& failed_map = iter->second; + meta::File2RefCount& failed_map = iter->second; for (auto it_file = failed_map.begin(); it_file != failed_map.end(); ++it_file) { failed_files.push_back(it_file->first); } @@ -53,7 +53,7 @@ IndexFailedChecker::MarkFailedIndexFile(const meta::TableFileSchema& file) { auto iter = index_failed_files_.find(file.table_id_); if (iter == index_failed_files_.end()) { - FileID2FailedTimes failed_files; + meta::File2RefCount failed_files; failed_files.insert(std::make_pair(file.file_id_, 1)); index_failed_files_.insert(std::make_pair(file.table_id_, failed_files)); } else { diff --git a/core/src/db/IndexFailedChecker.h b/core/src/db/IndexFailedChecker.h index cdcc34a76d..edd6a114bf 100644 --- a/core/src/db/IndexFailedChecker.h +++ b/core/src/db/IndexFailedChecker.h @@ -47,9 +47,7 @@ class IndexFailedChecker { private: std::mutex mutex_; - using FileID2FailedTimes = std::map; - using Table2FailedFiles = std::map; - Table2FailedFiles index_failed_files_; // file id mapping to failed times + meta::Table2Files index_failed_files_; // table id mapping to (file id mapping to failed times) }; } // namespace engine diff --git a/core/src/db/OngoingFileChecker.cpp b/core/src/db/OngoingFileChecker.cpp index 3462621d3c..daaf6a2a4f 100644 --- a/core/src/db/OngoingFileChecker.cpp +++ b/core/src/db/OngoingFileChecker.cpp @@ -16,6 +16,7 @@ // under the License. #include "db/OngoingFileChecker.h" +#include "utils/Log.h" #include @@ -56,11 +57,21 @@ OngoingFileChecker::UnmarkOngoingFiles(const meta::TableFilesSchema& table_files return Status::OK(); } -meta::Table2FileIDs -OngoingFileChecker::GetOngoingFiles() { - // return copy - // don't return reference(avoid multi-threads conflict) - return ongoing_files_; +bool +OngoingFileChecker::IsIgnored(const meta::TableFileSchema& schema) { + std::lock_guard lck(mutex_); + + auto iter = ongoing_files_.find(schema.table_id_); + if (iter == ongoing_files_.end()) { + return false; + } else { + auto it_file = iter->second.find(schema.file_id_); + if (it_file == iter->second.end()) { + return false; + } else { + return (it_file->second > 0); + } + } } Status @@ -71,12 +82,21 @@ OngoingFileChecker::MarkOngoingFileNoLock(const meta::TableFileSchema& table_fil auto iter = ongoing_files_.find(table_file.table_id_); if (iter == ongoing_files_.end()) { - meta::FileIDArray file_ids = {table_file.file_id_}; - ongoing_files_.insert(std::make_pair(table_file.table_id_, file_ids)); + meta::File2RefCount files_refcount; + files_refcount.insert(std::make_pair(table_file.file_id_, 1)); + ongoing_files_.insert(std::make_pair(table_file.table_id_, files_refcount)); } else { - iter->second.insert(table_file.file_id_); + auto it_file = iter->second.find(table_file.file_id_); + if (it_file == iter->second.end()) { + iter->second[table_file.file_id_] = 1; + } else { + it_file->second++; + } } + ENGINE_LOG_DEBUG << "Mark ongoing file:" << table_file.file_id_ + << " refcount:" << ongoing_files_[table_file.table_id_][table_file.file_id_]; + return Status::OK(); } @@ -94,6 +114,9 @@ OngoingFileChecker::UnmarkOngoingFileNoLock(const meta::TableFileSchema& table_f } } + ENGINE_LOG_DEBUG << "Mark ongoing file:" << table_file.file_id_ + << " refcount:" << ongoing_files_[table_file.table_id_][table_file.file_id_]; + return Status::OK(); } diff --git a/core/src/db/OngoingFileChecker.h b/core/src/db/OngoingFileChecker.h index 8f21a45045..c7995e425a 100644 --- a/core/src/db/OngoingFileChecker.h +++ b/core/src/db/OngoingFileChecker.h @@ -28,7 +28,7 @@ namespace milvus { namespace engine { -class OngoingFileChecker { +class OngoingFileChecker : public meta::Meta::CleanUpFilter { public: Status MarkOngoingFile(const meta::TableFileSchema& table_file); @@ -42,8 +42,8 @@ class OngoingFileChecker { Status UnmarkOngoingFiles(const meta::TableFilesSchema& table_files); - meta::Table2FileIDs - GetOngoingFiles(); + bool + IsIgnored(const meta::TableFileSchema& schema) override; private: Status @@ -54,7 +54,7 @@ class OngoingFileChecker { private: std::mutex mutex_; - meta::Table2FileIDs ongoing_files_; + meta::Table2Files ongoing_files_; // table id mapping to (file id mapping to ongoing ref-count) }; } // namespace engine diff --git a/core/src/db/meta/Meta.h b/core/src/db/meta/Meta.h index f620087ad5..8dabb58203 100644 --- a/core/src/db/meta/Meta.h +++ b/core/src/db/meta/Meta.h @@ -35,6 +35,13 @@ static const char* META_TABLES = "Tables"; static const char* META_TABLEFILES = "TableFiles"; class Meta { + public: + class CleanUpFilter { + public: + virtual bool + IsIgnored(const TableFileSchema& schema) = 0; + }; + public: virtual ~Meta() = default; @@ -121,10 +128,10 @@ class Meta { CleanUpShadowFiles() = 0; virtual Status - CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) = 0; + CleanUpCacheWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) = 0; virtual Status - CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) = 0; + CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) = 0; virtual Status DropAll() = 0; diff --git a/core/src/db/meta/MetaTypes.h b/core/src/db/meta/MetaTypes.h index 3e28658983..f8c082032e 100644 --- a/core/src/db/meta/MetaTypes.h +++ b/core/src/db/meta/MetaTypes.h @@ -98,8 +98,8 @@ using TableFileSchemaPtr = std::shared_ptr; using TableFilesSchema = std::vector; using DatePartionedTableFilesSchema = std::map; -using FileIDArray = std::set; -using Table2FileIDs = std::map; +using File2RefCount = std::map; +using Table2Files = std::map; } // namespace meta } // namespace engine diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index 4e2f3b47e1..1fab7a0f77 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -1783,7 +1783,7 @@ MySQLMetaImpl::CleanUpShadowFiles() { } Status -MySQLMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) { +MySQLMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, CleanUpFilter* filter) { auto now = utils::GetMicroSecTimeStamp(); // erase deleted/backup files from cache @@ -1813,14 +1813,11 @@ MySQLMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore resRow["file_id"].to_string(table_file.file_id_); table_file.date_ = resRow["date"]; - // check if the file can be deleted - auto iter = ignore_files.find(table_file.table_id_); - if (iter != ignore_files.end()) { - if (iter->second.find(table_file.file_id_) != iter->second.end()) { - ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ - << " currently is in use, not able to erase from cache now"; - continue; // ignore this file, don't delete it - } + // check if the file can be erased + if (filter && filter->IsIgnored(table_file)) { + ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ + << " currently is in use, not able to erase from cache now"; + continue; // ignore this file, don't erase it } // erase file data from cache @@ -1835,7 +1832,7 @@ MySQLMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore } Status -MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) { +MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { auto now = utils::GetMicroSecTimeStamp(); std::set table_ids; @@ -1869,13 +1866,10 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore table_file.date_ = resRow["date"]; // check if the file can be deleted - auto iter = ignore_files.find(table_file.table_id_); - if (iter != ignore_files.end()) { - if (iter->second.find(table_file.file_id_) != iter->second.end()) { - ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ - << " currently is in use, not able to delete now"; - continue; // ignore this file, don't delete it - } + if (filter && filter->IsIgnored(table_file)) { + ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ + << " currently is in use, not able to delete now"; + continue; // ignore this file, don't delete it } // delete file from disk storage diff --git a/core/src/db/meta/MySQLMetaImpl.h b/core/src/db/meta/MySQLMetaImpl.h index d13ed7e043..d2a94f6cd3 100644 --- a/core/src/db/meta/MySQLMetaImpl.h +++ b/core/src/db/meta/MySQLMetaImpl.h @@ -120,10 +120,10 @@ class MySQLMetaImpl : public Meta { CleanUpShadowFiles() override; Status - CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) override; + CleanUpCacheWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) override; Status - CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) override; + CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) override; Status DropAll() override; diff --git a/core/src/db/meta/SqliteMetaImpl.cpp b/core/src/db/meta/SqliteMetaImpl.cpp index b2f4102dde..9b63f122da 100644 --- a/core/src/db/meta/SqliteMetaImpl.cpp +++ b/core/src/db/meta/SqliteMetaImpl.cpp @@ -1294,7 +1294,7 @@ SqliteMetaImpl::CleanUpShadowFiles() { } Status -SqliteMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) { +SqliteMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, CleanUpFilter* filter) { auto now = utils::GetMicroSecTimeStamp(); // erase deleted/backup files from cache @@ -1327,14 +1327,11 @@ SqliteMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignor table_file.file_id_ = std::get<2>(file); table_file.date_ = std::get<3>(file); - // check if the file can be deleted - auto iter = ignore_files.find(table_file.table_id_); - if (iter != ignore_files.end()) { - if (iter->second.find(table_file.file_id_) != iter->second.end()) { - ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ - << " currently is in use, not able to erase from cache now"; - continue; // ignore this file, don't delete it - } + // check if the file can be erased + if (filter && filter->IsIgnored(table_file)) { + ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ + << " currently is in use, not able to erase from cache now"; + continue; // ignore this file, don't erase it } // erase file data from cache @@ -1350,7 +1347,7 @@ SqliteMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignor } Status -SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) { +SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { auto now = utils::GetMicroSecTimeStamp(); std::set table_ids; @@ -1382,13 +1379,10 @@ SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignor table_file.date_ = std::get<3>(file); // check if the file can be deleted - auto iter = ignore_files.find(table_file.table_id_); - if (iter != ignore_files.end()) { - if (iter->second.find(table_file.file_id_) != iter->second.end()) { - ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ - << " currently is in use, not able to delete now"; - continue; // ignore this file, don't delete it - } + if (filter && filter->IsIgnored(table_file)) { + ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ + << " currently is in use, not able to delete now"; + continue; // ignore this file, don't delete it } // delete file from meta diff --git a/core/src/db/meta/SqliteMetaImpl.h b/core/src/db/meta/SqliteMetaImpl.h index 4ef4542022..16bbc0a205 100644 --- a/core/src/db/meta/SqliteMetaImpl.h +++ b/core/src/db/meta/SqliteMetaImpl.h @@ -120,10 +120,10 @@ class SqliteMetaImpl : public Meta { CleanUpShadowFiles() override; Status - CleanUpCacheWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) override; + CleanUpCacheWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) override; Status - CleanUpFilesWithTTL(uint64_t seconds, const Table2FileIDs& ignore_files) override; + CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) override; Status DropAll() override; diff --git a/core/unittest/db/test_meta.cpp b/core/unittest/db/test_meta.cpp index c2a9f8e8bc..b89c73c296 100644 --- a/core/unittest/db/test_meta.cpp +++ b/core/unittest/db/test_meta.cpp @@ -335,8 +335,7 @@ TEST_F(MetaTest, TABLE_FILES_TEST) { status = impl_->DropTable(table_id); ASSERT_TRUE(status.ok()); - milvus::engine::meta::Table2FileIDs ignore_files; - status = impl_->CleanUpFilesWithTTL(1UL, ignore_files); + status = impl_->CleanUpFilesWithTTL(1UL); ASSERT_TRUE(status.ok()); } diff --git a/core/unittest/db/test_meta_mysql.cpp b/core/unittest/db/test_meta_mysql.cpp index cdd8aa32a8..9a52a01b7b 100644 --- a/core/unittest/db/test_meta_mysql.cpp +++ b/core/unittest/db/test_meta_mysql.cpp @@ -349,8 +349,7 @@ TEST_F(MySqlMetaTest, TABLE_FILES_TEST) { status = impl_->DropTable(table_id); ASSERT_TRUE(status.ok()); - milvus::engine::meta::Table2FileIDs ignore_files; - status = impl_->CleanUpFilesWithTTL(0UL, ignore_files); + status = impl_->CleanUpFilesWithTTL(0UL); ASSERT_TRUE(status.ok()); } diff --git a/core/unittest/db/test_misc.cpp b/core/unittest/db/test_misc.cpp index 1ed02afb53..3e9d597c3f 100644 --- a/core/unittest/db/test_misc.cpp +++ b/core/unittest/db/test_misc.cpp @@ -20,6 +20,7 @@ #include "db/Options.h" #include "db/Utils.h" #include "db/engine/EngineFactory.h" +#include "db/meta/MetaTypes.h" #include "db/meta/SqliteMetaImpl.h" #include "utils/Exception.h" #include "utils/Status.h" @@ -161,25 +162,21 @@ TEST(DBMiscTest, CHECKER_TEST) { schema.file_id_ = "5000"; checker.MarkOngoingFile(schema); - auto ongoing_files = checker.GetOngoingFiles(); - ASSERT_EQ(ongoing_files.size(), 1UL); + ASSERT_TRUE(checker.IsIgnored(schema)); schema.table_id_ = "bbb"; schema.file_id_ = "5001"; milvus::engine::meta::TableFilesSchema table_files = {schema}; checker.MarkOngoingFiles(table_files); - ongoing_files = checker.GetOngoingFiles(); - ASSERT_EQ(ongoing_files.size(), 2UL); + ASSERT_TRUE(checker.IsIgnored(schema)); checker.UnmarkOngoingFile(schema); - ongoing_files = checker.GetOngoingFiles(); - ASSERT_EQ(ongoing_files.size(), 1UL); + ASSERT_FALSE(checker.IsIgnored(schema)); schema.table_id_ = "aaa"; schema.file_id_ = "5000"; checker.UnmarkOngoingFile(schema); - ongoing_files = checker.GetOngoingFiles(); - ASSERT_EQ(ongoing_files.size(), 0UL); + ASSERT_FALSE(checker.IsIgnored(schema)); } } From 22e86eb0a0ede3fc6a9eae3dc18f31500b40478e Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 29 Nov 2019 12:47:38 +0800 Subject: [PATCH 06/17] fix a bug --- core/src/db/OngoingFileChecker.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/db/OngoingFileChecker.cpp b/core/src/db/OngoingFileChecker.cpp index daaf6a2a4f..308649573d 100644 --- a/core/src/db/OngoingFileChecker.cpp +++ b/core/src/db/OngoingFileChecker.cpp @@ -108,15 +108,21 @@ OngoingFileChecker::UnmarkOngoingFileNoLock(const meta::TableFileSchema& table_f auto iter = ongoing_files_.find(table_file.table_id_); if (iter != ongoing_files_.end()) { - iter->second.erase(table_file.file_id_); - if (iter->second.empty()) { - ongoing_files_.erase(table_file.table_id_); + auto it_file = iter->second.find(table_file.file_id_); + if (it_file != iter->second.end()) { + it_file->second--; + + ENGINE_LOG_DEBUG << "Unmark ongoing file:" << table_file.file_id_ << " refcount:" << it_file->second; + + if (it_file->second <= 0) { + iter->second.erase(table_file.file_id_); + if (iter->second.empty()) { + ongoing_files_.erase(table_file.table_id_); + } + } } } - ENGINE_LOG_DEBUG << "Mark ongoing file:" << table_file.file_id_ - << " refcount:" << ongoing_files_[table_file.table_id_][table_file.file_id_]; - return Status::OK(); } From c220e0e1577eb96aac782a507a002bdf9c5b3545 Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 29 Nov 2019 16:18:57 +0800 Subject: [PATCH 07/17] refine code --- core/src/db/IndexFailedChecker.cpp | 4 ++-- core/src/db/IndexFailedChecker.h | 3 ++- core/src/db/OngoingFileChecker.cpp | 2 +- core/src/db/OngoingFileChecker.h | 3 ++- core/src/db/Types.h | 6 ++++++ core/src/db/engine/ExecutionEngineImpl.cpp | 2 ++ core/src/db/meta/MetaTypes.h | 4 ---- core/unittest/db/test_misc.cpp | 1 - 8 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/src/db/IndexFailedChecker.cpp b/core/src/db/IndexFailedChecker.cpp index bdd152dc4b..2ed22d75c4 100644 --- a/core/src/db/IndexFailedChecker.cpp +++ b/core/src/db/IndexFailedChecker.cpp @@ -38,7 +38,7 @@ IndexFailedChecker::GetFailedIndexFileOfTable(const std::string& table_id, std:: std::lock_guard lck(mutex_); auto iter = index_failed_files_.find(table_id); if (iter != index_failed_files_.end()) { - meta::File2RefCount& failed_map = iter->second; + File2RefCount& failed_map = iter->second; for (auto it_file = failed_map.begin(); it_file != failed_map.end(); ++it_file) { failed_files.push_back(it_file->first); } @@ -53,7 +53,7 @@ IndexFailedChecker::MarkFailedIndexFile(const meta::TableFileSchema& file) { auto iter = index_failed_files_.find(file.table_id_); if (iter == index_failed_files_.end()) { - meta::File2RefCount failed_files; + File2RefCount failed_files; failed_files.insert(std::make_pair(file.file_id_, 1)); index_failed_files_.insert(std::make_pair(file.table_id_, failed_files)); } else { diff --git a/core/src/db/IndexFailedChecker.h b/core/src/db/IndexFailedChecker.h index edd6a114bf..cf9ea990fe 100644 --- a/core/src/db/IndexFailedChecker.h +++ b/core/src/db/IndexFailedChecker.h @@ -17,6 +17,7 @@ #pragma once +#include "db/Types.h" #include "meta/Meta.h" #include "utils/Status.h" @@ -47,7 +48,7 @@ class IndexFailedChecker { private: std::mutex mutex_; - meta::Table2Files index_failed_files_; // table id mapping to (file id mapping to failed times) + Table2Files index_failed_files_; // table id mapping to (file id mapping to failed times) }; } // namespace engine diff --git a/core/src/db/OngoingFileChecker.cpp b/core/src/db/OngoingFileChecker.cpp index 308649573d..3c3eb4011a 100644 --- a/core/src/db/OngoingFileChecker.cpp +++ b/core/src/db/OngoingFileChecker.cpp @@ -82,7 +82,7 @@ OngoingFileChecker::MarkOngoingFileNoLock(const meta::TableFileSchema& table_fil auto iter = ongoing_files_.find(table_file.table_id_); if (iter == ongoing_files_.end()) { - meta::File2RefCount files_refcount; + File2RefCount files_refcount; files_refcount.insert(std::make_pair(table_file.file_id_, 1)); ongoing_files_.insert(std::make_pair(table_file.table_id_, files_refcount)); } else { diff --git a/core/src/db/OngoingFileChecker.h b/core/src/db/OngoingFileChecker.h index c7995e425a..2e52fdeea6 100644 --- a/core/src/db/OngoingFileChecker.h +++ b/core/src/db/OngoingFileChecker.h @@ -17,6 +17,7 @@ #pragma once +#include "db/Types.h" #include "meta/Meta.h" #include "utils/Status.h" @@ -54,7 +55,7 @@ class OngoingFileChecker : public meta::Meta::CleanUpFilter { private: std::mutex mutex_; - meta::Table2Files ongoing_files_; // table id mapping to (file id mapping to ongoing ref-count) + Table2Files ongoing_files_; // table id mapping to (file id mapping to ongoing ref-count) }; } // namespace engine diff --git a/core/src/db/Types.h b/core/src/db/Types.h index 76c06126f8..ca6f97849a 100644 --- a/core/src/db/Types.h +++ b/core/src/db/Types.h @@ -21,6 +21,9 @@ #include #include +#include +#include +#include #include #include @@ -40,5 +43,8 @@ struct TableIndex { int32_t metric_type_ = (int)MetricType::L2; }; +using File2RefCount = std::map; +using Table2Files = std::map; + } // namespace engine } // namespace milvus diff --git a/core/src/db/engine/ExecutionEngineImpl.cpp b/core/src/db/engine/ExecutionEngineImpl.cpp index 5a3d6e5e2a..a2ef4c70d4 100644 --- a/core/src/db/engine/ExecutionEngineImpl.cpp +++ b/core/src/db/engine/ExecutionEngineImpl.cpp @@ -258,6 +258,7 @@ ExecutionEngineImpl::PhysicalSize() const { Status ExecutionEngineImpl::Serialize() { + ENGINE_LOG_DEBUG << "Serialize index size: " << index_->Size() << " to file: " << location_; auto status = write_index(index_, location_); // here we reset index size by file size, @@ -495,6 +496,7 @@ ExecutionEngineImpl::BuildIndex(const std::string& location, EngineType engine_t throw Exception(DB_ERROR, status.message()); } + ENGINE_LOG_DEBUG << "Sucessfully build index file: " << location << " size: " << to_index->Size(); return std::make_shared(to_index, location, engine_type, metric_type_, nlist_); } diff --git a/core/src/db/meta/MetaTypes.h b/core/src/db/meta/MetaTypes.h index f8c082032e..d98b74be7d 100644 --- a/core/src/db/meta/MetaTypes.h +++ b/core/src/db/meta/MetaTypes.h @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -98,9 +97,6 @@ using TableFileSchemaPtr = std::shared_ptr; using TableFilesSchema = std::vector; using DatePartionedTableFilesSchema = std::map; -using File2RefCount = std::map; -using Table2Files = std::map; - } // namespace meta } // namespace engine } // namespace milvus diff --git a/core/unittest/db/test_misc.cpp b/core/unittest/db/test_misc.cpp index 3e9d597c3f..326f705184 100644 --- a/core/unittest/db/test_misc.cpp +++ b/core/unittest/db/test_misc.cpp @@ -20,7 +20,6 @@ #include "db/Options.h" #include "db/Utils.h" #include "db/engine/EngineFactory.h" -#include "db/meta/MetaTypes.h" #include "db/meta/SqliteMetaImpl.h" #include "utils/Exception.h" #include "utils/Status.h" From 736c348cfc1c848d0843cb4e14bc41fa719763c5 Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 29 Nov 2019 17:20:16 +0800 Subject: [PATCH 08/17] add log --- core/src/db/DBImpl.cpp | 4 ++-- core/src/db/engine/ExecutionEngineImpl.cpp | 4 ++-- core/src/scheduler/task/BuildIndexTask.cpp | 13 +++++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index c88936a08e..1db686b5ba 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -792,12 +792,12 @@ DBImpl::BackgroundCompaction(std::set table_ids) { meta_ptr_->Archive(); { - uint64_t ttl = 1 * meta::SECOND; // default: file data will be erase from cache after few seconds + uint64_t ttl = 10 * meta::SECOND; // default: file data will be erase from cache after few seconds meta_ptr_->CleanUpCacheWithTTL(ttl, &ongoing_files_checker_); } { - uint64_t ttl = 1 * meta::SECOND; // default: file will be deleted after few seconds + uint64_t ttl = 20 * meta::SECOND; // default: file will be deleted after few seconds if (options_.mode_ == DBOptions::MODE::CLUSTER_WRITABLE) { ttl = meta::H_SEC; } diff --git a/core/src/db/engine/ExecutionEngineImpl.cpp b/core/src/db/engine/ExecutionEngineImpl.cpp index a2ef4c70d4..c81d5d8e54 100644 --- a/core/src/db/engine/ExecutionEngineImpl.cpp +++ b/core/src/db/engine/ExecutionEngineImpl.cpp @@ -258,12 +258,12 @@ ExecutionEngineImpl::PhysicalSize() const { Status ExecutionEngineImpl::Serialize() { - ENGINE_LOG_DEBUG << "Serialize index size: " << index_->Size() << " to file: " << location_; auto status = write_index(index_, location_); // here we reset index size by file size, // since some index type(such as SQ8) data size become smaller after serialized index_->set_size(PhysicalSize()); + ENGINE_LOG_DEBUG << "Finish serialize index file: " << location_ << " size: " << index_->Size(); return status; } @@ -496,7 +496,7 @@ ExecutionEngineImpl::BuildIndex(const std::string& location, EngineType engine_t throw Exception(DB_ERROR, status.message()); } - ENGINE_LOG_DEBUG << "Sucessfully build index file: " << location << " size: " << to_index->Size(); + ENGINE_LOG_DEBUG << "Finish build index file: " << location << " size: " << to_index->Size(); return std::make_shared(to_index, location, engine_type, metric_type_, nlist_); } diff --git a/core/src/scheduler/task/BuildIndexTask.cpp b/core/src/scheduler/task/BuildIndexTask.cpp index e952bd0938..681968c402 100644 --- a/core/src/scheduler/task/BuildIndexTask.cpp +++ b/core/src/scheduler/task/BuildIndexTask.cpp @@ -168,7 +168,10 @@ XBuildIndexTask::Execute() { // step 5: save index file try { - index->Serialize(); + status = index->Serialize(); + if (status.ok()) { + ENGINE_LOG_DEBUG << "Failed to serilize index file: " << status.message(); + } } catch (std::exception& ex) { // typical error: out of disk space or permition denied std::string msg = "Serialize index encounter exception: " + std::string(ex.what()); @@ -196,7 +199,13 @@ XBuildIndexTask::Execute() { origin_file.file_type_ = engine::meta::TableFileSchema::BACKUP; engine::meta::TableFilesSchema update_files = {table_file, origin_file}; - status = meta_ptr->UpdateTableFiles(update_files); + + if (table_file.file_size_ > 0) { // makesure index file is sucessfully serialized to disk + status = meta_ptr->UpdateTableFiles(update_files); + } else { + status = Status(DB_ERROR, "Illegal index file: out of disk space or memory"); + } + if (status.ok()) { ENGINE_LOG_DEBUG << "New index file " << table_file.file_id_ << " of size " << index->PhysicalSize() << " bytes" From 4a183c411678282b7e38a8d9eeedd64172a4461d Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 29 Nov 2019 17:27:01 +0800 Subject: [PATCH 09/17] add log --- core/src/cache/Cache.inl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/cache/Cache.inl b/core/src/cache/Cache.inl index 9ebec7cfdd..e5e0baf9e7 100644 --- a/core/src/cache/Cache.inl +++ b/core/src/cache/Cache.inl @@ -179,6 +179,11 @@ Cache::print() { } SERVER_LOG_DEBUG << "[Cache item count]: " << cache_count; +#if 0 + for (auto it = lru_.begin(); it != lru_.end(); ++it) { + SERVER_LOG_DEBUG << it->first; + } +#endif SERVER_LOG_DEBUG << "[Cache usage]: " << usage_ << " bytes"; SERVER_LOG_DEBUG << "[Cache capacity]: " << capacity_ << " bytes"; } From bc2dba26a289fa532ac82915e8d0829164cf5848 Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 29 Nov 2019 18:15:28 +0800 Subject: [PATCH 10/17] refine code --- core/src/cache/Cache.inl | 2 +- core/src/db/DBImpl.cpp | 24 ++++----- core/src/db/engine/ExecutionEngineImpl.cpp | 5 ++ core/src/db/meta/Meta.h | 3 -- core/src/db/meta/MySQLMetaImpl.cpp | 52 ++------------------ core/src/db/meta/MySQLMetaImpl.h | 3 -- core/src/db/meta/SqliteMetaImpl.cpp | 57 ++-------------------- core/src/db/meta/SqliteMetaImpl.h | 3 -- core/src/scheduler/task/BuildIndexTask.cpp | 16 +++--- 9 files changed, 35 insertions(+), 130 deletions(-) diff --git a/core/src/cache/Cache.inl b/core/src/cache/Cache.inl index e5e0baf9e7..a3acda41d2 100644 --- a/core/src/cache/Cache.inl +++ b/core/src/cache/Cache.inl @@ -179,7 +179,7 @@ Cache::print() { } SERVER_LOG_DEBUG << "[Cache item count]: " << cache_count; -#if 0 +#if 1 for (auto it = lru_.begin(); it != lru_.end(); ++it) { SERVER_LOG_DEBUG << it->first; } diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index 1db686b5ba..129a9e9928 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -705,20 +705,27 @@ DBImpl::MergeFiles(const std::string& table_id, const meta::DateT& date, const m // step 3: serialize to disk try { - index->Serialize(); + status = index->Serialize(); + if (status.ok()) { + ENGINE_LOG_ERROR << status.message(); + } } catch (std::exception& ex) { - // typical error: out of disk space or permition denied std::string msg = "Serialize merged index encounter exception: " + std::string(ex.what()); ENGINE_LOG_ERROR << msg; + status = Status(DB_ERROR, msg); + } + if (!status.ok()) { + // if failed to serialize merge file to disk + // typical error: out of disk space, out of memory or permition denied table_file.file_type_ = meta::TableFileSchema::TO_DELETE; status = meta_ptr_->UpdateTableFile(table_file); ENGINE_LOG_DEBUG << "Failed to update file to index, mark file: " << table_file.file_id_ << " to to_delete"; - std::cout << "ERROR: failed to persist merged index file: " << table_file.location_ - << ", possible out of disk space" << std::endl; + ENGINE_LOG_ERROR << "ERROR: failed to persist merged file: " << table_file.location_ + << ", possible out of disk space or memory"; - return Status(DB_ERROR, msg); + return status; } // step 4: update table files state @@ -792,12 +799,7 @@ DBImpl::BackgroundCompaction(std::set table_ids) { meta_ptr_->Archive(); { - uint64_t ttl = 10 * meta::SECOND; // default: file data will be erase from cache after few seconds - meta_ptr_->CleanUpCacheWithTTL(ttl, &ongoing_files_checker_); - } - - { - uint64_t ttl = 20 * meta::SECOND; // default: file will be deleted after few seconds + uint64_t ttl = 1 * meta::SECOND; // default: file will be deleted after few seconds if (options_.mode_ == DBOptions::MODE::CLUSTER_WRITABLE) { ttl = meta::H_SEC; } diff --git a/core/src/db/engine/ExecutionEngineImpl.cpp b/core/src/db/engine/ExecutionEngineImpl.cpp index c81d5d8e54..a87690c6d6 100644 --- a/core/src/db/engine/ExecutionEngineImpl.cpp +++ b/core/src/db/engine/ExecutionEngineImpl.cpp @@ -265,6 +265,11 @@ ExecutionEngineImpl::Serialize() { index_->set_size(PhysicalSize()); ENGINE_LOG_DEBUG << "Finish serialize index file: " << location_ << " size: " << index_->Size(); + if (index_->Size() == 0) { + std::string msg = "Failed to serialize file: " + location_ + " reason: out of disk space or memory"; + status = Status(DB_ERROR, msg); + } + return status; } diff --git a/core/src/db/meta/Meta.h b/core/src/db/meta/Meta.h index 8dabb58203..1929414fdc 100644 --- a/core/src/db/meta/Meta.h +++ b/core/src/db/meta/Meta.h @@ -127,9 +127,6 @@ class Meta { virtual Status CleanUpShadowFiles() = 0; - virtual Status - CleanUpCacheWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) = 0; - virtual Status CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) = 0; diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index 1fab7a0f77..7f7bd704d5 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -1782,55 +1782,6 @@ MySQLMetaImpl::CleanUpShadowFiles() { return Status::OK(); } -Status -MySQLMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, CleanUpFilter* filter) { - auto now = utils::GetMicroSecTimeStamp(); - - // erase deleted/backup files from cache - try { - server::MetricCollector metric; - - mysqlpp::ScopedConnection connectionPtr(*mysql_connection_pool_, safe_grab_); - - if (connectionPtr == nullptr) { - return Status(DB_ERROR, "Failed to connect to meta server(mysql)"); - } - - mysqlpp::Query query = connectionPtr->query(); - query << "SELECT id, table_id, file_id, date" - << " FROM " << META_TABLEFILES << " WHERE file_type IN (" << std::to_string(TableFileSchema::TO_DELETE) - << "," << std::to_string(TableFileSchema::BACKUP) << ")" - << " AND updated_time < " << std::to_string(now - seconds * US_PS) << ";"; - - mysqlpp::StoreQueryResult res = query.store(); - - TableFileSchema table_file; - std::vector idsToDelete; - - for (auto& resRow : res) { - table_file.id_ = resRow["id"]; // implicit conversion - resRow["table_id"].to_string(table_file.table_id_); - resRow["file_id"].to_string(table_file.file_id_); - table_file.date_ = resRow["date"]; - - // check if the file can be erased - if (filter && filter->IsIgnored(table_file)) { - ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ - << " currently is in use, not able to erase from cache now"; - continue; // ignore this file, don't erase it - } - - // erase file data from cache - utils::GetTableFilePath(options_, table_file); - server::CommonUtil::EraseFromCache(table_file.location_); - } - } catch (std::exception& e) { - return HandleException("GENERAL ERROR WHEN CLEANING UP FILES WITH TTL", e.what()); - } - - return Status::OK(); -} - Status MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { auto now = utils::GetMicroSecTimeStamp(); @@ -1876,6 +1827,9 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { utils::DeleteTableFilePath(options_, table_file); ENGINE_LOG_DEBUG << "Removing file id:" << table_file.id_ << " location:" << table_file.location_; + // erase file data from cache + server::CommonUtil::EraseFromCache(table_file.location_); + idsToDelete.emplace_back(std::to_string(table_file.id_)); table_ids.insert(table_file.table_id_); } diff --git a/core/src/db/meta/MySQLMetaImpl.h b/core/src/db/meta/MySQLMetaImpl.h index d2a94f6cd3..6d2e7cf4c2 100644 --- a/core/src/db/meta/MySQLMetaImpl.h +++ b/core/src/db/meta/MySQLMetaImpl.h @@ -119,9 +119,6 @@ class MySQLMetaImpl : public Meta { Status CleanUpShadowFiles() override; - Status - CleanUpCacheWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) override; - Status CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) override; diff --git a/core/src/db/meta/SqliteMetaImpl.cpp b/core/src/db/meta/SqliteMetaImpl.cpp index 9b63f122da..2a3867574f 100644 --- a/core/src/db/meta/SqliteMetaImpl.cpp +++ b/core/src/db/meta/SqliteMetaImpl.cpp @@ -1293,59 +1293,6 @@ SqliteMetaImpl::CleanUpShadowFiles() { return Status::OK(); } -Status -SqliteMetaImpl::CleanUpCacheWithTTL(uint64_t seconds, CleanUpFilter* filter) { - auto now = utils::GetMicroSecTimeStamp(); - - // erase deleted/backup files from cache - try { - server::MetricCollector metric; - - // multi-threads call sqlite update may get exception('bad logic', etc), so we add a lock here - std::lock_guard meta_lock(meta_mutex_); - - std::vector file_types = { - (int)TableFileSchema::TO_DELETE, - (int)TableFileSchema::BACKUP, - }; - - // collect files to be erased - auto files = ConnectorPtr->select(columns(&TableFileSchema::id_, - &TableFileSchema::table_id_, - &TableFileSchema::file_id_, - &TableFileSchema::date_), - where( - in(&TableFileSchema::file_type_, file_types) - and - c(&TableFileSchema::updated_time_) - < now - seconds * US_PS)); - - for (auto& file : files) { - TableFileSchema table_file; - 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.date_ = std::get<3>(file); - - // check if the file can be erased - if (filter && filter->IsIgnored(table_file)) { - ENGINE_LOG_DEBUG << "File:" << table_file.file_id_ - << " currently is in use, not able to erase from cache now"; - continue; // ignore this file, don't erase it - } - - // erase file data from cache - utils::GetTableFilePath(options_, table_file); - server::CommonUtil::EraseFromCache(table_file.location_); - } - - } catch (std::exception& e) { - return HandleException("Encounter exception when clean cache", e.what()); - } - - return Status::OK(); -} - Status SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { auto now = utils::GetMicroSecTimeStamp(); @@ -1390,6 +1337,10 @@ SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { // delete file from disk storage utils::DeleteTableFilePath(options_, table_file); + + // erase from cache + server::CommonUtil::EraseFromCache(table_file.location_); + ENGINE_LOG_DEBUG << "Removing file id:" << table_file.file_id_ << " location:" << table_file.location_; table_ids.insert(table_file.table_id_); } diff --git a/core/src/db/meta/SqliteMetaImpl.h b/core/src/db/meta/SqliteMetaImpl.h index 16bbc0a205..f50fa452f3 100644 --- a/core/src/db/meta/SqliteMetaImpl.h +++ b/core/src/db/meta/SqliteMetaImpl.h @@ -119,9 +119,6 @@ class SqliteMetaImpl : public Meta { Status CleanUpShadowFiles() override; - Status - CleanUpCacheWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) override; - Status CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) override; diff --git a/core/src/scheduler/task/BuildIndexTask.cpp b/core/src/scheduler/task/BuildIndexTask.cpp index 681968c402..b2d74e794b 100644 --- a/core/src/scheduler/task/BuildIndexTask.cpp +++ b/core/src/scheduler/task/BuildIndexTask.cpp @@ -170,22 +170,26 @@ XBuildIndexTask::Execute() { try { status = index->Serialize(); if (status.ok()) { - ENGINE_LOG_DEBUG << "Failed to serilize index file: " << status.message(); + ENGINE_LOG_ERROR << status.message(); } } catch (std::exception& ex) { - // typical error: out of disk space or permition denied std::string msg = "Serialize index encounter exception: " + std::string(ex.what()); ENGINE_LOG_ERROR << msg; + status = Status(DB_ERROR, msg); + } + if (!status.ok()) { + // if failed to serialize index file to disk + // typical error: out of disk space, out of memory or permition denied table_file.file_type_ = engine::meta::TableFileSchema::TO_DELETE; status = meta_ptr->UpdateTableFile(table_file); ENGINE_LOG_DEBUG << "Failed to update file to index, mark file: " << table_file.file_id_ << " to to_delete"; ENGINE_LOG_ERROR << "Failed to persist index file: " << table_file.location_ - << ", possible out of disk space"; + << ", possible out of disk space or memory"; build_index_job->BuildIndexDone(to_index_id_); - build_index_job->GetStatus() = Status(DB_ERROR, msg); + build_index_job->GetStatus() = status; to_index_engine_ = nullptr; return; } @@ -200,10 +204,8 @@ XBuildIndexTask::Execute() { engine::meta::TableFilesSchema update_files = {table_file, origin_file}; - if (table_file.file_size_ > 0) { // makesure index file is sucessfully serialized to disk + if (status.ok()) { // makesure index file is sucessfully serialized to disk status = meta_ptr->UpdateTableFiles(update_files); - } else { - status = Status(DB_ERROR, "Illegal index file: out of disk space or memory"); } if (status.ok()) { From 844feab9260c31da82c042cced6265a2d0f2dfc6 Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 29 Nov 2019 19:15:11 +0800 Subject: [PATCH 11/17] more log --- core/src/db/DBImpl.cpp | 2 +- core/src/scheduler/task/BuildIndexTask.cpp | 2 +- core/src/server/grpc_impl/request/InsertRequest.cpp | 4 +++- core/src/server/grpc_impl/request/SearchRequest.cpp | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index 129a9e9928..11f45501ce 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -706,7 +706,7 @@ DBImpl::MergeFiles(const std::string& table_id, const meta::DateT& date, const m // step 3: serialize to disk try { status = index->Serialize(); - if (status.ok()) { + if (!status.ok()) { ENGINE_LOG_ERROR << status.message(); } } catch (std::exception& ex) { diff --git a/core/src/scheduler/task/BuildIndexTask.cpp b/core/src/scheduler/task/BuildIndexTask.cpp index b2d74e794b..571bb279a3 100644 --- a/core/src/scheduler/task/BuildIndexTask.cpp +++ b/core/src/scheduler/task/BuildIndexTask.cpp @@ -169,7 +169,7 @@ XBuildIndexTask::Execute() { // step 5: save index file try { status = index->Serialize(); - if (status.ok()) { + if (!status.ok()) { ENGINE_LOG_ERROR << status.message(); } } catch (std::exception& ex) { diff --git a/core/src/server/grpc_impl/request/InsertRequest.cpp b/core/src/server/grpc_impl/request/InsertRequest.cpp index f436db074e..16d16ca8dc 100644 --- a/core/src/server/grpc_impl/request/InsertRequest.cpp +++ b/core/src/server/grpc_impl/request/InsertRequest.cpp @@ -45,7 +45,9 @@ InsertRequest::Create(const ::milvus::grpc::InsertParam* insert_param, ::milvus: Status InsertRequest::OnExecute() { try { - TimeRecorder rc("InsertRequest"); + std::string hdr = "InsertRequest(table=" + insert_param_->table_name() + + ", n=" + std::to_string(insert_param_->row_record_array_size()) + ")"; + TimeRecorder rc(hdr); // step 1: check arguments auto status = ValidationUtil::ValidateTableName(insert_param_->table_name()); diff --git a/core/src/server/grpc_impl/request/SearchRequest.cpp b/core/src/server/grpc_impl/request/SearchRequest.cpp index 28f4ff723e..db0a55d48e 100644 --- a/core/src/server/grpc_impl/request/SearchRequest.cpp +++ b/core/src/server/grpc_impl/request/SearchRequest.cpp @@ -51,7 +51,9 @@ SearchRequest::OnExecute() { int64_t top_k = search_param_->topk(); int64_t nprobe = search_param_->nprobe(); - std::string hdr = "SearchRequest(k=" + std::to_string(top_k) + ", nprob=" + std::to_string(nprobe) + ")"; + std::string hdr = "SearchRequest(table=" + search_param_->table_name() + + ", nq=" + std::to_string(search_param_->query_record_array_size()) + + ", k=" + std::to_string(top_k) + ", nprob=" + std::to_string(nprobe) + ")"; TimeRecorder rc(hdr); // step 1: check table name From 2e3caca4dacdfbbd4aadfe3c513bf3fc4923cdfe Mon Sep 17 00:00:00 2001 From: groot Date: Sat, 30 Nov 2019 15:38:14 +0800 Subject: [PATCH 12/17] more log --- core/src/cache/Cache.inl | 10 +++--- core/src/db/DBImpl.cpp | 16 ++++----- core/src/db/engine/ExecutionEngineImpl.cpp | 2 +- core/src/db/meta/MySQLMetaImpl.cpp | 28 ++++++++++----- core/src/db/meta/SqliteMetaImpl.cpp | 41 ++++++++++++++-------- core/src/utils/CommonUtil.cpp | 2 +- 6 files changed, 60 insertions(+), 39 deletions(-) diff --git a/core/src/cache/Cache.inl b/core/src/cache/Cache.inl index a3acda41d2..5b68e54249 100644 --- a/core/src/cache/Cache.inl +++ b/core/src/cache/Cache.inl @@ -176,14 +176,14 @@ Cache::print() { { std::lock_guard lock(mutex_); cache_count = lru_.size(); +#if 0 + for (auto it = lru_.begin(); it != lru_.end(); ++it) { + SERVER_LOG_DEBUG << it->first; + } +#endif } SERVER_LOG_DEBUG << "[Cache item count]: " << cache_count; -#if 1 - for (auto it = lru_.begin(); it != lru_.end(); ++it) { - SERVER_LOG_DEBUG << it->first; - } -#endif SERVER_LOG_DEBUG << "[Cache usage]: " << usage_ << " bytes"; SERVER_LOG_DEBUG << "[Cache capacity]: " << capacity_ << " bytes"; } diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index 11f45501ce..c5e04fb5c6 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -722,7 +722,7 @@ DBImpl::MergeFiles(const std::string& table_id, const meta::DateT& date, const m status = meta_ptr_->UpdateTableFile(table_file); ENGINE_LOG_DEBUG << "Failed to update file to index, mark file: " << table_file.file_id_ << " to to_delete"; - ENGINE_LOG_ERROR << "ERROR: failed to persist merged file: " << table_file.location_ + ENGINE_LOG_ERROR << "Failed to persist merged file: " << table_file.location_ << ", possible out of disk space or memory"; return status; @@ -803,6 +803,7 @@ DBImpl::BackgroundCompaction(std::set table_ids) { if (options_.mode_ == DBOptions::MODE::CLUSTER_WRITABLE) { ttl = meta::H_SEC; } + meta_ptr_->CleanUpFilesWithTTL(ttl, &ongoing_files_checker_); } @@ -839,14 +840,13 @@ DBImpl::StartBuildIndexTask(bool force) { void DBImpl::BackgroundBuildIndex() { - // ENGINE_LOG_TRACE << "Background build index thread start"; - std::unique_lock lock(build_index_mutex_); meta::TableFilesSchema to_index_files; meta_ptr_->FilesToIndex(to_index_files); Status status = index_failed_checker_.IgnoreFailedIndexFiles(to_index_files); if (!to_index_files.empty()) { + ENGINE_LOG_DEBUG << "Background build index thread begin"; status = ongoing_files_checker_.MarkOngoingFiles(to_index_files); // step 2: put build index task to scheduler @@ -870,17 +870,15 @@ DBImpl::BackgroundBuildIndex() { index_failed_checker_.MarkFailedIndexFile(file_schema); } else { - index_failed_checker_.MarkSucceedIndexFile(file_schema); ENGINE_LOG_DEBUG << "Building index job " << job->id() << " succeed."; - } - } - status = ongoing_files_checker_.UnmarkOngoingFiles(to_index_files); + index_failed_checker_.MarkSucceedIndexFile(file_schema); + } + status = ongoing_files_checker_.UnmarkOngoingFile(file_schema); + } ENGINE_LOG_DEBUG << "Background build index thread finished"; } - - // ENGINE_LOG_TRACE << "Background build index thread exit"; } Status diff --git a/core/src/db/engine/ExecutionEngineImpl.cpp b/core/src/db/engine/ExecutionEngineImpl.cpp index a87690c6d6..6bb0b97817 100644 --- a/core/src/db/engine/ExecutionEngineImpl.cpp +++ b/core/src/db/engine/ExecutionEngineImpl.cpp @@ -463,7 +463,7 @@ ExecutionEngineImpl::Merge(const std::string& location) { if (auto file_index = std::dynamic_pointer_cast(to_merge)) { auto status = index_->Add(file_index->Count(), file_index->GetRawVectors(), file_index->GetRawIds()); if (!status.ok()) { - ENGINE_LOG_ERROR << "Merge: Add Error"; + ENGINE_LOG_ERROR << "Failed to merge: " << location << " to: " << location_; } return status; } else { diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index 7f7bd704d5..96e7109c93 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -1800,7 +1800,9 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { mysqlpp::Query query = connectionPtr->query(); query << "SELECT id, table_id, file_id, date" - << " FROM " << META_TABLEFILES << " WHERE file_type = " << std::to_string(TableFileSchema::TO_DELETE) + << " FROM " << META_TABLEFILES << " WHERE file_type IN (" + << std::to_string(TableFileSchema::TO_DELETE) << "," + << std::to_string(TableFileSchema::BACKUP) << ")" << " AND updated_time < " << std::to_string(now - seconds * US_PS) << ";"; ENGINE_LOG_DEBUG << "MySQLMetaImpl::CleanUpFilesWithTTL: " << query.str(); @@ -1810,11 +1812,13 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { TableFileSchema table_file; std::vector idsToDelete; + int64_t clean_files = 0; for (auto& resRow : res) { table_file.id_ = resRow["id"]; // implicit conversion resRow["table_id"].to_string(table_file.table_id_); resRow["file_id"].to_string(table_file.file_id_); table_file.date_ = resRow["date"]; + table_file.file_type_ = resRow["file_type"]; // check if the file can be deleted if (filter && filter->IsIgnored(table_file)) { @@ -1823,15 +1827,21 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { continue; // ignore this file, don't delete it } - // delete file from disk storage - utils::DeleteTableFilePath(options_, table_file); - ENGINE_LOG_DEBUG << "Removing file id:" << table_file.id_ << " location:" << table_file.location_; - // erase file data from cache + // because GetTableFilePath won't able to generate file path after the file is deleted + utils::GetTableFilePath(options_, table_file); server::CommonUtil::EraseFromCache(table_file.location_); - idsToDelete.emplace_back(std::to_string(table_file.id_)); - table_ids.insert(table_file.table_id_); + if (table_file.file_type_ == (int)TableFileSchema::TO_DELETE) { + // delete file from disk storage + utils::DeleteTableFilePath(options_, table_file); + ENGINE_LOG_DEBUG << "Removing file id:" << table_file.id_ << " location:" << table_file.location_; + + idsToDelete.emplace_back(std::to_string(table_file.id_)); + table_ids.insert(table_file.table_id_); + } + + clean_files++; } // delete file from meta @@ -1852,8 +1862,8 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { } } - if (res.size() > 0) { - ENGINE_LOG_DEBUG << "Clean " << res.size() << " files deleted in " << seconds << " seconds"; + if (clean_files > 0) { + ENGINE_LOG_DEBUG << "Clean " << clean_files << " files deleted in " << seconds << " seconds"; } } // Scoped Connection } catch (std::exception& e) { diff --git a/core/src/db/meta/SqliteMetaImpl.cpp b/core/src/db/meta/SqliteMetaImpl.cpp index 2a3867574f..846655676d 100644 --- a/core/src/db/meta/SqliteMetaImpl.cpp +++ b/core/src/db/meta/SqliteMetaImpl.cpp @@ -1302,6 +1302,11 @@ SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { try { server::MetricCollector metric; + std::vector file_types = { + (int)TableFileSchema::TO_DELETE, + (int)TableFileSchema::BACKUP, + }; + // multi-threads call sqlite update may get exception('bad logic', etc), so we add a lock here std::lock_guard meta_lock(meta_mutex_); @@ -1309,21 +1314,23 @@ SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { auto files = ConnectorPtr->select(columns(&TableFileSchema::id_, &TableFileSchema::table_id_, &TableFileSchema::file_id_, + &TableFileSchema::file_type_, &TableFileSchema::date_), where( - c(&TableFileSchema::file_type_) == - (int)TableFileSchema::TO_DELETE + in(&TableFileSchema::file_type_, file_types) and c(&TableFileSchema::updated_time_) < now - seconds * US_PS)); + int64_t clean_files = 0; auto commited = ConnectorPtr->transaction([&]() mutable { TableFileSchema table_file; for (auto& file : files) { 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.date_ = std::get<3>(file); + table_file.file_type_ = std::get<3>(file); + table_file.date_ = std::get<4>(file); // check if the file can be deleted if (filter && filter->IsIgnored(table_file)) { @@ -1332,17 +1339,23 @@ SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { continue; // ignore this file, don't delete it } - // delete file from meta - ConnectorPtr->remove(table_file.id_); - - // delete file from disk storage - utils::DeleteTableFilePath(options_, table_file); - - // erase from cache + // erase from cache, must do this before file deleted, + // because GetTableFilePath won't able to generate file path after the file is deleted + utils::GetTableFilePath(options_, table_file); server::CommonUtil::EraseFromCache(table_file.location_); - ENGINE_LOG_DEBUG << "Removing file id:" << table_file.file_id_ << " location:" << table_file.location_; - table_ids.insert(table_file.table_id_); + if (table_file.file_type_ == (int)TableFileSchema::TO_DELETE) { + // delete file from meta + ConnectorPtr->remove(table_file.id_); + + // delete file from disk storage + utils::DeleteTableFilePath(options_, table_file); + + ENGINE_LOG_DEBUG << "Removing file id:" << table_file.file_id_ << " location:" << table_file.location_; + table_ids.insert(table_file.table_id_); + } + + clean_files++; } return true; }); @@ -1351,8 +1364,8 @@ SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { return HandleException("CleanUpFilesWithTTL error: sqlite transaction failed"); } - if (files.size() > 0) { - ENGINE_LOG_DEBUG << "Clean " << files.size() << " files deleted in " << seconds << " seconds"; + if (clean_files > 0) { + ENGINE_LOG_DEBUG << "Clean " << clean_files << " files deleted in " << seconds << " seconds"; } } catch (std::exception& e) { return HandleException("Encounter exception when clean table files", e.what()); diff --git a/core/src/utils/CommonUtil.cpp b/core/src/utils/CommonUtil.cpp index cfadb2fcc4..cdfae8f1e5 100644 --- a/core/src/utils/CommonUtil.cpp +++ b/core/src/utils/CommonUtil.cpp @@ -229,7 +229,7 @@ CommonUtil::ConvertTime(tm time_struct, time_t& time_integer) { void CommonUtil::EraseFromCache(const std::string& item_key) { if (item_key.empty()) { - // SERVER_LOG_ERROR << "Empty key cannot be erased from cache"; + SERVER_LOG_ERROR << "Empty key cannot be erased from cache"; return; } From 66b698186c16f15015f3bcd6f3b1b33f26394252 Mon Sep 17 00:00:00 2001 From: groot Date: Sat, 30 Nov 2019 16:19:37 +0800 Subject: [PATCH 13/17] modify log --- core/src/db/DBImpl.cpp | 2 +- core/src/db/meta/MySQLMetaImpl.cpp | 7 +++---- core/src/db/meta/SqliteMetaImpl.cpp | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index c5e04fb5c6..b51ce571fd 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -799,7 +799,7 @@ DBImpl::BackgroundCompaction(std::set table_ids) { meta_ptr_->Archive(); { - uint64_t ttl = 1 * meta::SECOND; // default: file will be deleted after few seconds + uint64_t ttl = 10 * meta::SECOND; // default: file will be hard-deleted few seconds after soft-deleted if (options_.mode_ == DBOptions::MODE::CLUSTER_WRITABLE) { ttl = meta::H_SEC; } diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index 96e7109c93..401ef62bbd 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -1801,8 +1801,7 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { mysqlpp::Query query = connectionPtr->query(); query << "SELECT id, table_id, file_id, date" << " FROM " << META_TABLEFILES << " WHERE file_type IN (" - << std::to_string(TableFileSchema::TO_DELETE) << "," - << std::to_string(TableFileSchema::BACKUP) << ")" + << std::to_string(TableFileSchema::TO_DELETE) << "," << std::to_string(TableFileSchema::BACKUP) << ")" << " AND updated_time < " << std::to_string(now - seconds * US_PS) << ";"; ENGINE_LOG_DEBUG << "MySQLMetaImpl::CleanUpFilesWithTTL: " << query.str(); @@ -1835,7 +1834,7 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { if (table_file.file_type_ == (int)TableFileSchema::TO_DELETE) { // delete file from disk storage utils::DeleteTableFilePath(options_, table_file); - ENGINE_LOG_DEBUG << "Removing file id:" << table_file.id_ << " location:" << table_file.location_; + ENGINE_LOG_DEBUG << "Remove file id:" << table_file.id_ << " location:" << table_file.location_; idsToDelete.emplace_back(std::to_string(table_file.id_)); table_ids.insert(table_file.table_id_); @@ -1863,7 +1862,7 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { } if (clean_files > 0) { - ENGINE_LOG_DEBUG << "Clean " << clean_files << " files deleted in " << seconds << " seconds"; + ENGINE_LOG_DEBUG << "Clean " << clean_files << " files expired in " << seconds << " seconds"; } } // Scoped Connection } catch (std::exception& e) { diff --git a/core/src/db/meta/SqliteMetaImpl.cpp b/core/src/db/meta/SqliteMetaImpl.cpp index 846655676d..c74212e6e7 100644 --- a/core/src/db/meta/SqliteMetaImpl.cpp +++ b/core/src/db/meta/SqliteMetaImpl.cpp @@ -1351,7 +1351,7 @@ SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { // delete file from disk storage utils::DeleteTableFilePath(options_, table_file); - ENGINE_LOG_DEBUG << "Removing file id:" << table_file.file_id_ << " location:" << table_file.location_; + ENGINE_LOG_DEBUG << "Remove file id:" << table_file.file_id_ << " location:" << table_file.location_; table_ids.insert(table_file.table_id_); } @@ -1365,7 +1365,7 @@ SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { } if (clean_files > 0) { - ENGINE_LOG_DEBUG << "Clean " << clean_files << " files deleted in " << seconds << " seconds"; + ENGINE_LOG_DEBUG << "Clean " << clean_files << " files expired in " << seconds << " seconds"; } } catch (std::exception& e) { return HandleException("Encounter exception when clean table files", e.what()); From 8ca2d52bff0c482fed854fa882339f50e659cb4c Mon Sep 17 00:00:00 2001 From: groot Date: Sat, 30 Nov 2019 17:02:40 +0800 Subject: [PATCH 14/17] fix mysql bug --- core/src/db/meta/MySQLMetaImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index 401ef62bbd..48bceca7d8 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -1799,7 +1799,7 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { } mysqlpp::Query query = connectionPtr->query(); - query << "SELECT id, table_id, file_id, date" + query << "SELECT id, table_id, file_id, file_type, date" << " FROM " << META_TABLEFILES << " WHERE file_type IN (" << std::to_string(TableFileSchema::TO_DELETE) << "," << std::to_string(TableFileSchema::BACKUP) << ")" << " AND updated_time < " << std::to_string(now - seconds * US_PS) << ";"; From 8862756d11f71899acc60aa168fa2308cf789089 Mon Sep 17 00:00:00 2001 From: groot Date: Mon, 2 Dec 2019 10:56:11 +0800 Subject: [PATCH 15/17] typo --- core/src/db/meta/MySQLMetaImpl.cpp | 4 ++-- core/src/db/meta/SqliteMetaImpl.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index 48bceca7d8..da91585b92 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -1838,9 +1838,9 @@ MySQLMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { idsToDelete.emplace_back(std::to_string(table_file.id_)); table_ids.insert(table_file.table_id_); - } - clean_files++; + clean_files++; + } } // delete file from meta diff --git a/core/src/db/meta/SqliteMetaImpl.cpp b/core/src/db/meta/SqliteMetaImpl.cpp index c74212e6e7..9e323a4fac 100644 --- a/core/src/db/meta/SqliteMetaImpl.cpp +++ b/core/src/db/meta/SqliteMetaImpl.cpp @@ -1353,9 +1353,9 @@ SqliteMetaImpl::CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter) { ENGINE_LOG_DEBUG << "Remove file id:" << table_file.file_id_ << " location:" << table_file.location_; table_ids.insert(table_file.table_id_); - } - clean_files++; + clean_files++; + } } return true; }); From b12f861b5113a9038cad5e24abda16ea15856fcf Mon Sep 17 00:00:00 2001 From: wxyu Date: Mon, 2 Dec 2019 11:17:24 +0800 Subject: [PATCH 16/17] Add a new rpc command to get milvus build version whether cpu or gpu close#644 --- CHANGELOG.md | 1 + core/src/server/grpc_impl/request/CmdRequest.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19a9c4519d..d78fe75cba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ Please mark all change in change log and use the ticket from JIRA. - \#502 - C++ SDK support IVFPQ and SPTAG - \#560 - Add version in server config file - \#605 - Print more messages when server start +- \#644 - Add a new rpc command to get milvus build version whether cpu or gpu ## Improvement - \#255 - Add ivfsq8 test report detailed version diff --git a/core/src/server/grpc_impl/request/CmdRequest.cpp b/core/src/server/grpc_impl/request/CmdRequest.cpp index b215f94d31..3afbe6d6e2 100644 --- a/core/src/server/grpc_impl/request/CmdRequest.cpp +++ b/core/src/server/grpc_impl/request/CmdRequest.cpp @@ -39,6 +39,12 @@ CmdRequest::OnExecute() { result_ = MILVUS_VERSION; } else if (cmd_ == "tasktable") { result_ = scheduler::ResMgrInst::GetInstance()->DumpTaskTables(); + } else if (cmd_ == "mode") { +#ifdef MILVUS_GPU_VERSION + result_ = "GPU"; +#else + result_ = "CPU"; +#endif } else { result_ = "OK"; } From 62b6db567d0990144b28b7e684b255d0cce2c030 Mon Sep 17 00:00:00 2001 From: groot Date: Mon, 2 Dec 2019 11:57:43 +0800 Subject: [PATCH 17/17] add more logs --- core/src/db/DBImpl.cpp | 1 - core/src/db/engine/ExecutionEngineImpl.cpp | 2 ++ core/src/server/grpc_impl/request/CmdRequest.cpp | 5 +++++ core/src/server/grpc_impl/request/CountTableRequest.cpp | 3 ++- core/src/server/grpc_impl/request/CreateIndexRequest.cpp | 3 ++- .../src/server/grpc_impl/request/CreatePartitionRequest.cpp | 6 +++++- core/src/server/grpc_impl/request/CreateTableRequest.cpp | 5 ++++- core/src/server/grpc_impl/request/DescribeIndexRequest.cpp | 3 ++- core/src/server/grpc_impl/request/DescribeTableRequest.cpp | 3 ++- core/src/server/grpc_impl/request/DropIndexRequest.cpp | 3 ++- core/src/server/grpc_impl/request/DropPartitionRequest.cpp | 5 +++++ core/src/server/grpc_impl/request/DropTableRequest.cpp | 3 ++- core/src/server/grpc_impl/request/HasTableRequest.cpp | 3 ++- core/src/server/grpc_impl/request/InsertRequest.cpp | 3 ++- core/src/server/grpc_impl/request/PreloadTableRequest.cpp | 3 ++- core/src/server/grpc_impl/request/ShowPartitionsRequest.cpp | 3 +++ core/src/server/grpc_impl/request/ShowTablesRequest.cpp | 2 ++ 17 files changed, 44 insertions(+), 12 deletions(-) diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index 779e1b731f..8f8516770f 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -695,7 +695,6 @@ DBImpl::MergeFiles(const std::string& table_id, const meta::DateT& date, const m auto file_schema = file; file_schema.file_type_ = meta::TableFileSchema::TO_DELETE; updated.push_back(file_schema); - ENGINE_LOG_DEBUG << "Merging file " << file_schema.file_id_; index_size = index->Size(); if (index_size >= file_schema.index_file_size_) { diff --git a/core/src/db/engine/ExecutionEngineImpl.cpp b/core/src/db/engine/ExecutionEngineImpl.cpp index 9464d66f28..f3fd4a67cf 100644 --- a/core/src/db/engine/ExecutionEngineImpl.cpp +++ b/core/src/db/engine/ExecutionEngineImpl.cpp @@ -472,6 +472,8 @@ ExecutionEngineImpl::Merge(const std::string& location) { auto status = index_->Add(file_index->Count(), file_index->GetRawVectors(), file_index->GetRawIds()); if (!status.ok()) { ENGINE_LOG_ERROR << "Failed to merge: " << location << " to: " << location_; + } else { + ENGINE_LOG_DEBUG << "Finish merge index file: " << location; } return status; } else { diff --git a/core/src/server/grpc_impl/request/CmdRequest.cpp b/core/src/server/grpc_impl/request/CmdRequest.cpp index b215f94d31..e3e2c06ad8 100644 --- a/core/src/server/grpc_impl/request/CmdRequest.cpp +++ b/core/src/server/grpc_impl/request/CmdRequest.cpp @@ -17,6 +17,8 @@ #include "server/grpc_impl/request/CmdRequest.h" #include "scheduler/SchedInst.h" +#include "utils/Log.h" +#include "utils/TimeRecorder.h" #include @@ -35,6 +37,9 @@ CmdRequest::Create(const std::string& cmd, std::string& result) { Status CmdRequest::OnExecute() { + std::string hdr = "CmdRequest(cmd=" + cmd_ + ")"; + TimeRecorder rc(hdr); + if (cmd_ == "version") { result_ = MILVUS_VERSION; } else if (cmd_ == "tasktable") { diff --git a/core/src/server/grpc_impl/request/CountTableRequest.cpp b/core/src/server/grpc_impl/request/CountTableRequest.cpp index 8559890ad6..b90a33bf61 100644 --- a/core/src/server/grpc_impl/request/CountTableRequest.cpp +++ b/core/src/server/grpc_impl/request/CountTableRequest.cpp @@ -39,7 +39,8 @@ CountTableRequest::Create(const std::string& table_name, int64_t& row_count) { Status CountTableRequest::OnExecute() { try { - TimeRecorder rc("CountTableRequest"); + std::string hdr = "CountTableRequest(table=" + table_name_ + ")"; + TimeRecorder rc(hdr); // step 1: check arguments auto status = ValidationUtil::ValidateTableName(table_name_); diff --git a/core/src/server/grpc_impl/request/CreateIndexRequest.cpp b/core/src/server/grpc_impl/request/CreateIndexRequest.cpp index 72678aee87..c7628048ff 100644 --- a/core/src/server/grpc_impl/request/CreateIndexRequest.cpp +++ b/core/src/server/grpc_impl/request/CreateIndexRequest.cpp @@ -44,7 +44,8 @@ CreateIndexRequest::Create(const ::milvus::grpc::IndexParam* index_param) { Status CreateIndexRequest::OnExecute() { try { - TimeRecorder rc("CreateIndexRequest"); + std::string hdr = "CreateIndexRequest(table=" + index_param_->table_name() + ")"; + TimeRecorder rc(hdr); // step 1: check arguments std::string table_name_ = index_param_->table_name(); diff --git a/core/src/server/grpc_impl/request/CreatePartitionRequest.cpp b/core/src/server/grpc_impl/request/CreatePartitionRequest.cpp index 3bd4a86ef6..1a18cdfcad 100644 --- a/core/src/server/grpc_impl/request/CreatePartitionRequest.cpp +++ b/core/src/server/grpc_impl/request/CreatePartitionRequest.cpp @@ -22,6 +22,7 @@ #include "utils/ValidationUtil.h" #include +#include namespace milvus { namespace server { @@ -42,7 +43,10 @@ CreatePartitionRequest::Create(const ::milvus::grpc::PartitionParam* partition_p Status CreatePartitionRequest::OnExecute() { - TimeRecorder rc("CreatePartitionRequest"); + std::string hdr = "CreatePartitionRequest(table=" + partition_param_->table_name() + + ", partition_name=" + partition_param_->partition_name() + + ", partition_tag=" + partition_param_->tag() + ")"; + TimeRecorder rc(hdr); try { // step 1: check arguments diff --git a/core/src/server/grpc_impl/request/CreateTableRequest.cpp b/core/src/server/grpc_impl/request/CreateTableRequest.cpp index 67a3eaa877..55d953aa6f 100644 --- a/core/src/server/grpc_impl/request/CreateTableRequest.cpp +++ b/core/src/server/grpc_impl/request/CreateTableRequest.cpp @@ -22,6 +22,7 @@ #include "utils/ValidationUtil.h" #include +#include namespace milvus { namespace server { @@ -42,7 +43,9 @@ CreateTableRequest::Create(const ::milvus::grpc::TableSchema* schema) { Status CreateTableRequest::OnExecute() { - TimeRecorder rc("CreateTableRequest"); + std::string hdr = "CreateTableRequest(table=" + schema_->table_name() + + ", dimension=" + std::to_string(schema_->dimension()) + ")"; + TimeRecorder rc(hdr); try { // step 1: check arguments diff --git a/core/src/server/grpc_impl/request/DescribeIndexRequest.cpp b/core/src/server/grpc_impl/request/DescribeIndexRequest.cpp index b3a987c6b0..d57d47bf2c 100644 --- a/core/src/server/grpc_impl/request/DescribeIndexRequest.cpp +++ b/core/src/server/grpc_impl/request/DescribeIndexRequest.cpp @@ -39,7 +39,8 @@ DescribeIndexRequest::Create(const std::string& table_name, ::milvus::grpc::Inde Status DescribeIndexRequest::OnExecute() { try { - TimeRecorder rc("DescribeIndexRequest"); + std::string hdr = "DescribeIndexRequest(table=" + table_name_ + ")"; + TimeRecorder rc(hdr); // step 1: check arguments auto status = ValidationUtil::ValidateTableName(table_name_); diff --git a/core/src/server/grpc_impl/request/DescribeTableRequest.cpp b/core/src/server/grpc_impl/request/DescribeTableRequest.cpp index 28a5f327c5..3bd97ef7e8 100644 --- a/core/src/server/grpc_impl/request/DescribeTableRequest.cpp +++ b/core/src/server/grpc_impl/request/DescribeTableRequest.cpp @@ -38,7 +38,8 @@ DescribeTableRequest::Create(const std::string& table_name, ::milvus::grpc::Tabl Status DescribeTableRequest::OnExecute() { - TimeRecorder rc("DescribeTableRequest"); + std::string hdr = "DescribeTableRequest(table=" + table_name_ + ")"; + TimeRecorder rc(hdr); try { // step 1: check arguments diff --git a/core/src/server/grpc_impl/request/DropIndexRequest.cpp b/core/src/server/grpc_impl/request/DropIndexRequest.cpp index ab5c83b0e5..619ea753ba 100644 --- a/core/src/server/grpc_impl/request/DropIndexRequest.cpp +++ b/core/src/server/grpc_impl/request/DropIndexRequest.cpp @@ -39,7 +39,8 @@ DropIndexRequest::Create(const std::string& table_name) { Status DropIndexRequest::OnExecute() { try { - TimeRecorder rc("DropIndexRequest"); + std::string hdr = "DropIndexRequest(table=" + table_name_ + ")"; + TimeRecorder rc(hdr); // step 1: check arguments auto status = ValidationUtil::ValidateTableName(table_name_); diff --git a/core/src/server/grpc_impl/request/DropPartitionRequest.cpp b/core/src/server/grpc_impl/request/DropPartitionRequest.cpp index 0e29b6abe8..1ec189986a 100644 --- a/core/src/server/grpc_impl/request/DropPartitionRequest.cpp +++ b/core/src/server/grpc_impl/request/DropPartitionRequest.cpp @@ -39,6 +39,11 @@ DropPartitionRequest::Create(const ::milvus::grpc::PartitionParam* partition_par Status DropPartitionRequest::OnExecute() { + std::string hdr = "DropPartitionRequest(table=" + partition_param_->table_name() + + ", partition_name=" + partition_param_->partition_name() + + ", partition_tag=" + partition_param_->tag() + ")"; + TimeRecorder rc(hdr); + std::string table_name = partition_param_->table_name(); std::string partition_name = partition_param_->partition_name(); std::string partition_tag = partition_param_->tag(); diff --git a/core/src/server/grpc_impl/request/DropTableRequest.cpp b/core/src/server/grpc_impl/request/DropTableRequest.cpp index a678e5a6f6..6f81a5b2a0 100644 --- a/core/src/server/grpc_impl/request/DropTableRequest.cpp +++ b/core/src/server/grpc_impl/request/DropTableRequest.cpp @@ -40,7 +40,8 @@ DropTableRequest::Create(const std::string& table_name) { Status DropTableRequest::OnExecute() { try { - TimeRecorder rc("DropTableRequest"); + std::string hdr = "DropTableRequest(table=" + table_name_ + ")"; + TimeRecorder rc(hdr); // step 1: check arguments auto status = ValidationUtil::ValidateTableName(table_name_); diff --git a/core/src/server/grpc_impl/request/HasTableRequest.cpp b/core/src/server/grpc_impl/request/HasTableRequest.cpp index 2909c93056..434580efdf 100644 --- a/core/src/server/grpc_impl/request/HasTableRequest.cpp +++ b/core/src/server/grpc_impl/request/HasTableRequest.cpp @@ -39,7 +39,8 @@ HasTableRequest::Create(const std::string& table_name, bool& has_table) { Status HasTableRequest::OnExecute() { try { - TimeRecorder rc("HasTableRequest"); + std::string hdr = "HasTableRequest(table=" + table_name_ + ")"; + TimeRecorder rc(hdr); // step 1: check arguments auto status = ValidationUtil::ValidateTableName(table_name_); diff --git a/core/src/server/grpc_impl/request/InsertRequest.cpp b/core/src/server/grpc_impl/request/InsertRequest.cpp index 16d16ca8dc..df65c679ed 100644 --- a/core/src/server/grpc_impl/request/InsertRequest.cpp +++ b/core/src/server/grpc_impl/request/InsertRequest.cpp @@ -46,7 +46,8 @@ Status InsertRequest::OnExecute() { try { std::string hdr = "InsertRequest(table=" + insert_param_->table_name() + - ", n=" + std::to_string(insert_param_->row_record_array_size()) + ")"; + ", n=" + std::to_string(insert_param_->row_record_array_size()) + + ", partition_tag=" + insert_param_->partition_tag() + ")"; TimeRecorder rc(hdr); // step 1: check arguments diff --git a/core/src/server/grpc_impl/request/PreloadTableRequest.cpp b/core/src/server/grpc_impl/request/PreloadTableRequest.cpp index e26aa8a877..3c46524afe 100644 --- a/core/src/server/grpc_impl/request/PreloadTableRequest.cpp +++ b/core/src/server/grpc_impl/request/PreloadTableRequest.cpp @@ -39,7 +39,8 @@ PreloadTableRequest::Create(const std::string& table_name) { Status PreloadTableRequest::OnExecute() { try { - TimeRecorder rc("PreloadTableRequest"); + std::string hdr = "PreloadTableRequest(table=" + table_name_ + ")"; + TimeRecorder rc(hdr); // step 1: check arguments auto status = ValidationUtil::ValidateTableName(table_name_); diff --git a/core/src/server/grpc_impl/request/ShowPartitionsRequest.cpp b/core/src/server/grpc_impl/request/ShowPartitionsRequest.cpp index 32fa0672c5..0d0809b171 100644 --- a/core/src/server/grpc_impl/request/ShowPartitionsRequest.cpp +++ b/core/src/server/grpc_impl/request/ShowPartitionsRequest.cpp @@ -40,6 +40,9 @@ ShowPartitionsRequest::Create(const std::string& table_name, ::milvus::grpc::Par Status ShowPartitionsRequest::OnExecute() { + std::string hdr = "ShowPartitionsRequest(table=" + table_name_ + ")"; + TimeRecorder rc(hdr); + auto status = ValidationUtil::ValidateTableName(table_name_); if (!status.ok()) { return status; diff --git a/core/src/server/grpc_impl/request/ShowTablesRequest.cpp b/core/src/server/grpc_impl/request/ShowTablesRequest.cpp index 90dbad981f..404e08197e 100644 --- a/core/src/server/grpc_impl/request/ShowTablesRequest.cpp +++ b/core/src/server/grpc_impl/request/ShowTablesRequest.cpp @@ -38,6 +38,8 @@ ShowTablesRequest::Create(::milvus::grpc::TableNameList* table_name_list) { Status ShowTablesRequest::OnExecute() { + TimeRecorder rc("ShowTablesRequest"); + std::vector schema_array; auto statuts = DBWrapper::DB()->AllTables(schema_array); if (!statuts.ok()) {