Skip to content

Commit

Permalink
roachprod: reuse start script if start is called with --restart=true
Browse files Browse the repository at this point in the history
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: #125085
Release note: None
  • Loading branch information
vidit-bhat committed Aug 20, 2024
1 parent 1e8073b commit b31a6ae
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 b31a6ae

Please sign in to comment.