Skip to content

Commit aa91607

Browse files
craig[bot]Nukitt
andcommitted
Merge #148804
148804: all: reduce usage of `tenant 2` as an application tenant from tests r=msbutler,shubhamdhama a=Nukitt Currently, we use tenant ID 2 as an application tenant in various tests. However, in normal operational scenarios, the creation of tenant ID 2 is explicitly disabled to avoid conflicts with its role in UA, as detailed here: https://github.com/cockroachdb/cockroach/blob/9919801f067f26c951f43cbedfa093c37cdda20e/pkg/sql/tenant_creation.go#L604-L609 With the ongoing migration towards UA, tenant ID 2 will begin functioning as a system tenant. Consequently, we are shifting the application tenant role from tenant ID 2 to tenant ID 3 to clearly separate the roles and responsibilities of system and application tenants. This patch specifically addresses and reduces the usage of tenant ID 2 within tests, ensuring tests align with this architectural adjustment and maintaining consistency across the codebase. Part of: #138801 Epic : CRDB-45181 Release note: none Co-authored-by: Nukitt <[email protected]>
2 parents ca0d407 + fbf14a1 commit aa91607

File tree

17 files changed

+77
-77
lines changed

17 files changed

+77
-77
lines changed

pkg/backup/schedule_exec_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestBackupSucceededUpdatesMetrics(t *testing.T) {
4242

4343
t.Run("updates RPO tenant metric", func(t *testing.T) {
4444
schedule := createSchedule(t, true)
45-
tenantIDs := mustMakeTenantIDs(t, 1, 2)
45+
tenantIDs := mustMakeTenantIDs(t, 1, 3)
4646
endTime := hlc.Timestamp{WallTime: hlc.UnixNano()}
4747
details := jobspb.BackupDetails{
4848
EndTime: endTime,
@@ -52,7 +52,7 @@ func TestBackupSucceededUpdatesMetrics(t *testing.T) {
5252
err := executor.backupSucceeded(ctx, nil, schedule, details, nil)
5353
require.NoError(t, err)
5454

55-
expectedTenantIDs := []string{"system", "2"}
55+
expectedTenantIDs := []string{"system", "3"}
5656
verifyRPOTenantMetricLabels(t, executor.metrics.RpoTenantMetric, expectedTenantIDs)
5757
verifyRPOTenantMetricGaugeValue(t, executor.metrics.RpoTenantMetric, details.EndTime)
5858
})

pkg/backup/show_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,23 +541,23 @@ func TestShowBackupTenantView(t *testing.T) {
541541

542542
_ = securitytest.EmbeddedTenantIDs()
543543

544-
_, conn2 := serverutils.StartTenant(t, srv, base.TestTenantArgs{TenantID: roachpb.MustMakeTenantID(2)})
545-
defer conn2.Close()
544+
_, conn3 := serverutils.StartTenant(t, srv, base.TestTenantArgs{TenantID: roachpb.MustMakeTenantID(3)})
545+
defer conn3.Close()
546546

547-
tenant2 := sqlutils.MakeSQLRunner(conn2)
547+
tenant3 := sqlutils.MakeSQLRunner(conn3)
548548
dataQuery := `CREATE DATABASE foo; CREATE TABLE foo.bar(i int primary key); INSERT INTO foo.bar VALUES (110), (210)`
549549
backupQuery := `BACKUP TABLE foo.bar INTO $1`
550550
showBackupQuery := "SELECT object_name, object_type, rows FROM [SHOW BACKUP FROM LATEST IN $1]"
551-
tenant2.Exec(t, dataQuery)
551+
tenant3.Exec(t, dataQuery)
552552

553553
// First, assert that SHOW BACKUPS on a tenant backup returns the same results if
554-
// either the system tenant or tenant2 calls it.
554+
// either the system tenant or tenant3 calls it.
555555
tenantAddr, httpServerCleanup := makeInsecureHTTPServer(t)
556556
defer httpServerCleanup()
557557

558-
tenant2.Exec(t, backupQuery, tenantAddr)
558+
tenant3.Exec(t, backupQuery, tenantAddr)
559559
systemTenantShowRes := systemDB.QueryStr(t, showBackupQuery, tenantAddr)
560-
require.Equal(t, systemTenantShowRes, tenant2.QueryStr(t, showBackupQuery, tenantAddr))
560+
require.Equal(t, systemTenantShowRes, tenant3.QueryStr(t, showBackupQuery, tenantAddr))
561561

562562
// If the system tenant created the same data, and conducted the same backup,
563563
// the row counts should look the same.

pkg/ccl/spanconfigccl/spanconfigsqlwatcherccl/sqlwatcher_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ func TestSQLWatcherReactsToUpdates(t *testing.T) {
229229
},
230230
{
231231
stmts: []string{
232-
"SELECT crdb_internal.create_tenant(2);",
233-
"BACKUP TENANT 2 INTO 'nodelocal://1/foo'",
232+
"SELECT crdb_internal.create_tenant(3);",
233+
"BACKUP TENANT 3 INTO 'nodelocal://1/foo'",
234234
},
235235
expectedPTSUpdates: []spanconfig.ProtectedTimestampUpdate{{ClusterTarget: false,
236-
TenantTarget: roachpb.MustMakeTenantID(2)}},
236+
TenantTarget: roachpb.MustMakeTenantID(3)}},
237237
},
238238
}
239239

pkg/crosscluster/producer/stream_event_batcher_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestBatchSpanConfigs(t *testing.T) {
7070
t.Logf("Replication helper seed %d", seed)
7171

7272
seb := makeStreamEventBatcher(true)
73-
codec := keys.MakeSQLCodec(roachpb.MustMakeTenantID(2))
73+
codec := keys.MakeSQLCodec(roachpb.MustMakeTenantID(3))
7474
bufferedEvents := make([]streampb.StreamedSpanConfigEntry, 0)
7575

7676
tableSpan := func(tableID uint32) roachpb.Span {

pkg/keys/keys_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ func TestEnsureSafeSplitKey(t *testing.T) {
702702
func TestDecodeTenantPrefix(t *testing.T) {
703703
tIDs := []roachpb.TenantID{
704704
roachpb.SystemTenantID,
705-
roachpb.MustMakeTenantID(2),
705+
roachpb.MustMakeTenantID(3),
706706
roachpb.MustMakeTenantID(999),
707707
roachpb.MustMakeTenantID(math.MaxUint64),
708708
}

pkg/kv/kvclient/kvtenant/tenant_range_lookup_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestRangeLookupPrefetchFiltering(t *testing.T) {
2828

2929
ctx := context.Background()
3030
tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{
31-
// Avovid additional splits (outside those below) by disabling the split
31+
// Avoid additional splits (outside those below) by disabling the split
3232
// queue via the replication manual mode.
3333
ReplicationMode: base.ReplicationManual,
3434
ServerArgs: base.TestServerArgs{
@@ -37,33 +37,33 @@ func TestRangeLookupPrefetchFiltering(t *testing.T) {
3737
})
3838
defer tc.Stopper().Stop(ctx)
3939

40-
ten2ID := roachpb.MustMakeTenantID(2)
41-
tenant2, err := tc.Server(0).TenantController().StartTenant(ctx, base.TestTenantArgs{
42-
TenantID: ten2ID,
40+
ten3ID := roachpb.MustMakeTenantID(3)
41+
tenant3, err := tc.Server(0).TenantController().StartTenant(ctx, base.TestTenantArgs{
42+
TenantID: ten3ID,
4343
})
4444
require.NoError(t, err)
4545

46-
// Split some ranges within tenant2 that we'll want to see in prefetch.
47-
ten2Codec := keys.MakeSQLCodec(ten2ID)
48-
ten2Split1 := append(ten2Codec.TenantPrefix(), 'a')
49-
ten2Split2 := append(ten2Codec.TenantPrefix(), 'b')
46+
// Split some ranges within tenant3 that we'll want to see in prefetch.
47+
ten3Codec := keys.MakeSQLCodec(ten3ID)
48+
ten3Split1 := append(ten3Codec.TenantPrefix(), 'a')
49+
ten3Split2 := append(ten3Codec.TenantPrefix(), 'b')
5050
{
51-
tc.SplitRangeOrFatal(t, ten2Split1)
52-
tc.SplitRangeOrFatal(t, ten2Split2)
51+
tc.SplitRangeOrFatal(t, ten3Split1)
52+
tc.SplitRangeOrFatal(t, ten3Split2)
5353
}
5454

55-
// Split some ranges for the tenant which comes after tenant2.
55+
// Split some ranges for the tenant which comes after tenant3.
5656
{
57-
ten3Codec := keys.MakeSQLCodec(roachpb.MustMakeTenantID(3))
58-
tc.SplitRangeOrFatal(t, ten3Codec.TenantPrefix())
59-
tc.SplitRangeOrFatal(t, append(ten3Codec.TenantPrefix(), 'b'))
60-
tc.SplitRangeOrFatal(t, append(ten3Codec.TenantPrefix(), 'c'))
57+
ten4Codec := keys.MakeSQLCodec(roachpb.MustMakeTenantID(4))
58+
tc.SplitRangeOrFatal(t, ten4Codec.TenantPrefix())
59+
tc.SplitRangeOrFatal(t, append(ten4Codec.TenantPrefix(), 'b'))
60+
tc.SplitRangeOrFatal(t, append(ten4Codec.TenantPrefix(), 'c'))
6161
}
6262

6363
// Do the fetch and make sure we prefetch all the ranges we should see,
6464
// and none of the ranges we should not.
65-
db := tenant2.DistSenderI().(*kvcoord.DistSender).RangeDescriptorCache().DB()
66-
prefixRKey := keys.MustAddr(ten2Codec.TenantPrefix())
65+
db := tenant3.DistSenderI().(*kvcoord.DistSender).RangeDescriptorCache().DB()
66+
prefixRKey := keys.MustAddr(ten3Codec.TenantPrefix())
6767
res, prefetch, err := db.RangeLookup(
6868
ctx, prefixRKey,
6969
rangecache.ReadFromLeaseholder, false, /* useReverseScan */
@@ -72,6 +72,6 @@ func TestRangeLookupPrefetchFiltering(t *testing.T) {
7272
require.Len(t, res, 1)
7373
require.Equal(t, prefixRKey, res[0].StartKey)
7474
require.Len(t, prefetch, 2)
75-
require.Equal(t, keys.MustAddr(ten2Split1), prefetch[0].StartKey)
76-
require.Equal(t, keys.MustAddr(ten2Split2), prefetch[1].StartKey)
75+
require.Equal(t, keys.MustAddr(ten3Split1), prefetch[0].StartKey)
76+
require.Equal(t, keys.MustAddr(ten3Split2), prefetch[1].StartKey)
7777
}

pkg/kv/kvclient/kvtenant/tenant_scan_range_descriptors_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ func setup(
3131
},
3232
})
3333

34-
ten2ID := roachpb.MustMakeTenantID(2)
35-
tenant2, err := tc.Server(0).TenantController().StartTenant(ctx, base.TestTenantArgs{
36-
TenantID: ten2ID,
34+
ten3ID := roachpb.MustMakeTenantID(3)
35+
tenant3, err := tc.Server(0).TenantController().StartTenant(ctx, base.TestTenantArgs{
36+
TenantID: ten3ID,
3737
})
3838
require.NoError(t, err)
39-
return tc, tenant2, tenant2.RangeDescIteratorFactory().(rangedesc.IteratorFactory)
39+
return tc, tenant3, tenant3.RangeDescIteratorFactory().(rangedesc.IteratorFactory)
4040
}
4141

4242
// TestScanRangeDescriptors is an integration test to ensure that tenants can
@@ -46,20 +46,20 @@ func TestScanRangeDescriptors(t *testing.T) {
4646
defer log.Scope(t).Close(t)
4747

4848
ctx := context.Background()
49-
tc, tenant2, iteratorFactory := setup(t, ctx)
49+
tc, tenant3, iteratorFactory := setup(t, ctx)
5050
defer tc.Stopper().Stop(ctx)
5151

5252
// Split some ranges within tenant2 that we'll scan over.
53-
ten2Codec := tenant2.Codec()
54-
ten2Split1 := append(ten2Codec.TenantPrefix(), 'a')
55-
ten2Split2 := append(ten2Codec.TenantPrefix(), 'b')
53+
ten3Codec := tenant3.Codec()
54+
ten3Split1 := append(ten3Codec.TenantPrefix(), 'a')
55+
ten3Split2 := append(ten3Codec.TenantPrefix(), 'b')
5656
{
57-
tc.SplitRangeOrFatal(t, ten2Split1)
58-
tc.SplitRangeOrFatal(t, ten2Split2)
59-
tc.SplitRangeOrFatal(t, ten2Codec.TenantEndKey()) // Last range
57+
tc.SplitRangeOrFatal(t, ten3Split1)
58+
tc.SplitRangeOrFatal(t, ten3Split2)
59+
tc.SplitRangeOrFatal(t, ten3Codec.TenantEndKey()) // Last range
6060
}
6161

62-
iter, err := iteratorFactory.NewIterator(ctx, ten2Codec.TenantSpan())
62+
iter, err := iteratorFactory.NewIterator(ctx, ten3Codec.TenantSpan())
6363
require.NoError(t, err)
6464

6565
var rangeDescs []roachpb.RangeDescriptor
@@ -71,17 +71,17 @@ func TestScanRangeDescriptors(t *testing.T) {
7171
require.Len(t, rangeDescs, 3)
7272
require.Equal(
7373
t,
74-
keys.MustAddr(ten2Codec.TenantPrefix()),
74+
keys.MustAddr(ten3Codec.TenantPrefix()),
7575
rangeDescs[0].StartKey,
7676
)
7777
require.Equal(
7878
t,
79-
keys.MustAddr(ten2Split1),
79+
keys.MustAddr(ten3Split1),
8080
rangeDescs[1].StartKey,
8181
)
8282
require.Equal(
8383
t,
84-
keys.MustAddr(ten2Split2),
84+
keys.MustAddr(ten3Split2),
8585
rangeDescs[2].StartKey,
8686
)
8787

@@ -110,7 +110,7 @@ func TestScanRangeDescriptors(t *testing.T) {
110110
// Last range we created above.
111111
require.Equal(
112112
t,
113-
keys.MustAddr(ten2Codec.TenantEndKey()),
113+
keys.MustAddr(ten3Codec.TenantEndKey()),
114114
rangeDescs[numRanges-1].StartKey,
115115
)
116116
}
@@ -124,5 +124,5 @@ func TestScanRangeDescriptorsOutsideTenantKeyspace(t *testing.T) {
124124
defer tc.Stopper().Stop(ctx)
125125

126126
_, err := iteratorFactory.NewIterator(ctx, keys.EverythingSpan)
127-
require.ErrorContains(t, err, "requested key span /M{in-ax} not fully contained in tenant keyspace /Tenant/{2-3}")
127+
require.ErrorContains(t, err, "requested key span /M{in-ax} not fully contained in tenant keyspace /Tenant/{3-4}")
128128
}

pkg/kv/kvserver/client_replica_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5117,8 +5117,8 @@ func TestTenantID(t *testing.T) {
51175117
})
51185118
defer tc.Stopper().Stop(ctx)
51195119

5120-
tenant2 := roachpb.MustMakeTenantID(2)
5121-
tenant2Prefix := keys.MakeTenantPrefix(tenant2)
5120+
tenant3 := roachpb.MustMakeTenantID(3)
5121+
tenant3Prefix := keys.MakeTenantPrefix(tenant3)
51225122
t.Run("(1) initial set", func(t *testing.T) {
51235123
// Ensure that a normal range has the system tenant.
51245124
{
@@ -5128,16 +5128,16 @@ func TestTenantID(t *testing.T) {
51285128
require.Equal(t, roachpb.SystemTenantID, tenantId, "%v", repl)
51295129
}
51305130
// Ensure that a range with a tenant prefix has the proper tenant ID.
5131-
tc.SplitRangeOrFatal(t, tenant2Prefix)
5131+
tc.SplitRangeOrFatal(t, tenant3Prefix)
51325132
{
5133-
_, repl := getFirstStoreReplica(t, tc.Server(0), tenant2Prefix)
5133+
_, repl := getFirstStoreReplica(t, tc.Server(0), tenant3Prefix)
51345134
tenantId, valid := repl.TenantID()
51355135
require.True(t, valid)
5136-
require.Equal(t, tenant2, tenantId, "%v", repl)
5136+
require.Equal(t, tenant3, tenantId, "%v", repl)
51375137
}
51385138
})
51395139
t.Run("(2) not set before snapshot", func(t *testing.T) {
5140-
_, repl := getFirstStoreReplica(t, tc.Server(0), tenant2Prefix)
5140+
_, repl := getFirstStoreReplica(t, tc.Server(0), tenant3Prefix)
51415141
sawSnapshot := make(chan struct{}, 1)
51425142
blockSnapshot := make(chan struct{})
51435143
tc.AddAndStartServer(t, base.TestServerArgs{
@@ -5166,7 +5166,7 @@ func TestTenantID(t *testing.T) {
51665166
// networking handshake timeouts.
51675167
addReplicaErr := make(chan error)
51685168
addReplica := func() {
5169-
_, err := tc.AddVoters(tenant2Prefix, tc.Target(1))
5169+
_, err := tc.AddVoters(tenant3Prefix, tc.Target(1))
51705170
addReplicaErr <- err
51715171
}
51725172
go addReplica()
@@ -5190,14 +5190,14 @@ func TestTenantID(t *testing.T) {
51905190
require.NoError(t, <-addReplicaErr)
51915191
tenantID, valid := uninitializedRepl.TenantID() // now initialized
51925192
require.True(t, valid)
5193-
require.Equal(t, tenant2, tenantID)
5193+
require.Equal(t, tenant3, tenantID)
51945194
})
51955195
t.Run("(3) upon restart", func(t *testing.T) {
51965196
tc.StopServer(0)
51975197
tc.AddAndStartServer(t, stickySpecTestServerArgs)
5198-
_, repl := getFirstStoreReplica(t, tc.Server(2), tenant2Prefix)
5198+
_, repl := getFirstStoreReplica(t, tc.Server(2), tenant3Prefix)
51995199
tenantID, _ := repl.TenantID() // now initialized
5200-
require.Equal(t, tenant2, tenantID, "%v", repl)
5200+
require.Equal(t, tenant3, tenantID, "%v", repl)
52015201
})
52025202

52035203
}

pkg/kv/kvserver/store_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,7 +2659,7 @@ func TestStore_HottestReplicasByTenant(t *testing.T) {
26592659
}
26602660

26612661
td := []testData{{1, 2}, {1, 3}, {1, 4}, {1, 5},
2662-
{2, 1}, {2, 2}, {2, 3}, {2, 4}}
2662+
{3, 1}, {3, 2}, {3, 3}, {3, 4}}
26632663

26642664
acc := NewTenantReplicaAccumulator(aload.Queries)
26652665

@@ -2685,7 +2685,7 @@ func TestStore_HottestReplicasByTenant(t *testing.T) {
26852685
for i := 0; i < iterationsNum; i++ {
26862686
go func() {
26872687
require.NotNil(t, store.HottestReplicasByTenant(roachpb.MustMakeTenantID(1)))
2688-
require.NotNil(t, store.HottestReplicasByTenant(roachpb.MustMakeTenantID(2)))
2688+
require.NotNil(t, store.HottestReplicasByTenant(roachpb.MustMakeTenantID(3)))
26892689
wg.Done()
26902690
}()
26912691
}

pkg/kv/kvserver/tenantrate/limiter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestCloser(t *testing.T) {
5050
factory := tenantrate.NewLimiterFactory(&st.SV, &tenantrate.TestingKnobs{
5151
QuotaPoolOptions: []quotapool.Option{quotapool.WithTimeSource(timeSource)},
5252
}, fakeAuthorizer{})
53-
tenant := roachpb.MustMakeTenantID(2)
53+
tenant := roachpb.MustMakeTenantID(3)
5454
closer := make(chan struct{})
5555
limiter := factory.GetTenant(ctx, tenant, closer)
5656
// First Wait call will not block.

0 commit comments

Comments
 (0)