Skip to content

Commit

Permalink
Merge #124285
Browse files Browse the repository at this point in the history
124285: roachtest: save cluster earlier if debug-always is set r=srosenberg a=DarrylWong

When the --debug-always flag is passed, we mark the cluster as saved to let the cluster destroy know not to destroy it.

Previously, we only marked a cluster as saved at the end of a test. However, if the caller terminated the test through ctrl c, which also destroys all clusters, it would lead to a race condition where sometimes the cluster would not be saved in time and get destroyed.

This change moves the cluster save to immediantly after the cluster is created.

Release note: none
Fixes: none
Epic: none

Co-authored-by: DarrylWong <darryl@cockroachlabs.com>
  • Loading branch information
craig[bot] and DarrylWong committed May 17, 2024
2 parents db5d44d + dec82f2 commit f53b133
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/cmd/roachtest/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,14 @@ func (r *testRunner) runWorker(
l.PrintfCtx(ctx, "Created new cluster for test %s: %s (arch=%q)", testToRun.spec.Name, c.Name(), arch)
}
}

// If DebugKeepAlways is set, mark it as a saved cluster, so it isn't
// cleaned up. Do it now instead of at the end as the test may be interrupted
// with ctrl c before we get there.
if clustersOpt.debugMode == DebugKeepAlways {
c.Save(ctx, "cluster saved since --debug-always set", l)
}

// Prepare the test's logger. Always set this up with real files, using a
// temp dir if necessary. This simplifies testing.
artifactsRootDir := lopt.artifactsDir
Expand Down Expand Up @@ -886,6 +894,8 @@ func (r *testRunner) runWorker(
switch clustersOpt.debugMode {
case DebugKeepAlways, DebugKeepOnFailure:
// Save the cluster for future debugging.
// We already marked the cluster as a saved cluster above in the case
// of DebugKeepAlways, but update it with the failureMsg.
c.Save(ctx, failureMsg, l)

// Continue with a fresh cluster.
Expand All @@ -904,9 +914,9 @@ func (r *testRunner) runWorker(
getPerfArtifacts(ctx, c, t)
}
if clustersOpt.debugMode == DebugKeepAlways {
// We already marked the cluster as a saved cluster above.
alloc.Freeze()
alloc = nil
c.Save(ctx, "cluster saved since --debug-always set", l)
c = nil
}
}
Expand Down

0 comments on commit f53b133

Please sign in to comment.