Skip to content

Commit 51aa625

Browse files
craig[bot]knz
andcommitted
107612: serverutils: clean up some interfaces r=knz a=knz Epic: CRDB-18499 Part of solving cockroachdb#107058. Informs cockroachdb#106772. In this commit: - `TestTenantInterface` renamed to `ApplicationLayerInterface`. - `TestServerInterface` split into: - `StorageLayerInterface` containing most of the methods previously in `TestServerInterface`. - `TenantControlInterface` with just the methods relating to starting the service for secondary tenants. - Relevant methods moved from `TestServerInterface` to `ApplicationLayerInterface`: - `ServingSQLAddr()` - renamed to `AdvSQLAddr()` - `RPCAddr()` - `LeaseManager()` - `DistSenderI()` - `MigrationServer()` - `SetDistSQLSpanResolver()` - `CollectionFactory()` - `SystemTableIDResolver()` - Removed `HostSQLAddr()` - use `.SystemLayer().AdvSQLAddr()` instead. - `AdvSQLAddr()` (previously `ServingSQLAddr()`) was simplified to always return the advertised SQL address for the current layer. - Updated comments/docstrings for the interfaces. Release note: None Co-authored-by: Raphael 'kena' Poss <[email protected]>
2 parents 68e43c8 + b2992d7 commit 51aa625

File tree

191 files changed

+1247
-1111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+1247
-1111
lines changed

