Skip to content

Fix Vector Set Creation Live Lock#1846

Merged
kevin-montrose merged 8 commits into
mainfrom
users/kmontrose/vectorSetLiveLock
Jun 3, 2026
Merged

Fix Vector Set Creation Live Lock#1846
kevin-montrose merged 8 commits into
mainfrom
users/kmontrose/vectorSetLiveLock

Conversation

@kevin-montrose
Copy link
Copy Markdown
Contributor

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.

…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
Copilot AI review requested due to automatic review settings June 1, 2026 21:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 takeExclusiveLock flag 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.

Comment thread libs/server/Resp/Vector/VectorManager.Locking.cs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Comment thread libs/server/Resp/Vector/VectorManager.Locking.cs
Comment thread libs/server/Resp/Vector/VectorManager.Locking.cs
Comment thread libs/common/Synchronization/ReadOptimizedLock.cs
Comment thread libs/common/Synchronization/ReadOptimizedLock.cs Outdated
Comment thread libs/common/Synchronization/ReadOptimizedLock.cs Outdated
@kevin-montrose kevin-montrose merged commit f2b070a into main Jun 3, 2026
284 of 285 checks passed
@kevin-montrose kevin-montrose deleted the users/kmontrose/vectorSetLiveLock branch June 3, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants