Skip to content

Commit 96930c7

Browse files
craig[bot]yuzefovich
andcommitted
Merge #155884
155884: rowenc, flowinfra: enable a couple test for secondary tenants r=yuzefovich a=yuzefovich **rowenc: adjust TestInitIndexFetchSpec to work with test tenants** With test tenants we have extra 2 bytes (the tenant prefix) included into the "key prefix length" of the spec, so we need to make an adjustment to the test. Also add a couple of log scopes in this package. Fixes: #109390 **flowinfra: enable TestDistSQLReadsFillGatewayID for secondary tenants** This required only a minor adjustment to the request filter. Fixes: #109392. Epic: CRDB-48945 Co-authored-by: Yahor Yuzefovich <[email protected]>
2 parents 2097e1e + 725f753 commit 96930c7

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

pkg/sql/flowinfra/cluster_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,10 @@ func TestLimitedBufferingDeadlock(t *testing.T) {
506506
// Test that DistSQL reads fill the BatchRequest.Header.GatewayNodeID field with
507507
// the ID of the gateway (as opposed to the ID of the node that created the
508508
// batch). Important to lease follow-the-workload transfers.
509+
//
510+
// Note that in single tenant and shared-process modes, GatewayNodeID field is
511+
// set on the kvclient side (i.e. in the SQL pod) whereas in external-process
512+
// mode it's set on the kvserver side (i.e. in the storage pod).
509513
func TestDistSQLReadsFillGatewayID(t *testing.T) {
510514
defer leaktest.AfterTest(t)()
511515
defer log.Scope(t).Close(t)
@@ -522,19 +526,18 @@ func TestDistSQLReadsFillGatewayID(t *testing.T) {
522526
base.TestClusterArgs{
523527
ReplicationMode: base.ReplicationManual,
524528
ServerArgs: base.TestServerArgs{
525-
UseDatabase: "test",
526-
DefaultTestTenant: base.TestIsForStuffThatShouldWorkWithSecondaryTenantsButDoesntYet(109392),
529+
UseDatabase: "test",
527530
Knobs: base.TestingKnobs{Store: &kvserver.StoreTestingKnobs{
528531
EvalKnobs: kvserverbase.BatchEvalTestingKnobs{
529532
TestingEvalFilter: func(filterArgs kvserverbase.FilterArgs) *kvpb.Error {
530533
scanReq, ok := filterArgs.Req.(*kvpb.ScanRequest)
531534
if !ok {
532535
return nil
533536
}
534-
if !strings.HasPrefix(
535-
scanReq.Key.String(),
536-
fmt.Sprintf("/Table/%d/1", tableID.Load()),
537-
) {
537+
pkPrefix := fmt.Sprintf("/Table/%d/1", tableID.Load())
538+
tenantPKPrefix := fmt.Sprintf("/Tenant/%d%s", serverutils.TestTenantID().InternalValue, pkPrefix)
539+
if !strings.HasPrefix(scanReq.Key.String(), pkPrefix) &&
540+
!strings.HasPrefix(scanReq.Key.String(), tenantPKPrefix) {
538541
return nil
539542
}
540543

@@ -552,6 +555,13 @@ func TestDistSQLReadsFillGatewayID(t *testing.T) {
552555
})
553556
defer tc.Stopper().Stop(context.Background())
554557

558+
if tc.DefaultTenantDeploymentMode().IsExternal() {
559+
tc.GrantTenantCapabilities(
560+
context.Background(), t, serverutils.TestTenantID(),
561+
map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanAdminRelocateRange: "true"},
562+
)
563+
}
564+
555565
db := tc.ServerConn(0)
556566
sqlutils.CreateTable(t, db, "t",
557567
"num INT PRIMARY KEY",

pkg/sql/rowenc/index_encoding_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/cockroachdb/cockroach/pkg/util/encoding"
4141
"github.com/cockroachdb/cockroach/pkg/util/json"
4242
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
43+
"github.com/cockroachdb/cockroach/pkg/util/log"
4344
"github.com/cockroachdb/cockroach/pkg/util/randutil"
4445
"github.com/cockroachdb/cockroach/pkg/util/trigram"
4546
"github.com/cockroachdb/cockroach/pkg/util/vector"
@@ -1076,7 +1077,6 @@ func TestEncodeTrigramInvertedIndexSpans(t *testing.T) {
10761077

10771078
runTest := func(indexedValue, value string, searchType trigramSearchType,
10781079
expectContainsKeys, expected, expectUnique bool) {
1079-
t.Logf("test case: %s %s %v %t %t %t", indexedValue, value, searchType, expectContainsKeys, expected, expectUnique)
10801080
keys, err := EncodeInvertedIndexTableKeys(tree.NewDString(indexedValue), nil, descpb.LatestIndexDescriptorVersion)
10811081
require.NoError(t, err)
10821082

@@ -1285,6 +1285,7 @@ func TestDecodeKeyVals(t *testing.T) {
12851285
// write leaf keys, so that's what's tested here.
12861286
func TestVectorEncoding(t *testing.T) {
12871287
defer leaktest.AfterTest(t)()
1288+
defer log.Scope(t).Close(t)
12881289

12891290
ctx := context.Background()
12901291
srv, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{})
@@ -1376,6 +1377,7 @@ func TestVectorEncoding(t *testing.T) {
13761377

13771378
func TestVectorCompositeEncoding(t *testing.T) {
13781379
defer leaktest.AfterTest(t)()
1380+
defer log.Scope(t).Close(t)
13791381

13801382
ctx := context.Background()
13811383
srv, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{})

pkg/sql/rowenc/index_fetch_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ func TestInitIndexFetchSpec(t *testing.T) {
2828
defer leaktest.AfterTest(t)()
2929
defer log.Scope(t).Close(t)
3030

31-
srv, db, kvDB := serverutils.StartServer(t, base.TestServerArgs{
32-
DefaultTestTenant: base.TestIsForStuffThatShouldWorkWithSecondaryTenantsButDoesntYet(109390),
33-
})
31+
srv, db, kvDB := serverutils.StartServer(t, base.TestServerArgs{})
3432
defer srv.Stopper().Stop(context.Background())
3533
codec := srv.ApplicationLayer().Codec()
3634

@@ -76,6 +74,13 @@ func TestInitIndexFetchSpec(t *testing.T) {
7674
if err := rowenc.InitIndexFetchSpec(&spec, codec, table, index, fetchColumnIDs); err != nil {
7775
d.Fatalf(t, "%+v", err)
7876
}
77+
if srv.StartedDefaultTestTenant() {
78+
// If we started a test tenant, then all keys will have the
79+
// tenant prefix (of 2 bytes) prepended to them. In order to
80+
// not create the duplicate expectation file, we'll adjust
81+
// the spec here to ignore those 2 bytes.
82+
spec.KeyPrefixLength -= uint32(len(codec.TenantPrefix()))
83+
}
7984
res, err := json.MarshalIndent(&spec, "", " ")
8085
if err != nil {
8186
d.Fatalf(t, "%+v", err)

0 commit comments

Comments
 (0)