Repository navigation
fix problem around collapsed replicated references - #4476
Conversation
| 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 |
There was a problem hiding this comment.
I'm trying to understand this a bit better, and I'm not sure I do. To summarize:
- The collapsed vectors space contain a bunch of vectors ordered by
(signature, primaryKey) - When you a cluster has a collapsed vector (set), it stores one representative, linked to the signature
- If
fetchCollapsedVectorIdreturnsnull, 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)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| new VectorId(Tuple.from(signature), RandomHelpers.randomUuid(Tuple.from("already-collapsed"), true)); | ||
| primitives.writeVectorReference(tr, quantizer, clusterId, | ||
| VectorReference.replicatedCopy(collapsedReplicaId, transformedDuplicate, 0.99d, true)); |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.foldCollapsedReplicascould keep two collapsed references for thesame signature in a cluster's assignment. Both carry
primaryKey = Tuple.from(signature), so they collide whenAbstractDeferredTask.computeTargetClusterDeltabuilds itsImmutableMap,crashing the reassign with:
java.lang.IllegalArgumentException: Multiple entries with same keyCause
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))returnsnull, sincethe collapsed store holds only members (keyed by their real primary keys), never
the representative's
Tuple.from(signature). So it was kept without claimingthe 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>ofalready-represented signatures:
the first one and claim the signature; drop a later collapsed reference for it.
after a collapse and not yet aggregated — a distinct record whose own
primaryKeycannot collide with the collapsed-area reference, so it must not be dropped on
signature alone.
reference and claim the signature.
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 aSet<UUID>, sinceonly signature membership was ever read.
Testing
CollapseScenarioTest(FDB required):reassignDedupesAnAlreadyCollapsedReplicaAgainstAMember— a higher-priorityalready-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 collapsedreference 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-memberfold) 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.