Skip to content

Commit c5c00d9

Browse files
committed
roachprod: remove c.TargetNodes
This was a vestigial method from when c.Nodes was a list of ints instead of Nodes to convert c.Nodes to []Nodes. Now that it is no longer needed, we can remove it entirely.
1 parent bf5dd77 commit c5c00d9

File tree

4 files changed

+28
-35
lines changed

4 files changed

+28
-35
lines changed

pkg/roachprod/install/cluster_synced.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ type SyncedCluster struct {
7070

7171
// Nodes is used by most commands (e.g. Start, Stop, Monitor). It describes
7272
// the list of nodes the operation pertains to.
73+
// $ roachprod create local -n 4
74+
// $ roachprod start local # [1, 2, 3, 4]
75+
// $ roachprod start local:2-4 # [2, 3, 4]
76+
// $ roachprod start local:2,1,4 # [1, 2, 4]
7377
Nodes Nodes
7478

7579
ClusterSettings
@@ -239,17 +243,6 @@ func (c *SyncedCluster) localVMDir(n Node) string {
239243
return local.VMDir(c.Name, int(n))
240244
}
241245

242-
// TargetNodes is the fully expanded, ordered list of nodes that any given
243-
// roachprod command is intending to target.
244-
//
245-
// $ roachprod create local -n 4
246-
// $ roachprod start local # [1, 2, 3, 4]
247-
// $ roachprod start local:2-4 # [2, 3, 4]
248-
// $ roachprod start local:2,1,4 # [1, 2, 4]
249-
func (c *SyncedCluster) TargetNodes() Nodes {
250-
return append(Nodes{}, c.Nodes...)
251-
}
252-
253246
// GetInternalIP returns the internal IP address of the specified node.
254247
func (c *SyncedCluster) GetInternalIP(n Node) (string, error) {
255248
if c.IsLocal() {

pkg/roachprod/install/cockroach.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func (c *SyncedCluster) fetchVersion(
405405
// Starting the first node is special-cased quite a bit, it's used to distribute
406406
// certs, set cluster settings, and initialize the cluster. Also, if we're only
407407
// starting a single node in the cluster and it happens to be the "first" node
408-
// (node 1, as understood by SyncedCluster.TargetNodes), we use
408+
// (node 1, as understood by SyncedCluster.Nodes), we use
409409
// `start-single-node` (this was written to provide a short hand to start a
410410
// single node cluster with a replication factor of one).
411411
func (c *SyncedCluster) Start(ctx context.Context, l *logger.Logger, startOpts StartOpts) error {
@@ -1306,7 +1306,7 @@ func (c *SyncedCluster) createAdminUserForSecureCluster(
13061306
retryOpts := retry.Options{MaxRetries: 20}
13071307
if err := retryOpts.Do(ctx, func(ctx context.Context) error {
13081308
// We use the first node in the virtual cluster to create the user.
1309-
firstNode := c.TargetNodes()[0]
1309+
firstNode := c.Nodes[0]
13101310
results, err := c.ExecSQL(
13111311
ctx, l, Nodes{firstNode}, virtualClusterName, sqlInstance, AuthRootCert, "", /* database */
13121312
[]string{"-e", stmts})
@@ -1509,7 +1509,7 @@ func (c *SyncedCluster) distributeCerts(ctx context.Context, l *logger.Logger) e
15091509
if !c.Secure {
15101510
return nil
15111511
}
1512-
for _, node := range c.TargetNodes() {
1512+
for _, node := range c.Nodes {
15131513
if node == 1 {
15141514
return c.DistributeCerts(ctx, l, false)
15151515
}

pkg/roachprod/install/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func (c *SyncedCluster) Monitor(
346346
) chan NodeMonitorInfo {
347347
ch := make(chan NodeMonitorInfo)
348348

349-
nodes := c.TargetNodes()
349+
nodes := c.Nodes
350350
var wg sync.WaitGroup
351351
monitorCtx, cancel := context.WithCancel(ctx)
352352

pkg/roachprod/roachprod.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func Run(
433433
}
434434
// If no nodes were specified, run on nodes derived from the clusterName.
435435
if len(options.Nodes) == 0 {
436-
options.Nodes = c.TargetNodes()
436+
options.Nodes = c.Nodes
437437
}
438438

439439
cmd := strings.TrimSpace(strings.Join(cmdArray, " "))
@@ -461,7 +461,7 @@ func RunWithDetails(
461461
}
462462
// If no nodes were specified, run on nodes derived from the clusterName.
463463
if len(options.Nodes) == 0 {
464-
options.Nodes = c.TargetNodes()
464+
options.Nodes = c.Nodes
465465
}
466466
cmd := strings.TrimSpace(strings.Join(cmdArray, " "))
467467
return c.RunWithDetails(ctx, l, options, TruncateString(cmd, 30), cmd)
@@ -557,7 +557,7 @@ func IP(l *logger.Logger, clusterName string, external bool) ([]string, error) {
557557
return nil, err
558558
}
559559

560-
nodes := c.TargetNodes()
560+
nodes := c.Nodes
561561
ips := make([]string, len(nodes))
562562

563563
for i := 0; i < len(nodes); i++ {
@@ -1126,7 +1126,7 @@ func PgURL(
11261126
if err != nil {
11271127
return nil, err
11281128
}
1129-
nodes := c.TargetNodes()
1129+
nodes := c.Nodes
11301130
ips := make([]string, len(nodes))
11311131
if opts.External {
11321132
for i := 0; i < len(nodes); i++ {
@@ -1262,7 +1262,7 @@ func AdminURL(
12621262
virtualClusterName: virtualClusterName,
12631263
sqlInstance: sqlInstance,
12641264
}
1265-
return urlGenerator(ctx, c, l, c.TargetNodes(), uConfig)
1265+
return urlGenerator(ctx, c, l, c.Nodes, uConfig)
12661266
}
12671267

12681268
// SQLPorts finds the SQL ports for a cluster.
@@ -1350,7 +1350,7 @@ func Pprof(ctx context.Context, l *logger.Logger, clusterName string, opts Pprof
13501350

13511351
httpClient := httputil.NewClientWithTimeout(timeout)
13521352
startTime := timeutil.Now().Unix()
1353-
err = c.Parallel(ctx, l, install.WithNodes(c.TargetNodes()).WithDisplay(description),
1353+
err = c.Parallel(ctx, l, install.WithNodes(c.Nodes).WithDisplay(description),
13541354
func(ctx context.Context, node install.Node) (*install.RunResultDetails, error) {
13551355
res := &install.RunResultDetails{Node: node}
13561356
host := c.Host(node)
@@ -2131,7 +2131,7 @@ func CreateSnapshot(
21312131
return nil, err
21322132
}
21332133

2134-
nodes := c.TargetNodes()
2134+
nodes := c.Nodes
21352135
nodesStatus, err := c.Status(ctx, l)
21362136

21372137
if err != nil {
@@ -2263,13 +2263,13 @@ func ApplySnapshots(
22632263
return err
22642264
}
22652265

2266-
if n := len(c.TargetNodes()); n != len(snapshots) {
2266+
if n := len(c.Nodes); n != len(snapshots) {
22672267
return fmt.Errorf("mismatched number of snapshots (%d) to node count (%d)", len(snapshots), n)
22682268
// TODO(irfansharif): Validate labels (version, instance types).
22692269
}
22702270

22712271
// Detach and delete existing volumes. This is destructive.
2272-
if err := c.Parallel(ctx, l, install.WithNodes(c.TargetNodes()),
2272+
if err := c.Parallel(ctx, l, install.WithNodes(c.Nodes),
22732273
func(ctx context.Context, node install.Node) (*install.RunResultDetails, error) {
22742274
res := &install.RunResultDetails{Node: node}
22752275

@@ -2294,7 +2294,7 @@ func ApplySnapshots(
22942294
return err
22952295
}
22962296

2297-
return c.Parallel(ctx, l, install.WithNodes(c.TargetNodes()),
2297+
return c.Parallel(ctx, l, install.WithNodes(c.Nodes),
22982298
func(ctx context.Context, node install.Node) (*install.RunResultDetails, error) {
22992299
res := &install.RunResultDetails{Node: node}
23002300

@@ -2406,7 +2406,7 @@ func StartJaeger(
24062406
// install from source or get linux binaries and start them
24072407
// with systemd. For now this just matches what we've been
24082408
// copy and pasting.
2409-
jaegerNode := c.TargetNodes()[len(c.TargetNodes())-1:]
2409+
jaegerNode := c.Nodes[len(c.Nodes)-1:]
24102410
err = install.InstallTool(ctx, l, c, jaegerNode, "docker", l.Stdout, l.Stderr)
24112411
if err != nil {
24122412
return err
@@ -2458,7 +2458,7 @@ func StopJaeger(ctx context.Context, l *logger.Logger, clusterName string) error
24582458
if err != nil {
24592459
return err
24602460
}
2461-
jaegerNode := c.TargetNodes()[len(c.TargetNodes())-1:]
2461+
jaegerNode := c.Nodes[len(c.Nodes)-1:]
24622462
stopCmd := fmt.Sprintf("docker stop %s", jaegerContainerName)
24632463
err = c.Run(ctx, l, l.Stdout, l.Stderr, install.WithNodes(jaegerNode), stopCmd, stopCmd)
24642464
if err != nil {
@@ -2477,7 +2477,7 @@ func JaegerURL(
24772477
if err != nil {
24782478
return "", err
24792479
}
2480-
jaegerNode := c.TargetNodes()[len(c.TargetNodes())-1:]
2480+
jaegerNode := c.Nodes[len(c.Nodes)-1:]
24812481
urls, err := urlGenerator(ctx, c, l, jaegerNode, urlConfig{
24822482
usePublicIP: true,
24832483
openInBrowser: openInBrowser,
@@ -2619,7 +2619,7 @@ func StorageCollectionPerformAction(
26192619
}
26202620

26212621
func printNodeToVolumeMapping(c *install.SyncedCluster) {
2622-
nodes := c.TargetNodes()
2622+
nodes := c.Nodes
26232623
for _, n := range nodes {
26242624
cVM := c.VMs[n-1]
26252625
for _, volume := range cVM.NonBootAttachedVolumes {
@@ -2633,7 +2633,7 @@ func printNodeToVolumeMapping(c *install.SyncedCluster) {
26332633
func sendCaptureCommand(
26342634
ctx context.Context, l *logger.Logger, c *install.SyncedCluster, action string, captureDir string,
26352635
) error {
2636-
nodes := c.TargetNodes()
2636+
nodes := c.Nodes
26372637
httpClient := httputil.NewClientWithTimeout(0 /* timeout: None */)
26382638
_, _, err := c.ParallelE(ctx, l, install.WithNodes(nodes).WithDisplay(fmt.Sprintf("Performing workload capture %s", action)),
26392639
func(ctx context.Context, node install.Node) (*install.RunResultDetails, error) {
@@ -2713,7 +2713,7 @@ func createAttachMountVolumes(
27132713
opts vm.VolumeCreateOpts,
27142714
mountDir string,
27152715
) error {
2716-
nodes := c.TargetNodes()
2716+
nodes := c.Nodes
27172717
for idx, n := range nodes {
27182718
curNode := nodes[idx : idx+1]
27192719

@@ -2780,7 +2780,7 @@ func CreateLoadBalancer(
27802780
// Find the SQL ports for the service on all nodes.
27812781
services, err := c.DiscoverServices(
27822782
ctx, virtualClusterName, install.ServiceTypeSQL,
2783-
install.ServiceNodePredicate(c.TargetNodes()...), install.ServiceInstancePredicate(sqlInstance),
2783+
install.ServiceNodePredicate(c.Nodes...), install.ServiceInstancePredicate(sqlInstance),
27842784
)
27852785
if err != nil {
27862786
return err
@@ -2909,7 +2909,7 @@ func Deploy(
29092909
}
29102910

29112911
stageDir := "stage-cockroach"
2912-
err = c.Run(ctx, l, l.Stdout, l.Stderr, install.WithNodes(c.TargetNodes()), "creating staging dir",
2912+
err = c.Run(ctx, l, l.Stdout, l.Stderr, install.WithNodes(c.Nodes), "creating staging dir",
29132913
fmt.Sprintf("rm -rf %[1]s && mkdir -p %[1]s", stageDir))
29142914
if err != nil {
29152915
return err
@@ -2919,7 +2919,7 @@ func Deploy(
29192919
if pathToBinary == "" {
29202920
return errors.Errorf("%s application requires a path to the binary", applicationName)
29212921
}
2922-
err = c.Put(ctx, l, c.TargetNodes(), pathToBinary, filepath.Join(stageDir, "cockroach"))
2922+
err = c.Put(ctx, l, c.Nodes, pathToBinary, filepath.Join(stageDir, "cockroach"))
29232923
} else {
29242924
err = Stage(ctx, l, clusterName, "", "", stageDir, applicationName, version)
29252925
}
@@ -2929,7 +2929,7 @@ func Deploy(
29292929
}
29302930

29312931
l.Printf("Performing rolling restart of %d nodes on %s", len(c.VMs), clusterName)
2932-
for _, node := range c.TargetNodes() {
2932+
for _, node := range c.Nodes {
29332933
curNode := []install.Node{node}
29342934

29352935
err = c.WithNodes(curNode).Stop(ctx, l, sig, wait, gracePeriod, "")

0 commit comments

Comments
 (0)