Skip to content

Fix VectorElementKey.IsPinned and drop_index calls while Vector Set in use#1871

Merged
badrishc merged 19 commits into
mainfrom
users/kmontrose/vectorElementKeyPinningFix
Jun 17, 2026
Merged

Fix VectorElementKey.IsPinned and drop_index calls while Vector Set in use#1871
badrishc merged 19 commits into
mainfrom
users/kmontrose/vectorElementKeyPinningFix

Conversation

@kevin-montrose

@kevin-montrose kevin-montrose commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Fixing VectorElementKey.IsPinned

NamespaceBytes is only pinned, currently, if the stack doesn't unwind - which isn't a safe assumption in the face of pending IO.

Either uses the space DiskANN provides before the key (for single read/write ops), or stackallocs space for VectorReadBatch which survives across GetKey(...) calls.

Fixing drop_index Calls While Vector Set In Use

Eviction (ie. moving a record to disk) can occur on an index key while a Vector Set is in use - today that dies horribly.

This change GarnetRecordTriggers.OnEvict to request a drop_index call rather than perform one - that call happens on a background task, under an exclusive lock (guaranteeing no DiskANN operations in progress), and recreation of the same index is blocked until it occurs.


Together these fix the issues found in Badrish's VADDLowMemoryStorageTierForcesDiskSpill test, which is also integrated as part of this PR.

…akes VectorElementKey.IsPinned => true actually correctly
Copilot AI review requested due to automatic review settings June 12, 2026 21:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes VectorElementKey.IsPinned correctness for pending IO by ensuring the key’s namespace bytes live in stable native/pinned memory (rather than stack-only lifetime), restoring the prior “namespace stored adjacent to key bytes” approach expected by the DiskANN interop paths.

Changes:

  • Updated VectorElementKey to carry namespace bytes via a ReadOnlySpan<byte>-based constructor (pointer-backed on !NET9) instead of a single stored byte.
  • Updated DiskANN callback/batch key materialization to write the namespace into reserved bytes immediately preceding the key data.
  • Adjusted vector-set tests to reset the “smashed” length-prefix byte after exercising VectorReadBatch.GetKey.

Reviewed changes

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

Show a summary per file
File Description
test/standalone/Garnet.test.vectorset/RespVectorSetTests.cs Updates tests to call CompletePending so in-place namespace writes don’t permanently corrupt the input buffer; removes an assertion in MakeVectorElementKey.
libs/server/Resp/Vector/VectorManager.Migration.cs Updates migration paths to build VectorElementKey using the new namespace-bytes ctor.
libs/server/Resp/Vector/VectorManager.cs Updates metadata key construction for the new ctor.
libs/server/Resp/Vector/VectorManager.ContextMetadata.cs Updates context-metadata RMW key construction for the new ctor.
libs/server/Resp/Vector/VectorManager.Cleanup.cs Updates cleanup delete key construction for the new ctor.
libs/server/Resp/Vector/VectorManager.Callbacks.cs Writes namespace into reserved bytes before key data; restores “smashed” length prefix on advance/complete; updates key construction for new ctor.
libs/cluster/Server/Migration/MigrateSessionCommonUtils.cs Updates cluster migration read path to build VectorElementKey using namespace bytes.

Comment thread libs/server/Resp/Vector/VectorManager.cs Outdated
Comment thread libs/server/Resp/Vector/VectorManager.ContextMetadata.cs Outdated
Comment thread libs/server/Resp/Vector/VectorManager.Cleanup.cs Outdated
Comment thread libs/server/Resp/Vector/VectorManager.Callbacks.cs
Comment thread test/standalone/Garnet.test.vectorset/RespVectorSetTests.cs
… indexes; this isnecessary because an eviction might cause an index to 'need to be dropped' during another operation; subtlety here is that we also need to block recreation until the drop is processed or we can end up with two active DiskANN indexes for the same logical Vector Set; introduces a test from Badrish which originally revealed the break
@kevin-montrose kevin-montrose changed the title Fix VectorElementKey.IsPinned Fix VectorElementKey.IsPinned and drop_index calls while Vector Set in use Jun 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 11 out of 11 changed files in this pull request and generated 9 comments.

Comment thread libs/server/Resp/Vector/VectorManager.Migration.cs Outdated
Comment thread libs/server/Resp/Vector/VectorManager.ContextMetadata.cs Outdated
Comment thread libs/server/Resp/Vector/VectorManager.Cleanup.cs Outdated
Comment thread libs/server/Resp/Vector/VectorManager.Callbacks.cs Outdated
Comment thread libs/server/Resp/Vector/VectorManager.cs
Comment thread libs/server/Resp/Vector/VectorManager.Locking.cs Outdated
Comment thread libs/server/Resp/Vector/VectorManager.Locking.cs Outdated
Comment thread libs/server/Resp/Vector/VectorManager.cs Outdated
Comment thread libs/server/Resp/Vector/VectorManager.Cleanup.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 12 out of 12 changed files in this pull request and generated 4 comments.

Comment thread libs/server/Resp/Vector/VectorManager.Migration.cs
Comment thread libs/server/Resp/Vector/VectorManager.cs
Comment thread libs/server/Resp/Vector/VectorManager.Cleanup.cs
Comment thread libs/server/Resp/Vector/VectorManager.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@kevin-montrose kevin-montrose requested a review from badrishc June 15, 2026 20:49
@badrishc badrishc merged commit 096731e into main Jun 17, 2026
284 of 285 checks passed
@badrishc badrishc deleted the users/kmontrose/vectorElementKeyPinningFix branch June 17, 2026 00:02
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