From 94005b7198858b427e81edf2aaef2ca298ca4e5b Mon Sep 17 00:00:00 2001 From: Buqian Zheng Date: Mon, 30 Sep 2024 10:39:16 +0800 Subject: [PATCH] fix: Sparse float vector incorrectly ExpandData at mmap mode (#36603) issue: #36561 Signed-off-by: Buqian Zheng --- internal/core/src/mmap/Column.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/core/src/mmap/Column.h b/internal/core/src/mmap/Column.h index 37e6389cb8c76..7049c01f2e7b2 100644 --- a/internal/core/src/mmap/Column.h +++ b/internal/core/src/mmap/Column.h @@ -579,6 +579,19 @@ class SparseFloatColumn : public ColumnBase { size_t required_size = data_size_ + data->DataSize(); if (required_size > data_cap_size_) { ExpandData(required_size * 2); + // after expanding, the address of each row in vec_ become invalid. + // the number of elements of each row is still correct, update the + // address of each row to the new data_. + size_t bytes = 0; + for (size_t i = 0; i < num_rows_; i++) { + auto count = vec_[i].size(); + auto row_bytes = vec_[i].data_byte_size(); + // destroy the old object and placement new a new one + vec_[i].~SparseRow(); + new (&vec_[i]) knowhere::sparse::SparseRow( + count, (uint8_t*)(data_) + bytes, false); + bytes += row_bytes; + } } dim_ = std::max( dim_,