Skip to content

Commit 2fac03c

Browse files
authored
Merge pull request #141 from cockroachdb/support_reset_server
support restarting / upgrading nodes
2 parents 1540631 + a7906e6 commit 2fac03c

File tree

4 files changed

+525
-184
lines changed

4 files changed

+525
-184
lines changed

testserver/tenant.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ import (
1818
"database/sql"
1919
"errors"
2020
"fmt"
21-
"github.com/cockroachdb/cockroach-go/v2/testserver/version"
2221
"log"
2322
"net"
2423
"net/url"
2524
"os/exec"
2625
"path/filepath"
2726
"strconv"
2827
"strings"
28+
29+
"github.com/cockroachdb/cockroach-go/v2/testserver/version"
2930
)
3031

3132
func (ts *testServerImpl) isTenant() bool {
@@ -53,11 +54,11 @@ func (ts *testServerImpl) NewTenantServer(proxy bool) (TestServer, error) {
5354
if proxy && !ts.serverArgs.secure {
5455
return nil, fmt.Errorf("%s: proxy cannot be used with insecure mode", tenantserverMessagePrefix)
5556
}
56-
cockroachBinary := ts.cmdArgs[0]
57+
cockroachBinary := ts.serverArgs.cockroachBinary
5758
tenantID, err := func() (int, error) {
5859
ts.mu.Lock()
5960
defer ts.mu.Unlock()
60-
if ts.state != stateRunning {
61+
if ts.nodes[0].state != stateRunning {
6162
return 0, errors.New("TestServer must be running before NewTenantServer may be called")
6263
}
6364
if ts.isTenant() {
@@ -147,7 +148,7 @@ func (ts *testServerImpl) NewTenantServer(proxy bool) (TestServer, error) {
147148
}
148149

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

152153
ts.mu.Lock()
153154
defer ts.mu.Unlock()
@@ -203,25 +204,33 @@ func (ts *testServerImpl) NewTenantServer(proxy bool) (TestServer, error) {
203204
"--http-addr=:0",
204205
}
205206

207+
nodes := []nodeInfo{
208+
{
209+
state: stateNew,
210+
startCmdArgs: args,
211+
// TODO(asubiotto): Specify listeningURLFile once we support dynamic
212+
// ports.
213+
listeningURLFile: "",
214+
},
215+
}
216+
206217
tenant := &testServerImpl{
207-
serverArgs: ts.serverArgs,
208-
version: ts.version,
209-
state: stateNew,
210-
baseDir: ts.baseDir,
211-
cmdArgs: args,
212-
stdout: filepath.Join(ts.baseDir, logsDirName, fmt.Sprintf("cockroach.tenant.%d.stdout", tenantID)),
213-
stderr: filepath.Join(ts.baseDir, logsDirName, fmt.Sprintf("cockroach.tenant.%d.stderr", tenantID)),
214-
// TODO(asubiotto): Specify listeningURLFile once we support dynamic
215-
// ports.
216-
listeningURLFile: "",
218+
serverArgs: ts.serverArgs,
219+
version: ts.version,
220+
serverState: stateNew,
221+
baseDir: ts.baseDir,
222+
stdout: filepath.Join(ts.baseDir, logsDirName, fmt.Sprintf("cockroach.tenant.%d.stdout", tenantID)),
223+
stderr: filepath.Join(ts.baseDir, logsDirName, fmt.Sprintf("cockroach.tenant.%d.stderr", tenantID)),
224+
nodes: nodes,
217225
}
218226

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

226235
tenant.setPGURL(&tenantURL)
227236
if err := tenant.Start(); err != nil {

0 commit comments

Comments
 (0)