Skip to content

Commit 2b71df6

Browse files
craig[bot]knz
craig[bot]
andcommitted
Merge #110005
110005: externalconn/testutils: fix a mistake in SetSQLDBForUser r=stevendanna a=knz All commits but the last are from #110004 (review only the last commit here) Prior to this patch, this method was incorrectly swapping a SQL connection to the secondary tenant for one to the system tenant. This patch fixes it. Epic: CRDB-18499 Co-authored-by: Raphael 'kena' Poss <[email protected]>
2 parents 6e0dfb1 + 547a048 commit 2b71df6

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

pkg/ccl/partitionccl/zone_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,14 @@ func TestZoneConfigAppliesToTemporaryIndex(t *testing.T) {
386386
},
387387
}
388388

389-
s, sqlDB, kvDB := serverutils.StartServer(t, params)
390-
defer s.Stopper().Stop(context.Background())
389+
srv, sqlDB, kvDB := serverutils.StartServer(t, params)
390+
defer srv.Stopper().Stop(context.Background())
391+
392+
s := srv.ApplicationLayer()
393+
391394
tdb := sqlutils.MakeSQLRunner(sqlDB)
392-
codec := s.ApplicationLayer().Codec()
393-
sv := &s.ApplicationLayer().ClusterSettings().SV
395+
codec := s.Codec()
396+
sv := &s.ClusterSettings().SV
394397
sql.SecondaryTenantZoneConfigsEnabled.Override(context.Background(), sv, true)
395398

396399
if _, err := sqlDB.Exec(`

pkg/cloud/externalconn/testutils/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (h *Handle) SetSQLDBForUser(tenantID roachpb.TenantID, user string) func()
5858
return resetToRootUser
5959
}
6060

61-
userSQLDB := h.tc.Server(0).SQLConnForUser(h.t, user, "")
61+
userSQLDB := tenantState.ApplicationLayerInterface.SQLConnForUser(h.t, user, "")
6262
tenantState.curDB = sqlutils.MakeSQLRunner(userSQLDB)
6363
tenantState.userToDB[user] = tenantState.curDB
6464

pkg/server/server_controller_new_server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ func makeSharedProcessTenantServerConfig(
245245
baseCfg.Locality = kvServerCfg.BaseConfig.Locality
246246
baseCfg.SpanConfigsDisabled = kvServerCfg.BaseConfig.SpanConfigsDisabled
247247
baseCfg.EnableDemoLoginEndpoint = kvServerCfg.BaseConfig.EnableDemoLoginEndpoint
248+
baseCfg.DefaultZoneConfig = kvServerCfg.BaseConfig.DefaultZoneConfig
248249

249250
// TODO(knz): use a single network interface for all tenant servers.
250251
// See: https://github.com/cockroachdb/cockroach/issues/92524

pkg/server/testserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,7 @@ func (ts *testServer) StartTenant(
14761476
baseCfg.StartDiagnosticsReporting = params.StartDiagnosticsReporting
14771477
baseCfg.DisableTLSForHTTP = params.DisableTLSForHTTP
14781478
baseCfg.EnableDemoLoginEndpoint = params.EnableDemoLoginEndpoint
1479+
baseCfg.DefaultZoneConfig = ts.Cfg.DefaultZoneConfig
14791480

14801481
// Waiting for capabilities can time To avoid paying this cost in all
14811482
// cases, we only set the nodelocal storage capability if the caller has

pkg/testutils/sqlutils/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ go_library(
2424
"//pkg/sql/lexbase",
2525
"//pkg/sql/parser",
2626
"//pkg/sql/pgwire/pgerror",
27+
"//pkg/sql/protoreflect",
2728
"//pkg/sql/sem/catconstants",
2829
"//pkg/sql/sem/tree",
2930
"//pkg/testutils",

pkg/testutils/sqlutils/zone.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
"github.com/cockroachdb/cockroach/pkg/config/zonepb"
1919
"github.com/cockroachdb/cockroach/pkg/sql/lexbase"
20-
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
20+
"github.com/cockroachdb/cockroach/pkg/sql/protoreflect"
2121
)
2222

2323
// ZoneRow represents a row returned by SHOW ZONE CONFIGURATION.
@@ -27,13 +27,17 @@ type ZoneRow struct {
2727
}
2828

2929
func (row ZoneRow) sqlRowString() ([]string, error) {
30-
configProto, err := protoutil.Marshal(&row.Config)
30+
// Make the JSON comparable with the output of crdb_internal.pb_to_json.
31+
configJSON, err := protoreflect.MessageToJSON(
32+
&row.Config,
33+
protoreflect.FmtFlags{EmitDefaults: false, EmitRedacted: false},
34+
)
3135
if err != nil {
3236
return nil, err
3337
}
3438
return []string{
3539
fmt.Sprintf("%d", row.ID),
36-
string(configProto),
40+
configJSON.String(),
3741
}, nil
3842
}
3943

@@ -83,8 +87,8 @@ func VerifyZoneConfigForTarget(t testing.TB, sqlDB *SQLRunner, target string, ro
8387
t.Fatal(err)
8488
}
8589
sqlDB.CheckQueryResults(t, fmt.Sprintf(`
86-
SELECT zone_id, raw_config_protobuf
87-
FROM [SHOW ZONE CONFIGURATION FOR %s]`, target),
90+
SELECT zone_id, crdb_internal.pb_to_json('cockroach.config.zonepb.ZoneConfig', raw_config_protobuf)::STRING
91+
FROM [SHOW ZONE CONFIGURATION FOR %s]`, target),
8892
[][]string{sqlRow})
8993
}
9094

@@ -100,7 +104,9 @@ func VerifyAllZoneConfigs(t testing.TB, sqlDB *SQLRunner, rows ...ZoneRow) {
100104
t.Fatal(err)
101105
}
102106
}
103-
sqlDB.CheckQueryResults(t, `SELECT zone_id, raw_config_protobuf FROM crdb_internal.zones`, expected)
107+
sqlDB.CheckQueryResults(t, `
108+
SELECT zone_id, crdb_internal.pb_to_json('cockroach.config.zonepb.ZoneConfig', raw_config_protobuf)::STRING
109+
FROM crdb_internal.zones`, expected)
104110
}
105111

106112
// ZoneConfigExists returns whether a zone config with the provided name exists.

0 commit comments

Comments
 (0)