mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
fix: Add padding for sorted index preventing 0 length mmap (#43663)
Related to #43655 This patch add a padding when writing mmap file for ScalarSortedIndex in case of mmap falure due to 0 mmap length. Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
parent
43c3c160ff
commit
f29964bd17
@ -40,6 +40,8 @@ const std::string STLSORT_INDEX_FILE_NAME = "stlsort-index";
|
||||
|
||||
constexpr size_t ALIGNMENT = 32; // 32-byte alignment
|
||||
|
||||
const uint64_t MMAP_INDEX_PADDING = 1;
|
||||
|
||||
template <typename T>
|
||||
ScalarIndexSort<T>::ScalarIndexSort(
|
||||
const storage::FileManagerContext& file_manager_context)
|
||||
@ -219,12 +221,19 @@ ScalarIndexSort<T>::LoadWithoutAssemble(const BinarySet& index_binary,
|
||||
0);
|
||||
file_writer.Write(padding.data(), padding.size());
|
||||
}
|
||||
// write padding in case of all null values
|
||||
std::vector<uint8_t> padding(MMAP_INDEX_PADDING, 0);
|
||||
file_writer.Write(padding.data(), padding.size());
|
||||
file_writer.Finish();
|
||||
}
|
||||
|
||||
auto file = File::Open(mmap_filepath_, O_RDONLY);
|
||||
mmap_data_ = static_cast<char*>(mmap(
|
||||
NULL, aligned_size, PROT_READ, MAP_PRIVATE, file.Descriptor(), 0));
|
||||
mmap_data_ = static_cast<char*>(mmap(NULL,
|
||||
aligned_size + MMAP_INDEX_PADDING,
|
||||
PROT_READ,
|
||||
MAP_PRIVATE,
|
||||
file.Descriptor(),
|
||||
0));
|
||||
|
||||
if (mmap_data_ == MAP_FAILED) {
|
||||
file.Close();
|
||||
@ -234,7 +243,7 @@ ScalarIndexSort<T>::LoadWithoutAssemble(const BinarySet& index_binary,
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
mmap_size_ = aligned_size;
|
||||
mmap_size_ = aligned_size + MMAP_INDEX_PADDING;
|
||||
data_size_ = index_data->size;
|
||||
|
||||
file.Close();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user