Skip to content

fix problem around collapsed replicated references - #4476

Merged
normen662 merged 3 commits into
FoundationDB:mainfrom
normen662:main
Aug 19, 2026
Merged

normen662 merged 3 commits into
FoundationDB:mainfrom
normen662:main

Conversation

@normen662

@normen662 normen662 commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Fix duplicate-key crash when reassign folds an already-collapsed replica with a

same-signature member

Labels: bug fix · Target: main · open as draft

Problem

ReassignTask.foldCollapsedReplicas could keep two collapsed references for the
same signature in a cluster's assignment. Both carry primaryKey = Tuple.from(signature), so they collide when
AbstractDeferredTask.computeTargetClusterDelta builds its ImmutableMap,
crashing the reassign with:

java.lang.IllegalArgumentException: Multiple entries with same key

Cause

The fold claimed a signature only in the freshly-folded branch. An
already-collapsed replica — the collapsed-area representative, replicated in
from another cluster — took the pass-through branch instead: its
fetchCollapsedVectorId(signature, Tuple.from(signature)) returns null, since
the collapsed store holds only members (keyed by their real primary keys), never
the representative's Tuple.from(signature). So it was kept without claiming
the signature, and a later same-signature member was then folded into a second
collapsed reference — and the two collided.

Fix

Make the fold's dedup membership-aware so at most one collapsed-area reference
per signature is ever kept, while distinct records are preserved. For each replica
(highest replication priority first), keyed off a Set<UUID> of
already-represented signatures:

  • already-collapsed representative — never a store member, so no lookup: keep
    the first one and claim the signature; drop a later collapsed reference for it.
  • non-collapsed replica → look it up in the collapsed store:
    • not a member → keep it. This is a live replica, or a duplicate inserted
      after a collapse and not yet aggregated — a distinct record whose own primaryKey
      cannot collide with the collapsed-area reference, so it must not be dropped on
      signature alone.
    • member, first of its signature → replace it with the single collapsed-area
      reference and claim the signature.
    • member, signature already represented → drop it (already covered by the
      kept reference).

This keeps the crash fixed (one collapsed-area reference per signature) and also
corrects a related over-drop: a fresh, not-yet-aggregated duplicate of a collapsed
signature is no longer discarded just because a collapsed reference for that
signature is present. The cost is one collapsed-store read per non-collapsed
replica (the previous signature-only guard skipped that read). The dedup tracker
was also simplified from a Map<UUID, VectorReference> to a Set<UUID>, since
only signature membership was ever read.

Testing

CollapseScenarioTest (FDB required):

  • reassignDedupesAnAlreadyCollapsedReplicaAgainstAMember — a higher-priority
    already-collapsed replica plus a lower-priority same-signature member: verifies
    reassign completes and the two fold to a single collapsed-area reference keeping
    the highest priority. Reproduced the crash before the fix; passes after.
  • reassignKeepsAFreshNonMemberReplicaAlongsideACollapsedReference — a collapsed
    reference plus a same-signature non-member replica (in metadata, absent from
    the collapsed store): verifies reassign keeps both, pinning that non-members
    are not dropped on signature alone.
  • reassignFoldsCollapsedReplicasIntoOneReference (the existing all-plain-member
    fold) continues to pass.

Refreshed to the membership-aware version. The only follow-up left dangling is the

  • reassignFoldsCollapsedReplicasIntoOneReference (the existing all-plain-member fold) continues to pass.

@normen662 normen662 added the bug fix Change that fixes a bug label Aug 19, 2026
keptReplicas.add(replica);
if (replica.isCollapsed()) {
// An already-collapsed replica is its signature's collapsed-area
// representative (not a store member), so register it here so later

@alecgrieser alecgrieser Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm trying to understand this a bit better, and I'm not sure I do. To summarize:

  1. The collapsed vectors space contain a bunch of vectors ordered by (signature, primaryKey)
  2. When you a cluster has a collapsed vector (set), it stores one representative, linked to the signature
  3. If fetchCollapsedVectorId returns null, then that would mean that we have a collapsed vector replica, but its representative vector is no longer there

I'm trying to understand what actually causes 3. Does it mean that the underlying vector was deleted?

I'm not sure I totally understand what "store member" is really trying to get at here. Do they mean that the representative has been deleted (or was never a "real" vector ID)?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay, I think I have a bit of a better understanding, and if replica.isCollapsed(), then we should always get a null storedVectorId here. The reason would be that the primary key of a collapsed vector is always set to the signature. The subspace in the stored vector ID land only contains the primary keys of the actual base vectors. It's in some sense a type error to try and look up to see if the stored vector space contains the "collapsed" ID, but alas.

I do think the "not a store member" is a bit confusing. I also think the "representative" terminology maybe writ large is a bit confusing. It may be better to say instead that the primary key contains just the signature and is not expected to map to any actual vector's primary key.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is pre-existing, but isn't toCollapsed(signature, signature) wrong? That second signature should be the primary key of the representative in the cluster, not a second copy of the signature

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay, nvm, I misread this API, and the second UUID is the "UUID" component of the primary key. I'm not sure what it should be (or if it should be random), but it sounds like it should pick that up from someone else anyway, and so this is fine.

Comment on lines +652 to +654
new VectorId(Tuple.from(signature), RandomHelpers.randomUuid(Tuple.from("already-collapsed"), true));
primitives.writeVectorReference(tr, quantizer, clusterId,
VectorReference.replicatedCopy(collapsedReplicaId, transformedDuplicate, 0.99d, true));

@alecgrieser alecgrieser Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is the crux of the new test, right? That is RandomHelpers.randomUuid(Tuple.from("already-collapsed") is not written to the collapsed vector ID subspace, so we fail to read it in the fetchCollapsedVectorId call. Which again, still surprises me as a case that we'd hit, absent deletes, unless that .toCollapsed(signature, signature) call is wrong

Okay, I think I'm seeing this a bit clearer now. The primary key is the signature, not the random UUID, so that doesn't matter so much

@alecgrieser alecgrieser left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay, I needed to re-walk through how some of this actually works, and re-remember (if I ever knew) how collapsed VectorIds work. But I think going through it again, that I now understand why this works. We did talk off line about maybe how the isCollapsed() check should be moved to before the lookup, and I do agree that that would make sense. Regardless, I think the code change does what it needs to. Some of the terminology in the comments could maybe be workshopped, I guess

keptReplicas.add(replica);
if (replica.isCollapsed()) {
// An already-collapsed replica is its signature's collapsed-area
// representative (not a store member), so register it here so later

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay, I think I have a bit of a better understanding, and if replica.isCollapsed(), then we should always get a null storedVectorId here. The reason would be that the primary key of a collapsed vector is always set to the signature. The subspace in the stored vector ID land only contains the primary keys of the actual base vectors. It's in some sense a type error to try and look up to see if the stored vector space contains the "collapsed" ID, but alas.

I do think the "not a store member" is a bit confusing. I also think the "representative" terminology maybe writ large is a bit confusing. It may be better to say instead that the primary key contains just the signature and is not expected to map to any actual vector's primary key.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay, nvm, I misread this API, and the second UUID is the "UUID" component of the primary key. I'm not sure what it should be (or if it should be random), but it sounds like it should pick that up from someone else anyway, and so this is fine.

@normen662
normen662 merged commit 2abd403 into FoundationDB:main Aug 19, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix Change that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants