Fix Vector Set Creation Live Lock#1846
Merged
Merged
Conversation
…r vector set creation to live lock; this fixes that by, should initial creation be necessary, switching to an exclusive acquisition iff the 'cheap' promotion fails
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a live-lock in the vector-set read/create path. Previously, threads acquired a shared lock and tried to optimistically promote to exclusive when a (re)create was needed; under contention many threads could repeatedly fail to promote, release, and retry, never making progress. Now, after a failed promotion, the next iteration acquires an exclusive lock outright (guaranteed to eventually succeed), preserving the cheap shared-then-promote path as the optimistic fast path. A symmetric change is applied to both ReadVectorIndex and ReadOrCreateVectorIndex.
Changes:
- Track a
takeExclusiveLockflag across retries; switch lock acquisition based on it. - On failed promotion, release the shared lock and demand an exclusive lock on the next iteration.
- If an exclusive lock was acquired but recreate is no longer required, drop it back to shared via a retry instead of doing work under exclusive.
…, needs a refactor
…adOptimizedLock; cleanup VectorSet locking as part of adopting type
…m/microsoft/garnet into users/kmontrose/vectorSetLiveLock
badrishc
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We don't know if we're going to create (or recreate) a Vector Set when a VXXX command comes in, so we first take a shared lock and then try to promote to an exclusive lock if we determine we need to.
However, promotion can fail if there are other active shared or exclusive locks. Under contention this can cause a live lock, where separate threads are each acquiring a shared lock, failing to promote, releasing the shared lock, and retrying.
This PR fixes the live lock by switching to an initial exclusive lock if the last iteration failed to promote to an exclusive lock. Acquiring an exclusive lock will always eventually succeed, but may burn a lot of CPU doing so - so we still try to promote as an optimistic and cheap fast-er path during index (re)creation.