fix: clean up crash residue (#208)

This commit is contained in:
Qinren Zhou
2026-03-11 15:55:13 +08:00
committed by GitHub
parent ba86c1663d
commit 331933c75a
8 changed files with 865 additions and 22 deletions
+48 -15
View File
@@ -11,6 +11,7 @@
// 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 <cmath>
#include <cstdint>
#include <cstdlib>
#include <cstring>
@@ -1108,6 +1109,52 @@ std::string Doc::to_detail_string() const {
return oss.str();
}
struct Doc::ValueEqual {
template <typename T, typename U>
bool operator()(const T &, const U &) const {
return false;
}
template <typename T>
bool operator()(const T &a, const T &b) const {
return a == b;
}
bool operator()(float a, float b) const {
return std::fabs(a - b) < 1e-6f;
}
bool operator()(double a, double b) const {
return std::fabs(a - b) < 1e-9;
}
bool operator()(const std::vector<float16_t> &a,
const std::vector<float16_t> &b) const {
if (a.size() != b.size()) return false;
for (size_t i = 0; i < a.size(); ++i)
if (std::fabs(static_cast<float>(a[i]) - static_cast<float>(b[i])) >=
1e-3f)
return false;
return true;
}
bool operator()(const std::vector<float> &a,
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;
return true;
}
bool operator()(const std::vector<double> &a,
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;
return true;
}
};
bool Doc::operator==(const Doc &other) const {
// Compare basic fields
if (pk_ != other.pk_) {
@@ -1135,21 +1182,7 @@ bool Doc::operator==(const Doc &other) const {
}
// Use visitor to compare the actual values
bool values_equal = std::visit(
[](const auto &lhs, const auto &rhs) -> bool {
if constexpr (std::is_same_v<std::decay_t<decltype(lhs)>,
std::decay_t<decltype(rhs)>>) {
return lhs == rhs;
} else {
// This should not happen due to the index check above
return false;
}
},
field_value, it->second);
if (!values_equal) {
return false;
}
if (!std::visit(ValueEqual{}, field_value, it->second)) return false;
}
return true;
+21 -7
View File
@@ -3939,6 +3939,14 @@ VectorColumnIndexer::Ptr SegmentImpl::create_vector_indexer(
memory_vector_block_ids_[field_name] = 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 =
std::make_shared<VectorColumnIndexer>(index_file_path, field);
vector_column_params::ReadOptions options{true, true};
@@ -3958,6 +3966,13 @@ Status SegmentImpl::init_memory_components() {
// create and open memory forward block
auto mem_path = FileHelper::MakeForwardBlockPath(seg_path_, mem_block.id_,
!options_.enable_mmap_);
if (FileHelper::FileExists(mem_path)) {
LOG_WARN(
"ForwardBlock file[%s] already exists (possible crash residue); "
"cleaning and overwriting.",
mem_path.c_str());
FileHelper::RemoveFile(mem_path);
}
memory_store_ = std::make_shared<MemForwardStore>(
collection_schema_, mem_path,
options_.enable_mmap_ ? FileFormat::IPC : FileFormat::PARQUET,
@@ -4104,18 +4119,17 @@ Status SegmentImpl::recover() {
}
const auto added_docs = recovered_doc_count[0] + // INSERT
recovered_doc_count[1] + // UPDATE
recovered_doc_count[2]; // UPSERT
recovered_doc_count[1] + // UPSERT
recovered_doc_count[2]; // UPDATE
mem_block.max_doc_id_ += added_docs;
LOG_INFO(
"Recover from wal finished. total_recovered_doc_count[%zu] "
"insert[%zu] update[%zu] upsert[%zu] "
"delete[%zu] path[%s]",
"Recover from wal finished. total_recovered_doc_count[%zu] insert[%zu] "
"upsert[%zu] update[%zu] delete[%zu] path[%s]",
(size_t)total_recovered_doc_count,
(size_t)recovered_doc_count[0], // INSERT
(size_t)recovered_doc_count[1], // UPDATE
(size_t)recovered_doc_count[2], // UPSERT
(size_t)recovered_doc_count[1], // UPSERT
(size_t)recovered_doc_count[2], // UPDATE
(size_t)recovered_doc_count[3], // DELETE
wal_file_path.c_str());
+2
View File
@@ -294,6 +294,8 @@ class Doc {
static void read_from_buffer(const uint8_t *&data, void *dest, size_t size);
struct ValueEqual;
private:
std::string pk_;
float score_{0.0f};