Skip to content

Commit 4fd9f70

Browse files
committed
serverutils: clean up some interfaces
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
1 parent 4413ec7 commit 4fd9f70

File tree

119 files changed

+662
-550
lines changed

Some content is hidden

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

119 files changed

+662
-550
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/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().ServingSQLAddr(), 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().ServingSQLAddr(), 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().ServingSQLAddr(), 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).ServingSQLAddr(),
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().ServingSQLAddr(),
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().ServingSQLAddr()
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().ServingSQLAddr(),
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

pkg/ccl/changefeedccl/changefeed_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4345,7 +4345,7 @@ func TestChangefeedSchemaTTL(t *testing.T) {
43454345
}
43464346

43474347
// TODO(samiskin): tenant tests skipped because of forceTableGC not working
4348-
// with a TestTenantInterface
4348+
// with a ApplicationLayerInterface
43494349
cdcTestWithSystem(t, testFn, feedTestNoTenants)
43504350
}
43514351

pkg/ccl/changefeedccl/helpers_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ func startTestCluster(t testing.TB) (serverutils.TestClusterInterface, *gosql.DB
472472
}
473473

474474
func waitForTenantPodsActive(
475-
t testing.TB, tenantServer serverutils.TestTenantInterface, numPods int,
475+
t testing.TB, tenantServer serverutils.ApplicationLayerInterface, numPods int,
476476
) {
477477
testutils.SucceedsWithin(t, func() error {
478478
status := tenantServer.StatusServer().(serverpb.SQLStatusServer)
@@ -490,7 +490,7 @@ func waitForTenantPodsActive(
490490

491491
func startTestTenant(
492492
t testing.TB, systemServer serverutils.TestServerInterface, options feedTestOptions,
493-
) (roachpb.TenantID, serverutils.TestTenantInterface, *gosql.DB, func()) {
493+
) (roachpb.TenantID, serverutils.ApplicationLayerInterface, *gosql.DB, func()) {
494494
knobs := base.TestingKnobs{
495495
DistSQL: &execinfra.TestingKnobs{Changefeed: &TestingKnobs{}},
496496
JobsTestingKnobs: jobs.NewTestingKnobsWithShortIntervals(),
@@ -666,7 +666,9 @@ func serverArgsRegion(args base.TestServerArgs) string {
666666
// expectNotice creates a pretty crude database connection that doesn't involve
667667
// a lot of cdc test framework, use with caution. Driver-agnostic tools don't
668668
// have clean ways of inspecting incoming notices.
669-
func expectNotice(t *testing.T, s serverutils.TestTenantInterface, sql string, expected string) {
669+
func expectNotice(
670+
t *testing.T, s serverutils.ApplicationLayerInterface, sql string, expected string,
671+
) {
670672
url, cleanup := sqlutils.PGUrl(t, s.SQLAddr(), t.Name(), url.User(username.RootUser))
671673
defer cleanup()
672674
base, err := pq.NewConnector(url.String())
@@ -762,7 +764,7 @@ func closeFeedIgnoreError(t testing.TB, f cdctest.TestFeed) {
762764
// of a test running as the system tenant or a secondary tenant
763765
type TestServer struct {
764766
DB *gosql.DB
765-
Server serverutils.TestTenantInterface
767+
Server serverutils.ApplicationLayerInterface
766768
Codec keys.SQLCodec
767769
TestingKnobs base.TestingKnobs
768770
}
@@ -912,7 +914,7 @@ func addCloudStorageOptions(t *testing.T, options *feedTestOptions) (cleanup fun
912914
func makeFeedFactory(
913915
t *testing.T,
914916
sinkType string,
915-
s serverutils.TestTenantInterface,
917+
s serverutils.ApplicationLayerInterface,
916918
db *gosql.DB,
917919
testOpts ...feedTestOption,
918920
) (factory cdctest.TestFeedFactory, sinkCleanup func()) {
@@ -924,9 +926,9 @@ func makeFeedFactoryWithOptions(
924926
t *testing.T, sinkType string, srvOrCluster interface{}, db *gosql.DB, options feedTestOptions,
925927
) (factory cdctest.TestFeedFactory, sinkCleanup func()) {
926928
t.Logf("making %s feed factory", sinkType)
927-
s := func() serverutils.TestTenantInterface {
929+
s := func() serverutils.ApplicationLayerInterface {
928930
switch s := srvOrCluster.(type) {
929-
case serverutils.TestTenantInterface:
931+
case serverutils.ApplicationLayerInterface:
930932
return s
931933
case serverutils.TestClusterInterface:
932934
return s.Server(0)
@@ -1007,7 +1009,7 @@ func makeFeedFactoryWithOptions(
10071009
}
10081010

10091011
func getInitialDBForEnterpriseFactory(
1010-
t *testing.T, s serverutils.TestTenantInterface, rootDB *gosql.DB, opts feedTestOptions,
1012+
t *testing.T, s serverutils.ApplicationLayerInterface, rootDB *gosql.DB, opts feedTestOptions,
10111013
) (*gosql.DB, func()) {
10121014
// Instead of creating enterprise changefeeds on the root connection, we may
10131015
// choose to create them on a test user connection. This user should have the

0 commit comments

Comments
 (0)