Skip to content

Commit

Permalink
Support Start/Stop single node
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardJCai committed Jun 21, 2022
1 parent debae55 commit f6aac83
Show file tree
Hide file tree
Showing 4 changed files with 1,219 additions and 973 deletions.
12 changes: 7 additions & 5 deletions testserver/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (ts *testServerImpl) NewTenantServer(proxy bool) (TestServer, error) {
tenantID, err := func() (int, error) {
ts.mu.Lock()
defer ts.mu.Unlock()
if ts.state != stateRunning {
if ts.nodeStates[0] != stateRunning {
return 0, errors.New("TestServer must be running before NewTenantServer may be called")
}
if ts.isTenant() {
Expand Down Expand Up @@ -148,7 +148,7 @@ func (ts *testServerImpl) NewTenantServer(proxy bool) (TestServer, error) {
}

proxyAddr, err := func() (string, error) {
<-ts.pgURL.set
<-ts.pgURL[0].set

ts.mu.Lock()
defer ts.mu.Unlock()
Expand Down Expand Up @@ -208,22 +208,24 @@ func (ts *testServerImpl) NewTenantServer(proxy bool) (TestServer, error) {
serverArgs: ts.serverArgs,
version: ts.version,
state: stateNew,
nodeStates: []int{stateNew},
baseDir: ts.baseDir,
cmdArgs: args,
cmd: make([]*exec.Cmd, ts.serverArgs.numNodes),
stdout: filepath.Join(ts.baseDir, logsDirName, fmt.Sprintf("cockroach.tenant.%d.stdout", tenantID)),
stderr: filepath.Join(ts.baseDir, logsDirName, fmt.Sprintf("cockroach.tenant.%d.stderr", tenantID)),
// TODO(asubiotto): Specify listeningURLFile once we support dynamic
// ports.
listeningURLFile: "",
listeningURLFile: []string{""},
}

// Start the tenant.
// Initialize direct connection to the tenant. We need to use `orig` instead of `pgurl` because if the test server
// is using a root password, this password does not carry over to the tenant; client certs will, though.
tenantURL := ts.pgURL.orig
tenantURL := ts.pgURL[0].orig
tenantURL.Host = sqlAddr
tenant.pgURL.set = make(chan struct{})
tenant.pgURL = make([]pgURLChan, 1)
tenant.pgURL[0].set = make(chan struct{})

tenant.setPGURL(&tenantURL)
if err := tenant.Start(); err != nil {
Expand Down
Loading

0 comments on commit f6aac83

Please sign in to comment.