mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
- The lock directory is created (0700) when missing; only a directory or lock file that cannot be created or opened refuses, with the cure (install the tmpfiles.d entry, or chown the directory and its lock files to the unit's user). - The lock file is opened read-only (an existing file first, created 0644 only when missing), so a lock file another user created stays lockable; it is never unlinked, and the next owner locks the same file. - A stale-root startup end carries its cure into the final exit line: exiting status=78 reason=superseded cure="...". - Tests: a cut's remote_lsn is locally durable at its HEAD CAS, and the root's crash image at the CAS reattaches and serves; the rolled-back copy makes no claim or PUT, admits no I/O, keeps its data and durable LSN; an exact copy at HEAD attaches; a read-only lock file is taken. - Invariants: INV-WS-ONE-PROCESS-PER-HOST-001 and its M4 edge; the rollback row names its test file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
3.2 KiB
Go
94 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"os/exec"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestWorkspaceExitFirstOutcomeIsLatched(t *testing.T) {
|
|
for _, first := range []workspaceExit{{code: 75, reason: "lease_expired"}, {code: 78, reason: "superseded"}, {code: 0, reason: "revoked"}} {
|
|
e := newProcessExit(context.Background())
|
|
e.choose(first)
|
|
e.choose(workspaceExit{code: 75, reason: "assignment_timeout"})
|
|
<-e.done
|
|
if got := <-e.decision; got != first {
|
|
t.Fatalf("first=%+v changed to %+v", first, got)
|
|
}
|
|
e.choose(workspaceExit{code: 78, reason: "superseded"})
|
|
select {
|
|
case got := <-e.decision:
|
|
t.Fatalf("later outcome published: %+v", got)
|
|
default:
|
|
}
|
|
}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
cancel()
|
|
e := newProcessExit(ctx)
|
|
e.choose(workspaceExit{code: 78, reason: "superseded"})
|
|
if got := <-e.decision; got.code != 0 || got.reason != "signal" {
|
|
t.Fatalf("observed signal lost: %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestWorkspaceExitDoesNotWaitForBlockedFrontendClose(t *testing.T) {
|
|
finished := make(chan int) // a frontend Close that never returns
|
|
deadline := make(chan time.Time, 1)
|
|
deadline <- time.Time{}
|
|
if code := finishWorkspaceExit(workspaceExit{code: 75, reason: "lease_expired"}, finished, deadline); code != 75 {
|
|
t.Fatalf("code=%d", code)
|
|
}
|
|
// Cleanup errors do not overwrite an already selected retry/no-retry status.
|
|
done := make(chan int, 1)
|
|
done <- 1
|
|
if code := finishWorkspaceExit(workspaceExit{code: 78, reason: "superseded"}, done, make(chan time.Time)); code != 78 {
|
|
t.Fatalf("code=%d", code)
|
|
}
|
|
}
|
|
|
|
func TestWorkspacePlannedStopKeepsSuccess(t *testing.T) {
|
|
code := superviseProcess(context.Background(), func(e *processExit) int {
|
|
e.choose(workspaceExit{reason: "revoked"})
|
|
return 0 // the close/ACK owner completed normally
|
|
})
|
|
if code != 0 {
|
|
t.Fatalf("planned stop would restart: %d", code)
|
|
}
|
|
}
|
|
|
|
// A real child process contains the stuck resource owner. An injected event
|
|
// tests the select above; this witness also covers deferred-cleanup isolation.
|
|
func TestWorkspaceRetryProcessExitsWhenCloseBlocks(t *testing.T) {
|
|
if os.Getenv("GAP1_BLOCKED_CLOSE_CHILD") == "1" {
|
|
code := superviseProcess(context.Background(), func(e *processExit) int {
|
|
e.choose(workspaceExit{code: 75, reason: "lease_expired"})
|
|
select {} // the frontend/resource owner's Close never returns
|
|
})
|
|
os.Exit(code)
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
cmd := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestWorkspaceRetryProcessExitsWhenCloseBlocks$")
|
|
cmd.Env = append(os.Environ(), "GAP1_BLOCKED_CLOSE_CHILD=1")
|
|
out, err := cmd.CombinedOutput()
|
|
var exit *exec.ExitError
|
|
if ctx.Err() != nil || !errors.As(err, &exit) || exit.ExitCode() != 75 {
|
|
t.Fatalf("blocked close exit: %v %s", err, out)
|
|
}
|
|
}
|
|
|
|
func TestWorkspaceSignalFirstKeepsZeroAfterLaterFailure(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
cancel()
|
|
code := superviseProcess(ctx, func(e *processExit) int {
|
|
e.choose(workspaceExit{code: 78, reason: "superseded"})
|
|
return 1 // a later cleanup error cannot replace the chosen signal status
|
|
})
|
|
if code != 0 {
|
|
t.Fatalf("first signal status changed to %d", code)
|
|
}
|
|
}
|