pkg/bench/foreachdb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func benchmarkSharedProcessTenantCockroach(b *testing.B, f BenchmarkFn) {
8888
require.NoError(b, db.QueryRow(`SELECT id FROM [SHOW TENANT benchtenant]`).Scan(&tenantID))
8989

9090
err = testutils.SucceedsSoonError(func() error {
91-
capabilities, found := s.(*server.TestServer).Server.TenantCapabilitiesReader().GetCapabilities(roachpb.MustMakeTenantID(tenantID))
91+
capabilities, found := s.StorageLayer().TenantCapabilitiesReader().GetCapabilities(roachpb.MustMakeTenantID(tenantID))
9292
if !found {
9393
return errors.Newf("capabilities not yet ready")
9494
}

pkg/bench/pgbench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func BenchmarkPgbenchExec(b *testing.B) {
113113
defer s.Stopper().Stop(context.Background())
114114

115115
pgURL, cleanupFn := sqlutils.PGUrl(
116-
b, s.ServingSQLAddr(), "benchmarkCockroach", url.User(username.RootUser))
116+
b, s.AdvSQLAddr(), "benchmarkCockroach", url.User(username.RootUser))
117117
pgURL.RawQuery = "sslmode=disable"
118118
defer cleanupFn()
119119

pkg/bench/tpcc/tpcc_bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (bm *benchmark) startCockroach(b testing.TB) {
147147
}
148148

149149
pgURL, cleanup, err := sqlutils.PGUrlE(
150-
s.ServingSQLAddr(), b.TempDir(), url.User("root"),
150+
s.AdvSQLAddr(), b.TempDir(), url.User("root"),
151151
)
152152
require.NoError(b, err)
153153
pgURL.Path = databaseName

pkg/ccl/auditloggingccl/audit_logging_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestSingleRoleAuditLogging(t *testing.T) {
122122
defer s.Stopper().Stop(context.Background())
123123

124124
testUserURL, cleanupFn := sqlutils.PGUrl(t,
125-
s.ServingSQLAddr(), t.Name(), url.User(username.TestUser))
125+
s.ApplicationLayer().AdvSQLAddr(), t.Name(), url.User(username.TestUser))
126126
defer cleanupFn()
127127

128128
testUserDb, err := gosql.Open("postgres", testUserURL.String())
@@ -254,7 +254,7 @@ func TestMultiRoleAuditLogging(t *testing.T) {
254254
defer s.Stopper().Stop(context.Background())
255255

256256
testUserURL, cleanupFn := sqlutils.PGUrl(t,
257-
s.ServingSQLAddr(), t.Name(), url.User(username.TestUser))
257+
s.ApplicationLayer().AdvSQLAddr(), t.Name(), url.User(username.TestUser))
258258
defer cleanupFn()
259259

260260
testUserDb, err := gosql.Open("postgres", testUserURL.String())
@@ -375,7 +375,7 @@ func TestReducedAuditConfig(t *testing.T) {
375375
})
376376

377377
testUserURL, cleanupFn := sqlutils.PGUrl(t,
378-
s.ServingSQLAddr(), t.Name(), url.User(username.TestUser))
378+
s.ApplicationLayer().AdvSQLAddr(), t.Name(), url.User(username.TestUser))
379379
defer cleanupFn()
380380

381381
testUserDb, err := gosql.Open("postgres", testUserURL.String())

pkg/ccl/backupccl/backup_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,7 @@ func TestBackupRestoreResume(t *testing.T) {
18131813
const numAccounts = 1000
18141814
tc, outerDB, dir, cleanupFn := backupRestoreTestSetupWithParams(t, multiNode, numAccounts, InitManualReplication, params)
18151815
defer cleanupFn()
1816-
srv := tc.TenantOrServer(0)
1816+
srv := tc.ApplicationLayer(0)
18171817
codec := keys.MakeSQLCodec(srv.RPCContext().TenantID)
18181818
clusterID := srv.RPCContext().LogicalClusterID.Get()
18191819
backupTableDesc := desctestutils.TestingGetPublicTableDescriptor(tc.Servers[0].DB(), codec, "data", "bank")
@@ -1896,7 +1896,7 @@ func TestBackupRestoreResume(t *testing.T) {
18961896
sqlDB.Exec(t, `BACKUP DATABASE DATA TO $1`, restoreDir)
18971897
sqlDB.Exec(t, `CREATE DATABASE restoredb`)
18981898
restoreDatabaseID := sqlutils.QueryDatabaseID(t, sqlDB.DB, "restoredb")
1899-
restoreTableID, err := tc.TenantOrServer(0).ExecutorConfig().(sql.ExecutorConfig).DescIDGenerator.GenerateUniqueDescID(ctx)
1899+
restoreTableID, err := tc.ApplicationLayer(0).ExecutorConfig().(sql.ExecutorConfig).DescIDGenerator.GenerateUniqueDescID(ctx)
19001900
if err != nil {
19011901
t.Fatal(err)
19021902
}
@@ -5441,7 +5441,7 @@ func TestBackupRestoreSequenceOwnership(t *testing.T) {
54415441
origDB.Exec(t, `BACKUP DATABASE d TO $1`, backupLoc)
54425442

54435443
getTableDescriptorFromTestCluster := func(tc *testcluster.TestCluster, database string, table string) catalog.TableDescriptor {
5444-
srv := tc.TenantOrServer(0)
5444+
srv := tc.ApplicationLayer(0)
54455445
return desctestutils.TestingGetPublicTableDescriptor(srv.DB(), srv.Codec(), database, table)
54465446
}
54475447

@@ -5844,7 +5844,7 @@ func TestBatchedInsertStats(t *testing.T) {
58445844
}}
58455845
server, db, _ := serverutils.StartServer(t, params)
58465846
defer server.Stopper().Stop(context.Background())
5847-
s := server.TenantOrServer()
5847+
s := server.ApplicationLayer()
58485848
sqlDB := sqlutils.MakeSQLRunner(db)
58495849
ctx := context.Background()
58505850
execCfg := s.ExecutorConfig().(sql.ExecutorConfig)
@@ -6393,7 +6393,7 @@ func TestRestoreErrorPropagates(t *testing.T) {
63936393
runner := sqlutils.MakeSQLRunner(db)
63946394

63956395
jobsTableKey.Lock()
6396-
jobsTableKey.key = tc.TenantOrServer(0).Codec().TablePrefix(uint32(systemschema.JobsTable.GetID()))
6396+
jobsTableKey.key = tc.ApplicationLayer(0).Codec().TablePrefix(uint32(systemschema.JobsTable.GetID()))
63976397
jobsTableKey.Unlock()
63986398

63996399
runner.Exec(t, `SET CLUSTER SETTING jobs.metrics.interval.poll = '30s'`)
@@ -7513,7 +7513,7 @@ func TestClientDisconnect(t *testing.T) {
75137513
// Make credentials for the new connection.
75147514
sqlDB.Exec(t, `CREATE USER testuser`)
75157515
sqlDB.Exec(t, `GRANT admin TO testuser`)
7516-
pgURL, cleanup := sqlutils.PGUrl(t, tc.Server(0).ServingSQLAddr(),
7516+
pgURL, cleanup := sqlutils.PGUrl(t, tc.ApplicationLayer(0).AdvSQLAddr(),
75177517
"TestClientDisconnect-testuser", url.User("testuser"))
75187518
defer cleanup()
75197519

@@ -8620,7 +8620,7 @@ func TestRestoreJobEventLogging(t *testing.T) {
86208620

86218621
var forceFailure bool
86228622
for i := range tc.Servers {
8623-
tc.TenantOrServer(i).JobRegistry().(*jobs.Registry).TestingWrapResumerConstructor(
8623+
tc.ApplicationLayer(i).JobRegistry().(*jobs.Registry).TestingWrapResumerConstructor(
86248624
jobspb.TypeRestore,
86258625
func(raw jobs.Resumer) jobs.Resumer {
86268626
r := raw.(*restoreResumer)
@@ -8733,7 +8733,7 @@ func TestBackupOnlyPublicIndexes(t *testing.T) {
87338733
)
87348734
defer cleanupFn()
87358735
kvDB := tc.Server(0).DB()
8736-
codec := tc.TenantOrServer(0).ExecutorConfig().(sql.ExecutorConfig).Codec
8736+
codec := tc.ApplicationLayer(0).ExecutorConfig().(sql.ExecutorConfig).Codec
87378737

87388738
locationToDir := func(location string) string {
87398739
return strings.Replace(location, localFoo, filepath.Join(rawDir, "foo"), 1)
@@ -10225,7 +10225,7 @@ func TestBackupNoOverwriteCheckpoint(t *testing.T) {
1022510225

1022610226
// List all the BACKUP-CHECKPOINTS in the progress directory and see
1022710227
// if there are as many as we'd expect if none got overwritten.
10228-
execCfg := tc.TenantOrServer(0).ExecutorConfig().(sql.ExecutorConfig)
10228+
execCfg := tc.ApplicationLayer(0).ExecutorConfig().(sql.ExecutorConfig)
1022910229
ctx := context.Background()
1023010230
store, err := execCfg.DistSQLSrv.ExternalStorageFromURI(ctx, "userfile:///a", username.RootUserName())
1023110231
require.NoError(t, err)
@@ -10454,7 +10454,7 @@ func TestBackupRestoreTelemetryEvents(t *testing.T) {
1045410454

1045510455
var forceFailure bool
1045610456
for i := range tc.Servers {
10457-
tc.TenantOrServer(i).JobRegistry().(*jobs.Registry).TestingWrapResumerConstructor(
10457+
tc.ApplicationLayer(i).JobRegistry().(*jobs.Registry).TestingWrapResumerConstructor(
1045810458
jobspb.TypeRestore,
1045910459
func(raw jobs.Resumer) jobs.Resumer {
1046010460
r := raw.(*restoreResumer)

pkg/ccl/backupccl/create_scheduled_backup_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ func TestCreateBackupScheduleRequiresAdminRole(t *testing.T) {
971971

972972
th.sqlDB.Exec(t, `CREATE USER testuser`)
973973
pgURL, cleanupFunc := sqlutils.PGUrl(
974-
t, th.server.ServingSQLAddr(),
974+
t, th.server.ApplicationLayer().AdvSQLAddr(),
975975
"TestCreateSchedule-testuser", url.User("testuser"),
976976
)
977977
defer cleanupFunc()

pkg/ccl/backupccl/datadriven_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (d *datadrivenTestState) getSQLDB(t *testing.T, name string, user string) *
230230
if db, ok := d.sqlDBs[key]; ok {
231231
return db
232232
}
233-
addr := d.firstNode[name].ServingSQLAddr()
233+
addr := d.firstNode[name].ApplicationLayer().AdvSQLAddr()
234234
pgURL, cleanup := sqlutils.PGUrl(t, addr, "TestBackupRestoreDataDriven", url.User(user))
235235
d.cleanupFns = append(d.cleanupFns, cleanup)
236236

pkg/ccl/backupccl/restore_mid_schema_change_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func validateTable(
139139
tableName string,
140140
isSchemaOnly bool,
141141
) {
142-
srv := tc.TenantOrServer(0)
142+
srv := tc.ApplicationLayer(0)
143143
desc := desctestutils.TestingGetPublicTableDescriptor(srv.DB(), srv.Codec(), dbName, tableName)
144144
// There should be no mutations on these table descriptors at this point.
145145
require.Equal(t, 0, len(desc.TableDesc().Mutations))

pkg/ccl/backupccl/show_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ func TestShowBackupPrivileges(t *testing.T) {
681681
sqlDB.Exec(t, `CREATE USER testuser`)
682682
sqlDB.Exec(t, `CREATE TABLE privs (a INT)`)
683683

684-
pgURL, cleanup := sqlutils.PGUrl(t, srv.ServingSQLAddr(),
684+
pgURL, cleanup := sqlutils.PGUrl(t, srv.ApplicationLayer().AdvSQLAddr(),
685685
"TestShowBackupPrivileges-testuser", url.User("testuser"))
686686
defer cleanup()
687687
testuser, err := gosql.Open("postgres", pgURL.String())

pkg/ccl/changefeedccl/alter_changefeed_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ func TestAlterChangefeedPersistSinkURI(t *testing.T) {
662662

663663
s, rawSQLDB, _ := serverutils.StartServer(t, base.TestServerArgs{})
664664
sqlDB := sqlutils.MakeSQLRunner(rawSQLDB)
665-
registry := s.TenantOrServer().JobRegistry().(*jobs.Registry)
665+
registry := s.ApplicationLayer().JobRegistry().(*jobs.Registry)
666666
ctx := context.Background()
667667
defer s.Stopper().Stop(ctx)
668668

0 commit comments

Comments
 (0)