fix: recovery from crash during optimization (#246)

This commit is contained in:
Qinren Zhou
2026-03-24 10:53:16 +08:00
committed by GitHub
parent 209ef1fba8
commit ae345ad070
14 changed files with 420 additions and 53 deletions
+1 -1
View File
@@ -187,7 +187,7 @@ class BufferStorage : public IndexStorage {
}
//! Open storage
int open(const std::string &path, bool /*create*/) override {
int open(const std::string &path, bool /*create_if_missing*/) override {
file_name_ = path;
buffer_pool_ = std::make_shared<ailego::VecBufferPool>(path);
buffer_pool_handle_ = std::make_shared<ailego::VecBufferPoolHandle>(
+2 -2
View File
@@ -171,8 +171,8 @@ class MMapFileStorage : public IndexStorage {
}
//! Open storage
int open(const std::string &path, bool create) override {
if (!ailego::File::IsExist(path) && create) {
int open(const std::string &path, bool create_if_missing) override {
if (!ailego::File::IsExist(path) && create_if_missing) {
size_t last_slash = path.rfind('/');
if (last_slash != std::string::npos) {
ailego::File::MakePath(path.substr(0, last_slash));
+3 -3
View File
@@ -958,7 +958,7 @@ std::vector<SegmentTask::Ptr> CollectionImpl::build_compact_task(
if (current_actual_doc_count + actual_doc_count >
max_doc_count_per_segment) {
// only create SegmentCompactTask when rebuild=true
task = SegmentTask::CreateComapctTask(
task = SegmentTask::CreateCompactTask(
CompactTask{path_, schema, current_group,
allocate_segment_id_for_tmp_segment(), filter,
!options_.enable_mmap_, concurrency});
@@ -972,7 +972,7 @@ std::vector<SegmentTask::Ptr> CollectionImpl::build_compact_task(
current_group[0], "", nullptr, concurrency});
skip_task = current_group[0]->all_vector_index_ready();
} else {
task = SegmentTask::CreateComapctTask(
task = SegmentTask::CreateCompactTask(
CompactTask{path_, schema, current_group,
allocate_segment_id_for_tmp_segment(), nullptr,
!options_.enable_mmap_, concurrency});
@@ -1001,7 +1001,7 @@ std::vector<SegmentTask::Ptr> CollectionImpl::build_compact_task(
task = SegmentTask::CreateCreateVectorIndexTask(
CreateVectorIndexTask{current_group[0], "", nullptr, concurrency});
} else {
task = SegmentTask::CreateComapctTask(CompactTask{
task = SegmentTask::CreateCompactTask(CompactTask{
path_, schema, current_group, allocate_segment_id_for_tmp_segment(),
rebuild ? filter : nullptr, !options_.enable_mmap_, concurrency});
}
+2 -2
View File
@@ -1154,7 +1154,7 @@ struct Doc::ValueEqual {
const std::vector<float> &b) const {
if (a.size() != b.size()) return false;
for (size_t i = 0; i < a.size(); ++i)
if (std::fabs(a[i] - b[i]) >= 1e-6f) return false;
if (std::fabs(a[i] - b[i]) >= 1e-4f) return false;
return true;
}
@@ -1162,7 +1162,7 @@ struct Doc::ValueEqual {
const std::vector<double> &b) const {
if (a.size() != b.size()) return false;
for (size_t i = 0; i < a.size(); ++i)
if (std::fabs(a[i] - b[i]) >= 1e-9) return false;
if (std::fabs(a[i] - b[i]) >= 1e-6) return false;
return true;
}
};
+30 -2
View File
@@ -213,7 +213,7 @@ class SegmentImpl : public Segment,
const std::vector<int> &indices) const override;
ExecBatchPtr fetch(const std::vector<std::string> &columns,
int indice) const override;
int index) const override;
RecordBatchReaderPtr scan(
const std::vector<std::string> &columns) const override;
@@ -1631,6 +1631,13 @@ Status SegmentImpl::create_vector_index(
std::string index_file_path = FileHelper::MakeVectorIndexPath(
path_, column, segment_meta_->id(), block_id);
if (FileHelper::FileExists(index_file_path)) {
LOG_WARN(
"Index file[%s] already exists (possible crash residue); cleaning "
"and overwriting.",
index_file_path.c_str());
FileHelper::RemoveFile(index_file_path);
}
auto vector_indexer = merge_vector_indexer(
index_file_path, column, *field_with_new_index_params, concurrency);
if (!vector_indexer.has_value()) {
@@ -1668,6 +1675,13 @@ Status SegmentImpl::create_vector_index(
std::string index_file_path = FileHelper::MakeVectorIndexPath(
path_, column, segment_meta_->id(), block_id);
if (FileHelper::FileExists(index_file_path)) {
LOG_WARN(
"Index file[%s] already exists (possible crash residue); cleaning "
"and overwriting.",
index_file_path.c_str());
FileHelper::RemoveFile(index_file_path);
}
auto vector_indexer = merge_vector_indexer(index_file_path, column,
*field_with_flat, concurrency);
if (!vector_indexer.has_value()) {
@@ -1700,6 +1714,13 @@ Status SegmentImpl::create_vector_index(
std::string index_file_path = FileHelper::MakeQuantizeVectorIndexPath(
path_, column, segment_meta_->id(), quant_block_id);
if (FileHelper::FileExists(index_file_path)) {
LOG_WARN(
"Index file[%s] already exists (possible crash residue); cleaning "
"and overwriting.",
index_file_path.c_str());
FileHelper::RemoveFile(index_file_path);
}
auto vector_indexer = merge_vector_indexer(
index_file_path, column, *field_with_new_index_params, concurrency);
if (!vector_indexer.has_value()) {
@@ -1772,6 +1793,13 @@ Status SegmentImpl::create_vector_index(
std::string index_file_path = FileHelper::MakeQuantizeVectorIndexPath(
path_, column, segment_meta_->id(), quant_block_id);
if (FileHelper::FileExists(index_file_path)) {
LOG_WARN(
"Index file[%s] already exists (possible crash residue); cleaning "
"and overwriting.",
index_file_path.c_str());
FileHelper::RemoveFile(index_file_path);
}
auto vector_indexer = merge_vector_indexer(
index_file_path, column, *field_with_new_index_params, concurrency);
if (!vector_indexer.has_value()) {
@@ -2031,7 +2059,7 @@ Status SegmentImpl::create_scalar_index(const std::vector<std::string> &columns,
s = SegmentHelper::ReduceScalarIndex(new_scalar_indexer, batch_value,
accu_doc_count);
if (!s.ok()) {
LOG_ERROR("Reduce Scalar Index faield, err: %s", s.message().c_str());
LOG_ERROR("Reduce Scalar Index failed, err: %s", s.message().c_str());
}
CHECK_RETURN_STATUS(s);
+3 -3
View File
@@ -77,7 +77,7 @@ class Segment {
virtual Status drop_column(const std::string &column_name) = 0;
virtual Status create_all_vector_index(
int concurrency, SegmentMeta::Ptr *new_segmnet_meta,
int concurrency, SegmentMeta::Ptr *new_segment_meta,
std::unordered_map<std::string, VectorColumnIndexer::Ptr>
*vector_indexers,
std::unordered_map<std::string, VectorColumnIndexer::Ptr>
@@ -86,14 +86,14 @@ class Segment {
// defined in segment.h cause it needs to access block_id generator
virtual Status create_vector_index(
const std::string &column, const IndexParams::Ptr &index_params,
int concurrency, SegmentMeta::Ptr *new_segmnet_meta,
int concurrency, SegmentMeta::Ptr *new_segment_meta,
std::unordered_map<std::string, VectorColumnIndexer::Ptr>
*vector_indexers,
std::unordered_map<std::string, VectorColumnIndexer::Ptr>
*quant_vector_indexers) = 0;
virtual Status drop_vector_index(
const std::string &column, SegmentMeta::Ptr *new_segmnet_meta,
const std::string &column, SegmentMeta::Ptr *new_segment_meta,
std::unordered_map<std::string, VectorColumnIndexer::Ptr>
*vector_indexers) = 0;
+1 -1
View File
@@ -136,7 +136,7 @@ class SegmentTask {
std::variant<CompactTask, CreateVectorIndexTask, DropVectorIndexTask,
CreateScalarIndexTask, DropScalarIndexTask>;
static Ptr CreateComapctTask(const CompactTask &task) {
static Ptr CreateCompactTask(const CompactTask &task) {
return std::make_shared<SegmentTask>(task);
}
@@ -228,7 +228,7 @@ class IndexStorage : public IndexModule {
virtual int cleanup(void) = 0;
//! Open storage
virtual int open(const std::string &path, bool create) = 0;
virtual int open(const std::string &path, bool create_if_missing) = 0;
//! Flush storage
virtual int flush(void) = 0;