Skip to content

Commit 5e28cb6

Browse files
JoanFMmeiravgri
andcommitted
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 <meirav.grimberg@redis.com> (cherry picked from commit 42fdc90)
1 parent 7c58b3e commit 5e28cb6

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

src/VecSim/vec_sim_tiered_index.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,22 @@ VecSimDebugInfoIterator *VecSimTieredIndex<DataType, DistType>::debugInfoIterato
420420
.fieldType = INFOFIELD_UINT64,
421421
.fieldValue = {FieldValue{.uintegerValue = info.tieredInfo.bufferLimit}}});
422422

423-
infoIterator->addInfoField(VecSim_InfoField{
424-
.fieldName = VecSimCommonStrings::FRONTEND_INDEX_STRING,
425-
.fieldType = INFOFIELD_ITERATOR,
426-
.fieldValue = {FieldValue{.iteratorValue = this->frontendIndex->debugInfoIterator()}}});
423+
// Acquire shared locks to safely access each sub-index's debug info during background indexing.
424+
// Only hold each lock while accessing its respective index to minimize contention.
425+
{
426+
std::shared_lock<std::shared_mutex> flat_lock(this->flatIndexGuard);
427+
infoIterator->addInfoField(VecSim_InfoField{
428+
.fieldName = VecSimCommonStrings::FRONTEND_INDEX_STRING,
429+
.fieldType = INFOFIELD_ITERATOR,
430+
.fieldValue = {FieldValue{.iteratorValue = this->frontendIndex->debugInfoIterator()}}});
431+
}
427432

428-
infoIterator->addInfoField(VecSim_InfoField{
429-
.fieldName = VecSimCommonStrings::BACKEND_INDEX_STRING,
430-
.fieldType = INFOFIELD_ITERATOR,
431-
.fieldValue = {FieldValue{.iteratorValue = this->backendIndex->debugInfoIterator()}}});
433+
{
434+
std::shared_lock<std::shared_mutex> main_lock(this->mainIndexGuard);
435+
infoIterator->addInfoField(VecSim_InfoField{
436+
.fieldName = VecSimCommonStrings::BACKEND_INDEX_STRING,
437+
.fieldType = INFOFIELD_ITERATOR,
438+
.fieldValue = {FieldValue{.iteratorValue = this->backendIndex->debugInfoIterator()}}});
439+
}
432440
return infoIterator;
433441
};

0 commit comments

Comments
 (0)