Skip to content

Commit

Permalink
Merge #140662
Browse files Browse the repository at this point in the history
140662: testutils: add `DeploymentMode` method to `ApplicationLayerInterface` r=stevendanna,herkolategan a=shubhamdhama

Certain tests need to determine the deployment mode of the test
server—whether it's single-tenant, shared-process, or external-process.
While this can be queried via SQL, a dedicated helper method improves
usability.

This commit adds `DeploymentMode` to `ApplicationLayerInterface` to provide
a simpler way to retrieve this information.

Informs: #138912
Epic: CRDB-38970
Release note: None

Co-authored-by: Shubham Dhama <[email protected]>
  • Loading branch information
craig[bot] and shubhamdhama committed Feb 13, 2025
2 parents 9598211 + 9413682 commit 83b38f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/server/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,9 @@ type testTenant struct {
// pgPreServer handles SQL connections prior to routing them to a
// specific tenant.
pgPreServer *pgwire.PreServeConnHandler
// deploymentMode specifies the tenant's deployment mode.
// Allowed values: ExternalProcess or SharedProcess.
deploymentMode serverutils.DeploymentMode
}

var _ serverutils.ApplicationLayerInterface = &testTenant{}
Expand Down Expand Up @@ -1258,6 +1261,11 @@ func (t *testTenant) SettingsWatcher() interface{} {
return t.sql.settingsWatcher
}

// DeploymentMode is part of the serverutils.ApplicationLayerInterface.
func (t *testTenant) DeploymentMode() serverutils.DeploymentMode {
return t.deploymentMode
}

// WaitForTenantCapabilities is part of the serverutils.TenantControlInterface.
func (ts *testServer) WaitForTenantCapabilities(
ctx context.Context,
Expand Down Expand Up @@ -1415,6 +1423,7 @@ func (ts *testServer) StartSharedProcessTenant(
pgL: sqlServerWrapper.loopbackPgL,
httpTestServer: hts,
drain: sqlServerWrapper.drainServer,
deploymentMode: serverutils.SharedProcess,
}

sqlDB, err := ts.SQLConnE(serverutils.DBName("cluster:" + string(args.TenantName) + "/" + args.UseDatabase))
Expand Down Expand Up @@ -1791,6 +1800,7 @@ func (ts *testServer) StartTenant(
http: sw.http,
drain: sw.drainServer,
pgL: sw.loopbackPgL,
deploymentMode: serverutils.ExternalProcess,
}, err
}

Expand Down Expand Up @@ -1920,6 +1930,11 @@ func (ts *testServer) MustGetSQLNetworkCounter(name string) int64 {
return mustGetSQLCounterForRegistry(reg, name)
}

// DeploymentMode is part of the serverutils.ApplicationLayerInterface.
func (ts *testServer) DeploymentMode() serverutils.DeploymentMode {
return serverutils.SingleTenant
}

// Locality is part of the serverutils.ApplicationLayerInterface.
func (ts *testServer) Locality() roachpb.Locality {
return ts.cfg.Locality
Expand Down
16 changes: 16 additions & 0 deletions pkg/testutils/serverutils/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ type TestServerController interface {
RunInitialSQL(ctx context.Context, startSingleNode bool, adminUser, adminPassword string) error
}

// DeploymentMode defines the mode of the underlying test server or tenant,
// which can be single-tenant (system-only), shared-process, or
// external-process.
type DeploymentMode uint8

const (
SingleTenant DeploymentMode = iota
SharedProcess
ExternalProcess
)

// ApplicationLayerInterface defines accessors to the application
// layer of a test server. Tests written against this interface are
// effectively agnostic to whether they use a virtual cluster or not.
Expand Down Expand Up @@ -451,6 +462,11 @@ type ApplicationLayerInterface interface {

// DistSQLPlanningNodeID returns the NodeID to use by the DistSQL span resolver.
DistSQLPlanningNodeID() roachpb.NodeID

// DeploymentMode returns the deployment mode of the underlying server or
// tenant, which can be single-tenant (system-only), shared-process, or
// external-process.
DeploymentMode() DeploymentMode
}

// TenantControlInterface defines the API of a test server that can
Expand Down

0 comments on commit 83b38f5

Please sign in to comment.