[MOD-18683] Invalidate the pending repair jobs of an isolated element - #1053
Open
nonirosenfeldredis wants to merge 1 commit into
Open
nonirosenfeldredis wants to merge 1 commit into
nonirosenfeldredis wants to merge 1 commit into
Conversation
Isolating a deleted element removes every edge in and out of it, including the edges that a pending repair job *on* that element was created to remove. Those jobs were left for the swap job to invalidate, so a swap job of another deleted element kept waiting for a repair that the isolation had already made unnecessary. Invalidate them at isolation time instead: the waiting swap jobs are released as soon as the element leaves the graph, rather than when its slot is reclaimed. Doing so means a repair job can now be invalidated while the main index guard is only held for shared ownership, which the previous locking could not take: `executeRepairJob` tested `isValid` outside `idToRepairJobsGuard` and only then claimed the job from the lookup, so an invalidation landing in between would rewrite `node_id` with the invalid-job key and the claim would miss. Both steps are now decided under that guard, and `invalidateRepairJobs` takes it itself instead of relying on the main guard being held exclusively. Its existing callers are main-exclusive, so the main -> repair-jobs order is unchanged; the only new nesting is repair-jobs -> invalid-jobs (through `setAndSaveInvalidJob`), which nothing takes in the opposite order. `invalidRepairJobOnSwap` covers the new timing: the 0->1 job is invalidated when 0 is isolated, not when it is swapped out. `swapJobBasic` now reaches an invalidation, so it has to account for the invalid jobs lookup's buckets like the other lookups, and `deleteVectorMulti`'s second repair job is invalidated rather than executed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1053 +/- ##
=======================================
Coverage 97.54% 97.54%
=======================================
Files 141 141
Lines 9011 9014 +3
=======================================
+ Hits 8790 8793 +3
Misses 221 221 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
GuyAv46
approved these changes
Sep 16, 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.
Motivation
part of the optimization of reuse deleted ids.
first pr was: #1012
What
Isolating a deleted element takes every edge in and out of it, including the very edges that a
pending repair job on that element was created to remove. Those jobs were left for the swap job to
invalidate, so the swap job of another deleted element kept waiting for a repair that the
isolation had already made unnecessary. They are now invalidated at isolation time, so a waiting
swap job is released as soon as the element leaves the graph rather than when its slot is reclaimed.
Locking
In short:
idToRepairJobsGuardbecomes the one lock that guards access to the repair jobs map,taken explicitly by every path that reads or writes it, instead of some paths relying on the main
index guard being held exclusively.
Invalidating a repair job from the isolation path means doing it while the main index guard is held
for shared ownership only, which the previous locking could not take:
executeRepairJobtestedjob->isValidoutsideidToRepairJobsGuardand only then claimed thejob from
idToRepairJobs. An invalidation landing in between rewritesnode_idwith theinvalid-job key (
setAndSaveInvalidJobstores it there), so the claim would miss. Both steps arenow decided under that one guard.
invalidateRepairJobstakesidToRepairJobsGuarditself instead of relying on the main guardbeing held exclusively. A job still listed in the lookup has not been claimed by a worker yet -
executeRepairJobde-registers it under the same guard before touching it - so it is alive for aslong as the guard is held.
executeReadySwapJobs,deleteLabelFromHNSWInplace) are main-exclusiveand do not hold the guard, so
main -> idToRepairJobsGuardis unchanged and the guard is nottaken recursively. The only new nesting is
idToRepairJobsGuard -> invalidJobsLookupGuard(through
setAndSaveInvalidJob), and nothing takes those two in the opposite order.readySwapJobsis mutated insideinvalidateRepairJobs, so it is now under the guard there as well(
executeReadySwapJobs,deleteLabelFromHNSWInplace) are main-exclusive, which excludes everyshared holder.
Tests
Three existing tests encoded the old timing and were updated, since the new timing is the point:
invalidRepairJobOnSwap- the0->1job is invalidated when 0 is isolated, before any GC round,and 1's swap job stops waiting for it there. With both swap jobs ready, disposing of them takes two
GC rounds at a threshold of 1.
deleteVectorMulti- the second repair job is invalidated rather than executed, so itsnode_idnow holds its invalid-job key.
swapJobBasic- this flow now reaches an invalidation, so the memory accounting reserves 0 bucketsin the invalid jobs lookup like it does for the other two lookups.
ASAN, locally:
test_hnsw343/343 (261 tiered),test_hnsw_parallel4/4.Follow-up (commented in the code)
A swap job released here is not isolated in turn - it is only marked ready, and
executeReadySwapJobsremoves its element by walking its edges, as for any element whose repairscompleted without this shortcut. Cascading the isolation would make that removal the cheap one too.
🤖 Generated with Claude Code