Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
128898: roachprod: reuse start script if start is called with --restart=true r=herkolategan,renatolabs a=vidit-bhat

Previously, irrespective of the restart flag value we ended up overwriting the startup script which led to defaulting the values of other flags passed previously to the start command. This was inadequate because when restarting,
i.e., `restart=true`, it makes more sense that we would reuse the existing startup script by default. This patch changes this behaviour.

Epic: none
Fixes: cockroachdb#125085
Release note: None

Co-authored-by: Vidit Bhat <[email protected]>
  • Loading branch information
craig[bot] and vidit-bhat committed Aug 20, 2024
2 parents ba7c94a + b31a6ae commit 3894961
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions pkg/roachprod/install/cockroach.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ type StartOpts struct {
StorageCluster *SyncedCluster

// IsRestart allows skipping steps that are used during initial start like
// initialization and sequential node starts.
// initialization and sequential node starts and also reuses the previous start script.
IsRestart bool

// EnableFluentSink determines whether to enable the fluent-servers attribute
Expand Down Expand Up @@ -762,30 +762,35 @@ func (c *SyncedCluster) ExecSQL(
func (c *SyncedCluster) startNodeWithResult(
ctx context.Context, l *logger.Logger, node Node, startOpts StartOpts,
) (*RunResultDetails, error) {
startCmd, err := c.generateStartCmd(ctx, l, node, startOpts)
if err != nil {
return newRunResultDetails(node, err), err
}
var uploadCmd string
if c.IsLocal() {
uploadCmd = fmt.Sprintf(`cd %s ; `, c.localVMDir(node))
}
startScriptPath := StartScriptPath(startOpts.VirtualClusterName, startOpts.SQLInstance)
uploadCmd += fmt.Sprintf(`cat > %[1]s && chmod +x %[1]s`, startScriptPath)

var res = &RunResultDetails{}
uploadOpts := defaultCmdOpts("upload-start-script")
uploadOpts.stdin = strings.NewReader(startCmd)
res, err = c.runCmdOnSingleNode(ctx, l, node, uploadCmd, uploadOpts)
if err != nil || res.Err != nil {
return res, err
}

var runScriptCmd string
if c.IsLocal() {
runScriptCmd = fmt.Sprintf(`cd %s ; `, c.localVMDir(node))
}
runScriptCmd += "./" + startScriptPath

// If we are performing a restart, the start script should already
// exist, and we are going to reuse it.
if !startOpts.IsRestart {
startCmd, err := c.generateStartCmd(ctx, l, node, startOpts)
if err != nil {
return newRunResultDetails(node, err), err
}
var uploadCmd string
if c.IsLocal() {
uploadCmd = fmt.Sprintf(`cd %s ; `, c.localVMDir(node))
}
uploadCmd += fmt.Sprintf(`cat > %[1]s && chmod +x %[1]s`, startScriptPath)

var res = &RunResultDetails{}
uploadOpts := defaultCmdOpts("upload-start-script")
uploadOpts.stdin = strings.NewReader(startCmd)
res, err = c.runCmdOnSingleNode(ctx, l, node, uploadCmd, uploadOpts)
if err != nil || res.Err != nil {
return res, err
}
}

return c.runCmdOnSingleNode(ctx, l, node, runScriptCmd, defaultCmdOpts("run-start-script"))
}

Expand Down

0 comments on commit 3894961

Please sign in to comment.