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

server,serverutils: simplify interfaces #109591

Merged
merged 1 commit into from
Sep 1, 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
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/backup_tenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestBackupTenantImportingTable(t *testing.T) {
t.Fatal(err)
}
// Destroy the tenant, then restore it.
tSrv.Stopper().Stop(ctx)
tSrv.AppStopper().Stop(ctx)
if _, err := sqlDB.DB.ExecContext(ctx, "ALTER TENANT [10] STOP SERVICE; DROP TENANT [10] IMMEDIATE"); err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8964,10 +8964,7 @@ func TestRestorePauseOnError(t *testing.T) {

var forceFailure bool
for i := range tc.Servers {
jobRegistry := tc.Servers[i].JobRegistry()
if tc.StartedDefaultTestTenant() {
jobRegistry = tc.Servers[i].TestTenants()[0].JobRegistry()
}
jobRegistry := tc.Servers[i].ApplicationLayer().JobRegistry()

jobRegistry.(*jobs.Registry).TestingWrapResumerConstructor(
jobspb.TypeRestore,
Expand Down
9 changes: 3 additions & 6 deletions pkg/ccl/backupccl/datadriven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,12 +826,9 @@ func runTestDataDriven(t *testing.T, testFilePathFromWorkspace string) {
return ""

case "create-dummy-system-table":
db := ds.firstNode[lastCreatedCluster].DB()
execCfg := ds.firstNode[lastCreatedCluster].ExecutorConfig().(sql.ExecutorConfig)
testTenants := ds.firstNode[lastCreatedCluster].TestTenants()
if len(testTenants) > 0 {
execCfg = testTenants[0].ExecutorConfig().(sql.ExecutorConfig)
}
al := ds.firstNode[lastCreatedCluster].ApplicationLayer()
db := al.DB()
execCfg := al.ExecutorConfig().(sql.ExecutorConfig)
codec := execCfg.Codec
dummyTable := systemschema.SettingsTable
err := db.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/changefeedccl/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func startTestTenant(
waitForTenantPodsActive(t, tenantServer, 1)
resetRetry := testingUseFastRetry()
return tenantID, tenantServer, tenantDB, func() {
tenantServer.Stopper().Stop(ctx)
tenantServer.AppStopper().Stop(ctx)
resetRetry()
}
}
Expand Down
16 changes: 4 additions & 12 deletions pkg/ccl/changefeedccl/kvfeed/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/kvevent"
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/desctestutils"
Expand Down Expand Up @@ -52,31 +51,24 @@ func (r *recordResolvedWriter) AcquireMemory(ctx context.Context, n int64) (kvev
return kvevent.Alloc{}, nil
}

func tenantOrSystemCodec(s serverutils.TestServerInterface) keys.SQLCodec {
var codec = s.Codec()
if len(s.TestTenants()) > 0 {
codec = s.TestTenants()[0].Codec()
}
return codec
}

var _ kvevent.Writer = (*recordResolvedWriter)(nil)

func TestEmitsResolvedDuringScan(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

ctx := context.Background()
s, db, kvdb := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop(ctx)
srv, db, kvdb := serverutils.StartServer(t, base.TestServerArgs{})
defer srv.Stopper().Stop(ctx)
s := srv.ApplicationLayer()

sqlDB := sqlutils.MakeSQLRunner(db)
sqlDB.Exec(t, `
CREATE TABLE t (a INT PRIMARY KEY);
INSERT INTO t VALUES (1), (2), (3);
`)

codec := tenantOrSystemCodec(s)
codec := s.Codec()
descr := desctestutils.TestingGetPublicTableDescriptor(kvdb, codec, "defaultdb", "t")
span := tableSpan(codec, uint32(descr.GetID()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func FetchDescVersionModificationTime(
version int,
) hlc.Timestamp {
db := serverutils.OpenDBConn(
t, s.SQLAddr(), dbName, false, s.Stopper())
t, s.SQLAddr(), dbName, false, s.AppStopper())

tblKey := s.Codec().TablePrefix(keys.DescriptorTableID)
header := kvpb.RequestHeader{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestDataDriven(t *testing.T) {
ts := srv.ApplicationLayer()

tdb := sqlutils.MakeSQLRunner(sqlDB)
ctx, cancel := ts.Stopper().WithCancelOnQuiesce(ctx)
ctx, cancel := ts.AppStopper().WithCancelOnQuiesce(ctx)
defer cancel()
schemaFeeds := map[int]schemafeed.SchemaFeed{}
parseTargets := func(t *testing.T, in string) (targets changefeedbase.Targets) {
Expand Down
14 changes: 7 additions & 7 deletions pkg/ccl/kvccl/kvtenantccl/upgradeccl/tenant_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestTenantUpgrade(t *testing.T) {
db.CheckQueryResults(t, "SHOW CLUSTER SETTING version", [][]string{{v2.String()}})

t.Log("restart the tenant")
tenantServer.Stopper().Stop(ctx)
tenantServer.AppStopper().Stop(ctx)
tenantServer, err := ts.StartTenant(ctx, base.TestTenantArgs{
TenantID: roachpb.MustMakeTenantID(initialTenantID),
})
Expand All @@ -150,7 +150,7 @@ func TestTenantUpgrade(t *testing.T) {
"SHOW CLUSTER SETTING version", [][]string{{v2.String()}})

t.Log("restart the new tenant")
tenant.Stopper().Stop(ctx)
tenant.AppStopper().Stop(ctx)
var err error
tenant, err = ts.StartTenant(ctx, base.TestTenantArgs{
TenantID: roachpb.MustMakeTenantID(postUpgradeTenantID),
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestTenantUpgradeFailure(t *testing.T) {
// Wait until we are sure the stopper is quiescing.
for {
select {
case <-tenant.Stopper().ShouldQuiesce():
case <-tenant.AppStopper().ShouldQuiesce():
return nil
default:
continue
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestTenantUpgradeFailure(t *testing.T) {
go func() {
<-tenantStopperChannel
t.Log("received async notification to stop tenant")
tenant.Stopper().Stop(ctx)
tenant.AppStopper().Stop(ctx)
t.Log("tenant stopped")
waitForTenantClose <- struct{}{}
}()
Expand Down Expand Up @@ -344,9 +344,9 @@ func TestTenantUpgradeFailure(t *testing.T) {
[][]string{{v1.String()}})

t.Log("restart the tenant")
tenant.Stopper().Stop(ctx)
tenant.AppStopper().Stop(ctx)
tenant, conn = startAndConnectToTenant(t, initialTenantID)
defer tenant.Stopper().Stop(ctx)
defer tenant.AppStopper().Stop(ctx)
db = sqlutils.MakeSQLRunner(conn)

// Keep trying to resume the stopper channel until the channel is closed,
Expand Down Expand Up @@ -380,6 +380,6 @@ func TestTenantUpgradeFailure(t *testing.T) {
"SELECT * FROM t", [][]string{{"1"}, {"2"}})
db.CheckQueryResults(t,
"SHOW CLUSTER SETTING version", [][]string{{v2.String()}})
tenant.Stopper().Stop(ctx)
tenant.AppStopper().Stop(ctx)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func runTest(t *testing.T, variant sharedtestutil.TestVariant, test sharedtestut
}
tenant, err := tc.Server(0).StartTenant(ctx, tenantArgs)
require.NoError(t, err)
return tenant.SQLConn(t, ""), func() { tenant.Stopper().Stop(ctx) }
return tenant.SQLConn(t, ""), func() { tenant.AppStopper().Stop(ctx) }
}

logf("creating an initial tenant server")
Expand Down Expand Up @@ -292,7 +292,7 @@ func runTest(t *testing.T, variant sharedtestutil.TestVariant, test sharedtestut
logf("shutting down the other tenant server")
otherServerStopper.Stop(ctx)
} else if otherServerStartError == nil {
defer otherServer.Stopper().Stop(ctx)
defer otherServer.AppStopper().Stop(ctx)
otherTenant := otherServer.SQLConn(t, "")
otherTenantRunner = sqlutils.MakeSQLRunner(otherTenant)
numTenantsStr = "2"
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/multiregionccl/cold_start_latency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ COMMIT;`}
SELECT checkpoint > extract(epoch from after)
FROM checkpoint, after`,
[][]string{{"true"}})
tenant.Stopper().Stop(ctx)
tenant.AppStopper().Stop(ctx)
}

// Wait for the configs to be applied.
Expand Down Expand Up @@ -328,7 +328,7 @@ SELECT checkpoint > extract(epoch from after)
Locality: localities[i],
})
require.NoError(t, err)
defer tenant.Stopper().Stop(ctx)
defer tenant.AppStopper().Stop(ctx)
pgURL, cleanup, err := sqlutils.PGUrlWithOptionalClientCertsE(
tenant.AdvSQLAddr(), "tenantdata", url.UserPassword("foo", password),
false, // withClientCerts
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/multiregionccl/multiregion_system_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"testing"
"time"

"github.com/cockroachdb/apd/v3"
apd "github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/ccl/multiregionccl/multiregionccltestutils"
"github.com/cockroachdb/cockroach/pkg/roachpb"
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestMultiRegionTenantRegions(t *testing.T) {
},
},
})
defer ten.Stopper().Stop(ctx)
defer ten.AppStopper().Stop(ctx)
defer tSQL.Close()
tenSQLDB := sqlutils.MakeSQLRunner(tSQL)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ sql.virtual_cluster.feature_access.multiregion.enabled = true;`)
TenantID: serverutils.TestTenantID(),
UseDatabase: "defaultdb",
})
defer tenant.Stopper().Stop(ctx)
defer tenant.AppStopper().Stop(ctx)

tdb := sqlutils.MakeSQLRunner(tenantDB)
tdb.Exec(t, `ALTER DATABASE system SET PRIMARY REGION "us-east1";`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestEstimateQueryRUConsumption(t *testing.T) {
},
},
})
defer tenant1.Stopper().Stop(ctx)
defer tenant1.AppStopper().Stop(ctx)
defer tenantDB1.Close()
tdb := sqlutils.MakeSQLRunner(tenantDB1)
tdb.Exec(t, "SET CLUSTER SETTING sql.stats.automatic_collection.enabled=false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ func TestRUSettingsChanged(t *testing.T) {
tenant1, tenantDB1 := serverutils.StartTenant(t, s, base.TestTenantArgs{
TenantID: tenantID,
})
defer tenant1.Stopper().Stop(ctx)
defer tenant1.AppStopper().Stop(ctx)
defer tenantDB1.Close()

costClient, err := tenantcostclient.NewTenantSideCostController(tenant1.ClusterSettings(), tenantID, nil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/multitenantccl/tenantcostserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (ts *testState) start(t *testing.T) {
}

func (ts *testState) stop() {
ts.s.Stopper().Stop(context.Background())
ts.srv.Stopper().Stop(context.Background())
}

func (ts *testState) formatTime(tm time.Time) string {
Expand Down
21 changes: 8 additions & 13 deletions pkg/ccl/oidcccl/authentication_oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,21 @@ import (
"github.com/stretchr/testify/require"
)

func tenantOrSystemAdminURL(s serverutils.TestServerInterface) *serverutils.TestURL {
if len(s.TestTenants()) > 0 {
return s.TestTenants()[0].AdminURL()
}
return s.AdminURL()
}

func TestOIDCBadRequestIfDisabled(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

ctx := context.Background()
s := serverutils.StartServerOnly(t, base.TestServerArgs{})
defer s.Stopper().Stop(ctx)
srv := serverutils.StartServerOnly(t, base.TestServerArgs{})
defer srv.Stopper().Stop(ctx)
s := srv.ApplicationLayer()

testCertsContext := s.NewClientRPCContext(ctx, username.TestUserName())

client, err := testCertsContext.GetHTTPClient()
require.NoError(t, err)

resp, err := client.Get(tenantOrSystemAdminURL(s).WithPath("/oidc/v1/login").String())
resp, err := client.Get(s.AdminURL().WithPath("/oidc/v1/login").String())
if err != nil {
t.Fatalf("could not issue GET request to admin server: %s", err)
}
Expand All @@ -69,8 +63,9 @@ func TestOIDCEnabled(t *testing.T) {
defer log.Scope(t).Close(t)

ctx := context.Background()
s, db, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop(ctx)
srv, db, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer srv.Stopper().Stop(ctx)
s := srv.ApplicationLayer()

// Set up a test OIDC server that serves the JSON discovery document
var issuer string
Expand Down Expand Up @@ -164,7 +159,7 @@ func TestOIDCEnabled(t *testing.T) {
}

t.Run("login redirect", func(t *testing.T) {
resp, err := client.Get(tenantOrSystemAdminURL(s).WithPath("/oidc/v1/login").String())
resp, err := client.Get(s.AdminURL().WithPath("/oidc/v1/login").String())
if err != nil {
t.Fatalf("could not issue GET request to admin server: %s", err)
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/ccl/partitionccl/drop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ func TestDropIndexWithZoneConfigCCL(t *testing.T) {
SkipWaitingForMVCCGC: true,
},
}
s, sqlDBRaw, kvDB := serverutils.StartServer(t, params)
srv, sqlDBRaw, kvDB := serverutils.StartServer(t, params)
defer srv.Stopper().Stop(context.Background())
s := srv.ApplicationLayer()

sqlDB := sqlutils.MakeSQLRunner(sqlDBRaw)
defer s.Stopper().Stop(context.Background())

// Create a test table with a partitioned secondary index.
if err := tests.CreateKVTable(sqlDBRaw, "kv", numRows); err != nil {
Expand All @@ -74,7 +76,7 @@ func TestDropIndexWithZoneConfigCCL(t *testing.T) {
PARTITION p1 VALUES IN (1),
PARTITION p2 VALUES IN (2)
)`)
codec := tenantOrSystemCodec(s)
codec := s.Codec()
tableDesc := desctestutils.TestingGetPublicTableDescriptor(kvDB, codec, "t", "kv")
index, err := catalog.MustFindIndexByName(tableDesc, "i")
if err != nil {
Expand Down
Loading