Skip to content

Commit

Permalink
server: make cli-ready startTenant method()
Browse files Browse the repository at this point in the history
The goal is to turn `testSQLServerArgs` into something that can be
re-used to introduce a cli command for starting a SQL tenant. This
commit takes a step in that direction by lifting some testing-specific
inputs up.

Release note: None
  • Loading branch information
tbg committed May 29, 2020
1 parent e487d70 commit 1a27edc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ func NewServer(cfg Config, stopper *stop.Stopper) (*Server, error) {
registry: registry,
sessionRegistry: sessionRegistry,
circularInternalExecutor: internalExecutor,
jobRegistry: jobRegistry,
circularJobRegistry: jobRegistry,
jobAdoptionStopFile: jobAdoptionStopFile,
protectedtsProvider: protectedtsProvider,
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/server_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ type sqlServerArgs struct {
// The protected timestamps KV subsystem depends on this, so we pass a
// pointer to an empty struct in this configuration, which newSQLServer
// fills.
jobRegistry *jobs.Registry
circularJobRegistry *jobs.Registry
jobAdoptionStopFile string

// The executorConfig uses the provider.
Expand All @@ -176,7 +176,7 @@ func newSQLServer(ctx context.Context, cfg sqlServerArgs) (*sqlServer, error) {
}
blobspb.RegisterBlobServer(cfg.grpcServer, blobService)

jobRegistry := cfg.jobRegistry
jobRegistry := cfg.circularJobRegistry

{
regLiveness := cfg.nodeLiveness
Expand Down
50 changes: 26 additions & 24 deletions pkg/server/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,10 @@ func (d dummyProtectedTSProvider) Protect(context.Context, *kv.Txn, *ptpb.Record
// this is tracked in https://github.com/cockroachdb/cockroach/issues/47892.
const fakeNodeID = roachpb.NodeID(1)

func testSQLServerArgs(
stopper *stop.Stopper, kvClusterName string, tenID roachpb.TenantID,
func makeSQLServerArgs(
stopper *stop.Stopper, kvClusterName string, baseCfg BaseConfig, sqlCfg SQLConfig,
) sqlServerArgs {

st := cluster.MakeTestingClusterSettings()

sqlCfg := makeTestSQLConfig(st, tenID)

baseCfg := makeTestBaseConfig(st)
st := baseCfg.Settings
baseCfg.AmbientCtx.AddLogTag("sql", nil)
// TODO(tbg): this is needed so that the RPC heartbeats between the testcluster
// and this tenant work.
Expand Down Expand Up @@ -582,14 +577,14 @@ func testSQLServerArgs(
grpcServer: dummyRPCServer,
recorder: dummyRecorder,
isMeta1Leaseholder: func(timestamp hlc.Timestamp) (bool, error) {
return false, errors.New("fake isMeta1Leaseholder")
return false, errors.New("isMeta1Leaseholder is not available to tenants")
},
nodeIDContainer: idContainer,
externalStorage: func(ctx context.Context, dest roachpb.ExternalStorage) (cloud.ExternalStorage, error) {
return nil, errors.New("fake external storage")
return nil, errors.New("external storage is not available to tenants")
},
externalStorageFromURI: func(ctx context.Context, uri string) (cloud.ExternalStorage, error) {
return nil, errors.New("fake external uri storage")
return nil, errors.New("external uri storage is not available to tenants")
},
},
SQLConfig: &sqlCfg,
Expand All @@ -601,7 +596,7 @@ func testSQLServerArgs(
registry: registry,
sessionRegistry: sql.NewSessionRegistry(),
circularInternalExecutor: circularInternalExecutor,
jobRegistry: &jobs.Registry{},
circularJobRegistry: &jobs.Registry{},
protectedtsProvider: protectedTSProvider,
}
}
Expand All @@ -616,25 +611,32 @@ func (ts *TestServer) StartTenant(params base.TestTenantArgs) (pgAddr string, _
return "", err
}

return startTenant(ts.Stopper(), ts.Cfg.ClusterName, ts.RPCAddr(), params.TenantID, params.AllowSettingClusterSettings)
st := cluster.MakeTestingClusterSettings()
sqlCfg := makeTestSQLConfig(st, params.TenantID)
baseCfg := makeTestBaseConfig(st)
if params.AllowSettingClusterSettings {
baseCfg.TestingKnobs.TenantTestingKnobs = &sql.TenantTestingKnobs{
ClusterSettingsUpdater: st.MakeUpdater(),
}
}
return startTenant(
ts.Stopper(),
ts.Cfg.ClusterName,
ts.RPCAddr(),
baseCfg,
sqlCfg,
)
}

func startTenant(
stopper *stop.Stopper,
kvClusterName string,
kvClusterName string, // NB: gone after https://github.com/cockroachdb/cockroach/issues/42519
tsRPCAddr string,
tenID roachpb.TenantID,
allowSetClusterSetting bool,
baseCfg BaseConfig,
sqlCfg SQLConfig,
) (pgAddr string, _ error) {
args := testSQLServerArgs(stopper, kvClusterName, tenID)
// TODO(tbg): clean this up.
if allowSetClusterSetting {
args.TestingKnobs.TenantTestingKnobs = &sql.TenantTestingKnobs{
ClusterSettingsUpdater: args.Settings.MakeUpdater(),
}
}
args := makeSQLServerArgs(stopper, kvClusterName, baseCfg, sqlCfg)
ctx := context.Background()

s, err := newSQLServer(ctx, args)
if err != nil {
return "", err
Expand Down

0 comments on commit 1a27edc

Please sign in to comment.