提交 303d600e 编写于 作者: P peng.xu

feat(db): add build index api in db


Former-commit-id: dbd6da51e3c5fd666d7062798c0483c0f7fa7ffb
上级 06002a84
......@@ -44,6 +44,8 @@ public:
virtual Status Size(uint64_t& result) = 0;
virtual Status BuildIndex(const std::string& table_id) = 0;
virtual Status DropAll() = 0;
DB() = default;
......
......@@ -430,6 +430,11 @@ void DBImpl::StartBuildIndexTask() {
}
}
Status DBImpl::BuildIndex(const std::string& table_id) {
meta_ptr_->UpdateTableFilesToIndex(table_id);
return BuildIndexByTable(table_id);
}
Status DBImpl::BuildIndex(const meta::TableFileSchema& file) {
ExecutionEnginePtr to_index = EngineFactory::Build(file.dimension_, file.location_, (EngineType)file.engine_type_);
if(to_index == nullptr) {
......@@ -491,7 +496,27 @@ Status DBImpl::BuildIndex(const meta::TableFileSchema& file) {
return Status::OK();
}
Status DBImpl::BuildIndexByTable(const std::string& table_id) {
std::unique_ptr<std::mutex> lock(build_index_mutex_);
meta::TableFilesSchema to_index_files;
meta_ptr_->FilesToIndex(to_index_files);
Status status;
for (auto& file : to_index_files) {
status = BuildIndex(file);
if (!status.ok()) {
ENGINE_LOG_ERROR << "Building index for " << file.id_ << " failed: " << status.ToString();
return status;
}
ENGINE_LOG_DEBUG << "Sync building index for " << file.id_ << " passed";
}
return status;
}
void DBImpl::BackgroundBuildIndex() {
std::unique_ptr<std::mutex> lock(build_index_mutex_);
meta::TableFilesSchema to_index_files;
meta_ptr_->FilesToIndex(to_index_files);
Status status;
......
......@@ -82,6 +82,8 @@ class DBImpl : public DB {
Status Size(uint64_t &result) override;
Status BuildIndex(const std::string& table_id) override;
~DBImpl() override;
private:
......@@ -110,6 +112,8 @@ class DBImpl : public DB {
void StartBuildIndexTask();
void BackgroundBuildIndex();
Status
BuildIndexByTable(const std::string& table_id) {
Status
BuildIndex(const meta::TableFileSchema &);
......@@ -132,6 +136,8 @@ class DBImpl : public DB {
server::ThreadPool index_thread_pool_;
std::list<std::future<void>> index_thread_results_;
std::mutex build_index_mutex_;
}; // DBImpl
......
......@@ -791,6 +791,23 @@ Status DBMetaImpl::UpdateTableFile(TableFileSchema &file_schema) {
return Status::OK();
}
Status DBMetaImpl::UpdateTableFilesToIndex(const std::string& table_id) {
try {
ConnectorPtr->update_all(
set(
c(&TableFileSchema::file_type_) = (int) TableFileSchema::TO_INDEX
),
where(
c(&TableFileSchema::table_id_) == table_id and
c(&TableFileSchema::file_type_) == (int) TableFileSchema::RAW
));
} catch (std::exception &e) {
return HandleException("Encounter exception when update table files to to_index", e);
}
return Status::OK();
}
Status DBMetaImpl::UpdateTableFiles(TableFilesSchema &files) {
try {
MetricCollector metric;
......
......@@ -35,6 +35,8 @@ public:
const std::vector<size_t>& ids,
TableFilesSchema& table_files) override;
virtual Status UpdateTableFilesToIndex(const std::string& table_id) override;
virtual Status UpdateTableFile(TableFileSchema& file_schema) override;
virtual Status UpdateTableFiles(TableFilesSchema& files) override;
......
......@@ -39,6 +39,8 @@ public:
const std::vector<size_t>& ids,
TableFilesSchema& table_files) = 0;
virtual Status UpdateTableFilesToIndex(const std::string& table_id) = 0;
virtual Status UpdateTableFile(TableFileSchema& file_schema) = 0;
virtual Status UpdateTableFiles(TableFilesSchema& files) = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册