diff --git a/cpp/src/db/DBImpl.cpp b/cpp/src/db/DBImpl.cpp index d8f894fbc8ed7f45c1060dc05422ceb54d2a1486..dd56f797558cc111e2d8e68b398d229c9e177ed0 100644 --- a/cpp/src/db/DBImpl.cpp +++ b/cpp/src/db/DBImpl.cpp @@ -363,6 +363,7 @@ Status DBImpl::MergeFiles(const std::string& table_id, const meta::DateT& date, const meta::TableFilesSchema& files) { ENGINE_LOG_DEBUG << "Merge files for table " << table_id; + //step 1: create table file meta::TableFileSchema table_file; table_file.table_id_ = table_id; table_file.date_ = date; @@ -374,6 +375,7 @@ Status DBImpl::MergeFiles(const std::string& table_id, const meta::DateT& date, return status; } + //step 2: merge files ExecutionEnginePtr index = EngineFactory::Build(table_file.dimension_, table_file.location_, (EngineType)table_file.engine_type_); @@ -397,9 +399,25 @@ Status DBImpl::MergeFiles(const std::string& table_id, const meta::DateT& date, if (index_size >= options_.index_trigger_size) break; } + //step 3: serialize to disk + try { + index->Serialize(); + } 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; + + 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"; - index->Serialize(); + std::cout << "ERROR: failed to persist merged index file: " << table_file.location_ + << ", possible out of disk space" << std::endl; + + return Status::Error(msg); + } + //step 4: update table files state if (index_size >= options_.index_trigger_size) { table_file.file_type_ = meta::TableFileSchema::TO_INDEX; } else {