Skip to content

Commit 481f220

Browse files
craig[bot]andy-kimball
andcommitted
Merge #143619
143619: cspann: check level of root partition in delete vector fixup r=drewkimball a=andy-kimball Dangling vectors should only exist in leaf partitions. However, the root partition's level changes when it's split. If there is a pending delete vector fixup for a partition that gets split, this results in a RemoveFromPartition call with the wrong level (e.g. LeafLevel when the partition's level is now SecondLevel). This causes an assert in the memstore, which expects the correct level. The fix is to get the root partition's level when performing a delete vector fixup. Epic: CRDB-42943 Release note: None Co-authored-by: Andrew Kimball <[email protected]>
2 parents 32facf3 + 7842b19 commit 481f220

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

pkg/sql/vecindex/cspann/fixup_worker.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,19 @@ func (fw *fixupWorker) deleteVector(
799799
return nil
800800
}
801801

802+
// If removing from a root partition, check that it's level is LeafLevel. It
803+
// might not be if it was recently split.
804+
if partitionKey == RootKey {
805+
metadata, err := fw.txn.GetPartitionMetadata(
806+
ctx, fw.treeKey, partitionKey, false /* forUpdate */)
807+
if metadata.Level != LeafLevel {
808+
// Root partition's level has been updated, so just abort.
809+
return nil
810+
} else if err != nil {
811+
return errors.Wrapf(err, "getting root partition's level")
812+
}
813+
}
814+
802815
err = fw.index.removeFromPartition(ctx, fw.txn, fw.treeKey, partitionKey, LeafLevel, childKey)
803816
if errors.Is(err, ErrPartitionNotFound) {
804817
log.VEventf(ctx, 2, "partition %d no longer exists, do not delete vector", partitionKey)

pkg/sql/vecindex/cspann/testdata/delete.ddt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,55 @@ vec1: (1, 2)
230230
├───• vec4 (5, 5)
231231
└───• vec2 (7, 4)
232232

233+
# ----------------------------------------------------------------------
234+
# Delete vector from root partition just after a split.
235+
# ----------------------------------------------------------------------
236+
237+
# Load root partition that exceeds the max partition size.
238+
load-index min-partition-size=1 max-partition-size=3 beam-size=2
239+
• 1 (0, 0)
240+
241+
├───• vec1 (1, 2)
242+
├───• vec2 (7, 4)
243+
├───• vec3 (4, 3)
244+
└───• vec4 (5, 5)
245+
----
246+
Loaded 4 vectors.
247+
248+
# Delete vector from primary index, but not from secondary index.
249+
delete not-found
250+
vec3
251+
----
252+
• 1 (0, 0)
253+
254+
├───• vec1 (1, 2)
255+
├───• vec2 (7, 4)
256+
├───• vec3 (MISSING)
257+
└───• vec4 (5, 5)
258+
259+
# Search triggers a split, followed by an attempt to delete the missing vector.
260+
# However, the split changes the root partition level, so the fixup should
261+
# abort.
262+
search max-results=1
263+
(4, 3)
264+
----
265+
vec4: 5 (centroid=7.07)
266+
4 leaf vectors, 4 vectors, 4 full vectors, 1 partitions
267+
268+
# Split should detect missing vector and remove it.
269+
format-tree
270+
----
271+
• 1 (3.5, 3.25)
272+
273+
├───• 2 (6, 4.5)
274+
│ │
275+
│ ├───• vec4 (5, 5)
276+
│ └───• vec2 (7, 4)
277+
278+
└───• 3 (1, 2)
279+
280+
└───• vec1 (1, 2)
281+
233282
# ----------------------------------------------------------------------
234283
# Search root partition with only missing vectors.
235284
# ----------------------------------------------------------------------

0 commit comments

Comments
 (0)