Skip to content

Commit 3c99c98

Browse files
committed
vecindex: add Try methods to Store
Add a new set of Try methods to the Store method that run outside the scope of a transaction. Each Try method checks one or two preconditions, and will only perform its operation if the preconditions pass. These new methods will be used to do background fixup processing without the use of transactions, in order to reduce contention between foreground and background work. In order to handle multiple racing workers, this commit introduces a new state machine that tracks the progress of split and merge fixups. The current state of a partition is stored in its metadata. Each Try method takes "expected" metadata that represents a worker's current understanding of a partition's state. If the actual metadata does not match the expected metadata, then another worker must have updated it, and so the Try method fails with a ConditionFailedError. The calling worker can reset its understanding of that partition's state, and continue processing the fixup. Epic: CRDB-42943 Release note: None
1 parent 7984c75 commit 3c99c98

19 files changed

+1551
-173
lines changed

pkg/cmd/vecbench/mem_provider.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,14 @@ func (m *MemProvider) ensureIndex(ctx context.Context) error {
233233
if m.index != nil {
234234
return nil
235235
}
236+
237+
quantizer := quantize.NewRaBitQuantizer(m.dims, seed)
236238
if m.store == nil {
237239
// Construct empty store if one doesn't yet exist.
238-
m.store = memstore.New(m.dims, seed)
240+
m.store = memstore.New(quantizer, seed)
239241
}
240242

241243
var err error
242-
quantizer := quantize.NewRaBitQuantizer(m.dims, seed)
243244
m.index, err = cspann.NewIndex(ctx, m.store, quantizer, seed, &m.options, m.stopper)
244245
return err
245246
}

pkg/sql/vecindex/cspann/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ go_library(
1919
"kmeans.go",
2020
"pacer.go",
2121
"partition.go",
22+
"partition_metadata.go",
2223
"search_set.go",
2324
"split_data.go",
2425
"store.go",
26+
"store_errors.go",
2527
],
2628
embed = [":cspann_go_proto"],
2729
importpath = "github.com/cockroachdb/cockroach/pkg/sql/vecindex/cspann",
@@ -52,6 +54,7 @@ go_test(
5254
"index_test.go",
5355
"kmeans_test.go",
5456
"pacer_test.go",
57+
"partition_metadata_test.go",
5558
"partition_test.go",
5659
"search_set_test.go",
5760
],

pkg/sql/vecindex/cspann/commontest/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ go_library(
1414
"//pkg/sql/vecindex/cspann/testutils",
1515
"//pkg/sql/vecindex/cspann/workspace",
1616
"//pkg/util/num32",
17+
"//pkg/util/timeutil",
1718
"//pkg/util/vector",
1819
"@com_github_cockroachdb_errors//:errors",
1920
"@com_github_stretchr_testify//require",

0 commit comments

Comments
 (0)