From 6e894361a4d9949e619c270bf2bf4ba13892821f Mon Sep 17 00:00:00 2001 From: Joan Fontanals Date: Wed, 25 Mar 2026 17:07:27 +0100 Subject: [PATCH] MOD-14618 Fix race condition when calling `indexLabelCount` on SVS without locks (#919) * proposal to fix flaky test * clarify scope * fiox preferAdHocSearch and add comment to indexLabelCount() * revert preferAdHocSearch --------- Co-authored-by: meiravgri (cherry picked from commit 42fdc908140236aea0ca359904f202080b935848) --- src/VecSim/vec_sim_tiered_index.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/VecSim/vec_sim_tiered_index.h b/src/VecSim/vec_sim_tiered_index.h index ae18b8571..1e7708765 100644 --- a/src/VecSim/vec_sim_tiered_index.h +++ b/src/VecSim/vec_sim_tiered_index.h @@ -420,14 +420,22 @@ VecSimDebugInfoIterator *VecSimTieredIndex::debugInfoIterato .fieldType = INFOFIELD_UINT64, .fieldValue = {FieldValue{.uintegerValue = info.tieredInfo.bufferLimit}}}); - infoIterator->addInfoField(VecSim_InfoField{ - .fieldName = VecSimCommonStrings::FRONTEND_INDEX_STRING, - .fieldType = INFOFIELD_ITERATOR, - .fieldValue = {FieldValue{.iteratorValue = this->frontendIndex->debugInfoIterator()}}}); + // Acquire shared locks to safely access each sub-index's debug info during background indexing. + // Only hold each lock while accessing its respective index to minimize contention. + { + std::shared_lock flat_lock(this->flatIndexGuard); + infoIterator->addInfoField(VecSim_InfoField{ + .fieldName = VecSimCommonStrings::FRONTEND_INDEX_STRING, + .fieldType = INFOFIELD_ITERATOR, + .fieldValue = {FieldValue{.iteratorValue = this->frontendIndex->debugInfoIterator()}}}); + } - infoIterator->addInfoField(VecSim_InfoField{ - .fieldName = VecSimCommonStrings::BACKEND_INDEX_STRING, - .fieldType = INFOFIELD_ITERATOR, - .fieldValue = {FieldValue{.iteratorValue = this->backendIndex->debugInfoIterator()}}}); + { + std::shared_lock main_lock(this->mainIndexGuard); + infoIterator->addInfoField(VecSim_InfoField{ + .fieldName = VecSimCommonStrings::BACKEND_INDEX_STRING, + .fieldType = INFOFIELD_ITERATOR, + .fieldValue = {FieldValue{.iteratorValue = this->backendIndex->debugInfoIterator()}}}); + } return infoIterator; };