Skip to content

Commit

Permalink
cli/demo: fix connection string for shared DB server
Browse files Browse the repository at this point in the history
This is needed since the workload fixtures are not installed on the
shared server, so it only has the default databases.

Release note: None
  • Loading branch information
rafiss authored and Gerardo Torres committed Jan 24, 2022
1 parent 7e74f99 commit eaa8938
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
26 changes: 20 additions & 6 deletions pkg/cli/democluster/demo_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func (c *transientCluster) createAndAddNode(
}
nodeID := roachpb.NodeID(idx + 1)
args := c.demoCtx.testServerArgsForTransientCluster(
c.sockForServer(nodeID), nodeID, joinAddr, c.demoDir,
c.sockForServer(nodeID, "" /* databaseNameOverride */), nodeID, joinAddr, c.demoDir,
c.sqlFirstPort,
c.httpFirstPort,
c.stickyEngineRegistry,
Expand Down Expand Up @@ -944,7 +944,7 @@ func (c *transientCluster) RestartNode(ctx context.Context, nodeID int32) error
return errors.Errorf("restarting nodes is not supported in --%s configurations", cliflags.Global.Name)
}
args := c.demoCtx.testServerArgsForTransientCluster(
c.sockForServer(roachpb.NodeID(nodeID)),
c.sockForServer(roachpb.NodeID(nodeID), "" /* databaseNameOverride */),
roachpb.NodeID(nodeID),
c.firstServer.ServingRPCAddr(), c.demoDir,
c.sqlFirstPort, c.httpFirstPort, c.stickyEngineRegistry)
Expand Down Expand Up @@ -1137,13 +1137,17 @@ func (c *transientCluster) getNetworkURLForServer(
}
}
sqlAddr := c.servers[serverIdx].ServingSQLAddr()
database := c.defaultDB
if isTenant {
sqlAddr = c.tenantServers[serverIdx].SQLAddr()
}
if !isTenant && c.demoCtx.Multitenant {
database = catalogkeys.DefaultDatabaseName
}
host, port, _ := addr.SplitHostPort(sqlAddr, "")
u.
WithNet(pgurl.NetTCP(host, port)).
WithDatabase(c.defaultDB)
WithDatabase(database)

// For a demo cluster we don't use client TLS certs and instead use
// password-based authentication with the password pre-filled in the
Expand Down Expand Up @@ -1358,19 +1362,25 @@ func (c *transientCluster) AcquireDemoLicense(ctx context.Context) (chan error,
// sockForServer generates the metadata for a unix socket for the given node.
// For example, node 1 gets socket /tmpdemodir/.s.PGSQL.26267,
// node 2 gets socket /tmpdemodir/.s.PGSQL.26268, etc.
func (c *transientCluster) sockForServer(nodeID roachpb.NodeID) unixSocketDetails {
func (c *transientCluster) sockForServer(
nodeID roachpb.NodeID, databaseNameOverride string,
) unixSocketDetails {
if !c.useSockets {
return unixSocketDetails{}
}
port := strconv.Itoa(c.sqlFirstPort + int(nodeID) - 1)
databaseName := c.defaultDB
if databaseNameOverride != "" {
databaseName = databaseNameOverride
}
return unixSocketDetails{
socketDir: c.demoDir,
port: port,
u: pgurl.New().
WithNet(pgurl.NetUnix(c.demoDir, port)).
WithUsername(c.adminUser.Normalized()).
WithAuthn(pgurl.AuthnPassword(true, c.adminPassword)).
WithDatabase(c.defaultDB),
WithDatabase(databaseName),
}
}

Expand Down Expand Up @@ -1450,7 +1460,11 @@ func (c *transientCluster) ListDemoNodes(w, ew io.Writer, justOne bool) {
}
// Print unix socket if defined.
if c.useSockets {
sock := c.sockForServer(nodeID)
databaseNameOverride := ""
if c.demoCtx.Multitenant {
databaseNameOverride = catalogkeys.DefaultDatabaseName
}
sock := c.sockForServer(nodeID, databaseNameOverride)
fmt.Fprintln(w, " (sql/unix)", sock)
}
fmt.Fprintln(w)
Expand Down
20 changes: 18 additions & 2 deletions pkg/cli/interactive_tests/test_demo.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,25 @@ spawn $argv demo --insecure=true
eexpect "Welcome"
# Warn the user that they won't get persistence.
eexpect "your changes to data stored in the demo session will not be saved!"
# Inform the necessary URL.

# Verify the URLs for both shared and tenant server.
eexpect "system tenant"
eexpect "(webui)"
eexpect "http:"
eexpect "http://"
eexpect ":8081"
eexpect "(sql)"
eexpect "root"
eexpect ":26258/defaultdb"
eexpect "sslmode=disable"
eexpect "(sql/unix)"
eexpect "root:unused@/defaultdb"
eexpect "=26258"
eexpect "tenant 1"
eexpect "(sql)"
eexpect "root"
eexpect ":26257/movr"
eexpect "sslmode=disable"

# Ensure same messages as cockroach sql.
eexpect "Server version"
eexpect "Cluster ID"
Expand Down

0 comments on commit eaa8938

Please sign in to comment.