Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

externalconn/testutils: fix a mistake in SetSQLDBForUser #110005

Merged
merged 4 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/ccl/partitionccl/zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,14 @@ func TestZoneConfigAppliesToTemporaryIndex(t *testing.T) {
},
}

s, sqlDB, kvDB := serverutils.StartServer(t, params)
defer s.Stopper().Stop(context.Background())
srv, sqlDB, kvDB := serverutils.StartServer(t, params)
defer srv.Stopper().Stop(context.Background())

s := srv.ApplicationLayer()

tdb := sqlutils.MakeSQLRunner(sqlDB)
codec := s.ApplicationLayer().Codec()
sv := &s.ApplicationLayer().ClusterSettings().SV
codec := s.Codec()
sv := &s.ClusterSettings().SV
sql.SecondaryTenantZoneConfigsEnabled.Override(context.Background(), sv, true)

if _, err := sqlDB.Exec(`
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/externalconn/testutils/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (h *Handle) SetSQLDBForUser(tenantID roachpb.TenantID, user string) func()
return resetToRootUser
}

userSQLDB := h.tc.Server(0).SQLConnForUser(h.t, user, "")
userSQLDB := tenantState.ApplicationLayerInterface.SQLConnForUser(h.t, user, "")
tenantState.curDB = sqlutils.MakeSQLRunner(userSQLDB)
tenantState.userToDB[user] = tenantState.curDB

Expand Down
1 change: 1 addition & 0 deletions pkg/server/server_controller_new_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func makeSharedProcessTenantServerConfig(
baseCfg.Locality = kvServerCfg.BaseConfig.Locality
baseCfg.SpanConfigsDisabled = kvServerCfg.BaseConfig.SpanConfigsDisabled
baseCfg.EnableDemoLoginEndpoint = kvServerCfg.BaseConfig.EnableDemoLoginEndpoint
baseCfg.DefaultZoneConfig = kvServerCfg.BaseConfig.DefaultZoneConfig

// TODO(knz): use a single network interface for all tenant servers.
// See: https://github.com/cockroachdb/cockroach/issues/92524
Expand Down
1 change: 1 addition & 0 deletions pkg/server/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ func (ts *testServer) StartTenant(
baseCfg.StartDiagnosticsReporting = params.StartDiagnosticsReporting
baseCfg.DisableTLSForHTTP = params.DisableTLSForHTTP
baseCfg.EnableDemoLoginEndpoint = params.EnableDemoLoginEndpoint
baseCfg.DefaultZoneConfig = ts.Cfg.DefaultZoneConfig

// Waiting for capabilities can time To avoid paying this cost in all
// cases, we only set the nodelocal storage capability if the caller has
Expand Down
1 change: 1 addition & 0 deletions pkg/testutils/sqlutils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ go_library(
"//pkg/sql/lexbase",
"//pkg/sql/parser",
"//pkg/sql/pgwire/pgerror",
"//pkg/sql/protoreflect",
"//pkg/sql/sem/catconstants",
"//pkg/sql/sem/tree",
"//pkg/testutils",
Expand Down
18 changes: 12 additions & 6 deletions pkg/testutils/sqlutils/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/config/zonepb"
"github.com/cockroachdb/cockroach/pkg/sql/lexbase"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/cockroach/pkg/sql/protoreflect"
)

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

func (row ZoneRow) sqlRowString() ([]string, error) {
configProto, err := protoutil.Marshal(&row.Config)
// Make the JSON comparable with the output of crdb_internal.pb_to_json.
configJSON, err := protoreflect.MessageToJSON(
&row.Config,
protoreflect.FmtFlags{EmitDefaults: false, EmitRedacted: false},
)
if err != nil {
return nil, err
}
return []string{
fmt.Sprintf("%d", row.ID),
string(configProto),
configJSON.String(),
}, nil
}

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

Expand All @@ -100,7 +104,9 @@ func VerifyAllZoneConfigs(t testing.TB, sqlDB *SQLRunner, rows ...ZoneRow) {
t.Fatal(err)
}
}
sqlDB.CheckQueryResults(t, `SELECT zone_id, raw_config_protobuf FROM crdb_internal.zones`, expected)
sqlDB.CheckQueryResults(t, `
SELECT zone_id, crdb_internal.pb_to_json('cockroach.config.zonepb.ZoneConfig', raw_config_protobuf)::STRING
FROM crdb_internal.zones`, expected)
}

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