diff --git a/pkg/storage/BUILD.bazel b/pkg/storage/BUILD.bazel index 85831e80cc84..fdb8b61eb0e1 100644 --- a/pkg/storage/BUILD.bazel +++ b/pkg/storage/BUILD.bazel @@ -104,6 +104,7 @@ go_test( "disk_map_test.go", "engine_key_test.go", "engine_test.go", + "external_helpers_test.go", "intent_interleaving_iter_test.go", "intent_reader_writer_test.go", "main_test.go", diff --git a/pkg/storage/external_helpers_test.go b/pkg/storage/external_helpers_test.go new file mode 100644 index 000000000000..71c05dfcb610 --- /dev/null +++ b/pkg/storage/external_helpers_test.go @@ -0,0 +1,21 @@ +// Copyright 2022 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package storage_test + +import ( + "github.com/cockroachdb/cockroach/pkg/sql/catalog/bootstrap" + "github.com/cockroachdb/cockroach/pkg/storage" +) + +func init() { + storage.TestingUserDescID = bootstrap.TestingUserDescID + storage.TestingUserTableDataMin = bootstrap.TestingUserTableDataMin +} diff --git a/pkg/storage/mvcc_test.go b/pkg/storage/mvcc_test.go index 1498426de504..05cd64b933cd 100644 --- a/pkg/storage/mvcc_test.go +++ b/pkg/storage/mvcc_test.go @@ -26,7 +26,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/settings/cluster" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/bootstrap" "github.com/cockroachdb/cockroach/pkg/storage/enginepb" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/skip" @@ -4374,13 +4373,16 @@ func TestFindSplitKey(t *testing.T) { } } +// Injected via `external_helpers_test.go`. +var TestingUserDescID func(offset uint32) uint32 + // TestFindValidSplitKeys verifies split keys are located such that // they avoid splits through invalid key ranges. func TestFindValidSplitKeys(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) - userID := bootstrap.TestingUserDescID(0) + userID := TestingUserDescID(0) // Manually creates rows corresponding to the schema: // CREATE TABLE t (id1 STRING, id2 STRING, ... PRIMARY KEY (id1, id2, ...)) addTablePrefix := func(prefix roachpb.Key, id uint32, rowVals ...string) roachpb.Key { @@ -4574,7 +4576,7 @@ func TestFindValidSplitKeys(t *testing.T) { addColFam(tablePrefix(userID, "b"), 1), addColFam(tablePrefix(userID, "c"), 1), }, - rangeStart: keys.SystemSQLCodec.TablePrefix(bootstrap.TestingUserDescID(0)), + rangeStart: keys.SystemSQLCodec.TablePrefix(TestingUserDescID(0)), expSplit: tablePrefix(userID, "b"), expError: false, }, @@ -5014,6 +5016,9 @@ func (it *seekLTTrackingIterator) SeekLT(k MVCCKey) { it.MVCCIterator.SeekLT(k) } +// Injected via `external_helpers_test.go`. +var TestingUserTableDataMin func() roachpb.Key + // TestMVCCGarbageCollectUsesSeekLTAppropriately ensures that the garbage // collection only utilizes SeekLT if there are enough undeleted versions. func TestMVCCGarbageCollectUsesSeekLTAppropriately(t *testing.T) { @@ -5037,7 +5042,7 @@ func TestMVCCGarbageCollectUsesSeekLTAppropriately(t *testing.T) { batch := engine.NewBatch() defer batch.Close() it := batch.NewMVCCIterator(MVCCKeyAndIntentsIterKind, IterOptions{ - UpperBound: bootstrap.TestingUserTableDataMin(), + UpperBound: TestingUserTableDataMin(), LowerBound: keys.MaxKey, }) defer it.Close()