mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
test: verify replay kill status and release failed seeds
This commit is contained in:
1 parent
25d9867619
commit
92dac05d36
1 file changed
+69
-1
@@ -12,6 +12,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -64,6 +65,27 @@ func k3ReplaySeed(t *testing.T, path string, mode WMode) ([][]byte, uint64) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
owned := true
|
||||
t.Cleanup(func() {
|
||||
if !owned {
|
||||
return
|
||||
}
|
||||
checkpoint := s.CheckpointLSN()
|
||||
crashRecoveryHardeningStore(t, s)
|
||||
owned = false
|
||||
if os.Getenv("SWBLOCK_TEST_REPLAY_SEED_FAILURE") == "1" {
|
||||
_, err := s.fd.WriteAt([]byte{0}, 0)
|
||||
if !errors.Is(err, os.ErrClosed) || s.v3.ownedMap != nil || checkpoint != 0 {
|
||||
t.Errorf("failed seed still owns resources or checkpointed: %v cp=%d", err, checkpoint)
|
||||
return
|
||||
}
|
||||
fmt.Println("seed failure resources released; checkpoint=0")
|
||||
}
|
||||
})
|
||||
// Stopping the flusher does not remove a production replay interleaving:
|
||||
// RecoverContext holds s.mu for writing throughout replay; a flusher must
|
||||
// acquire its read lock before taking the dirty-map snapshot. Chunk startup
|
||||
// also keeps draining held until the chunk layer attaches.
|
||||
s.DisableAutoFlushForRecoveryTest() // stop before any write; the image must need replay
|
||||
expected := make([][]byte, k3ReplayBlocks)
|
||||
for i := range expected {
|
||||
@@ -86,6 +108,9 @@ func k3ReplaySeed(t *testing.T, path string, mode WMode) ([][]byte, uint64) {
|
||||
if ack, err = s.Sync(); err != nil || ack != r.last {
|
||||
t.Fatalf("ack=%d want=%d: %v", ack, r.last, err)
|
||||
}
|
||||
if os.Getenv("SWBLOCK_TEST_REPLAY_SEED_FAILURE") == "1" {
|
||||
t.Fatal("forced seed failure after acknowledged write")
|
||||
}
|
||||
for j, b := range blocks {
|
||||
expected[int(r.lba)+j] = b
|
||||
}
|
||||
@@ -94,6 +119,7 @@ func k3ReplaySeed(t *testing.T, path string, mode WMode) ([][]byte, uint64) {
|
||||
t.Fatal("seed checkpointed: the test would not prove WAL replay")
|
||||
}
|
||||
crashRecoveryHardeningStore(t, s) // no clean stop, no extent drain
|
||||
owned = false
|
||||
return expected, ack
|
||||
}
|
||||
|
||||
@@ -247,7 +273,7 @@ func k3ReplayKill(t *testing.T, path string, cut k3ReplayCut) {
|
||||
err = cmd.Wait()
|
||||
waited = true
|
||||
var exited *exec.ExitError
|
||||
if ctx.Err() != nil || !errors.As(err, &exited) || exited.ProcessState.Success() {
|
||||
if ctx.Err() != nil || !errors.As(err, &exited) || !k3ReplayKilled(exited.ProcessState) {
|
||||
t.Fatalf("child not killed at replay witness: %v deadline=%v: %s", err, ctx.Err(), stderr.String())
|
||||
}
|
||||
}
|
||||
@@ -341,3 +367,45 @@ func TestStartWALReplayInterruptionsConverge(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Keep an unrelated child failure distinct from a proved replay interruption.
|
||||
func k3ReplayKilled(state *os.ProcessState) bool {
|
||||
if runtime.GOOS == "linux" {
|
||||
status, ok := state.Sys().(syscall.WaitStatus)
|
||||
return ok && status.Signaled() && status.Signal() == syscall.Signal(9)
|
||||
}
|
||||
// Go's Windows Process.Kill uses TerminateProcess with exit code 1.
|
||||
// Ordinary test failures/timeouts use 2; this is not a SIGKILL claim.
|
||||
return runtime.GOOS == "windows" && state.ExitCode() == 1
|
||||
}
|
||||
|
||||
func TestStartWALReplayRejectsUnrelatedExit(t *testing.T) {
|
||||
if os.Getenv("SWBLOCK_TEST_REPLAY_ORDINARY_EXIT") == "1" {
|
||||
fmt.Println("witness reached")
|
||||
os.Exit(2)
|
||||
}
|
||||
cmd := exec.Command(os.Args[0], "-test.run=^TestStartWALReplayRejectsUnrelatedExit$")
|
||||
cmd.Env = append(os.Environ(), "SWBLOCK_TEST_REPLAY_ORDINARY_EXIT=1")
|
||||
output, err := cmd.Output()
|
||||
var exited *exec.ExitError
|
||||
if !errors.As(err, &exited) || !bytes.Contains(output, []byte("witness reached")) {
|
||||
t.Fatalf("ordinary-exit control failed: %s %v", output, err)
|
||||
}
|
||||
if k3ReplayKilled(exited.ProcessState) {
|
||||
t.Fatal("ordinary exit after a witness counted as a kill")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStartWALReplaySeedFailureCleansUp(t *testing.T) {
|
||||
if os.Getenv("SWBLOCK_TEST_REPLAY_SEED_FAILURE") == "1" {
|
||||
k3ReplaySeed(t, filepath.Join(t.TempDir(), "seed"), WModeLagged)
|
||||
return
|
||||
}
|
||||
cmd := exec.Command(os.Args[0], "-test.run=^TestStartWALReplaySeedFailureCleansUp$")
|
||||
cmd.Env = append(os.Environ(), "SWBLOCK_TEST_REPLAY_SEED_FAILURE=1")
|
||||
output, err := cmd.CombinedOutput()
|
||||
var exited *exec.ExitError
|
||||
if !errors.As(err, &exited) || !bytes.Contains(output, []byte("seed failure resources released; checkpoint=0")) {
|
||||
t.Fatalf("seed failure did not release its resources: %s %v", output, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user