phase171: add checkpoint crash-window gate

This commit is contained in:
pingqiu committed 2026-07-30 01:45:39 -07:00
1 parent bc4e6d289e
commit d05b582c19
3 files changed
+222

No files matched your search

@@ -0,0 +1,121 @@
//go:build linux
package storage
import (
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"
)
const (
checkpointCrashHelperEnv = "SW_BLOCK_CHECKPOINT_CRASH_HELPER"
checkpointCrashPathEnv = "SW_BLOCK_CHECKPOINT_CRASH_PATH"
)
func TestWALStoreCheckpointSIGKILLCrashWindows(t *testing.T) {
if crashWindow := os.Getenv(checkpointCrashHelperEnv); crashWindow != "" {
runCheckpointCrashHelper(crashWindow, os.Getenv(checkpointCrashPathEnv))
return
}
tests := []struct {
name string
checkpointMin uint64
checkpointMax uint64
}{
{name: "after_extent_sync", checkpointMin: 0, checkpointMax: 0},
{name: "after_checkpoint_pwrite", checkpointMin: 0, checkpointMax: 1},
{name: "after_checkpoint_sync", checkpointMin: 1, checkpointMax: 1},
{name: "after_tail_publish", checkpointMin: 1, checkpointMax: 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), "store.bin")
cmd := exec.Command(os.Args[0], "-test.run=^TestWALStoreCheckpointSIGKILLCrashWindows$")
cmd.Env = append(os.Environ(),
checkpointCrashHelperEnv+"="+tt.name,
checkpointCrashPathEnv+"="+path,
)
if output, err := cmd.CombinedOutput(); err == nil {
t.Fatalf("crash helper returned normally: %s", output)
}
reopened, err := OpenWALStore(path)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = reopened.Close() })
checkpoint := reopened.CheckpointLSN()
if checkpoint < tt.checkpointMin || checkpoint > tt.checkpointMax {
t.Fatalf("checkpoint=%d want in [%d,%d]",
checkpoint, tt.checkpointMin, tt.checkpointMax)
}
if _, err := reopened.Recover(); err != nil {
t.Fatal(err)
}
got, err := reopened.Read(3)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(got, makeBlock(4096, 0x7c)) {
t.Fatal("acknowledged bytes did not survive checkpoint crash window")
}
})
}
}
func runCheckpointCrashHelper(window, path string) {
s, err := CreateWALStore(path, 16, 4096)
if err != nil {
panic(err)
}
s.flusher.Stop()
if _, err := s.Write(3, makeBlock(4096, 0x7c)); err != nil {
panic(err)
}
if _, err := s.Sync(); err != nil {
panic(err)
}
kill := func() error {
process, err := os.FindProcess(os.Getpid())
if err != nil {
return err
}
return process.Kill()
}
switch window {
case "after_extent_sync":
s.writeSuperblockMetadata = func([]byte) error {
return kill()
}
case "after_checkpoint_pwrite":
s.writeSuperblockMetadata = func(data []byte) error {
_, err := s.fd.WriteAt(data, 0)
return err
}
s.syncSuperblockMetadata = kill
case "after_checkpoint_sync":
s.syncSuperblockMetadata = func() error {
if err := s.fd.Sync(); err != nil {
return err
}
return kill()
}
case "after_tail_publish":
default:
panic(fmt.Sprintf("unknown checkpoint crash window %q", window))
}
if err := s.flusher.flushOnce(); err != nil {
panic(err)
}
if err := kill(); err != nil {
panic(err)
}
panic("SIGKILL returned")
}
@@ -0,0 +1,41 @@
# Phase 171 D1 Checkpoint Correctness QA
Validate the exact assigned commit on Linux. Do not substitute an in-process
fd close for the SIGKILL crash windows.
## Environment
- Linux amd64
- Go 1.25 or the repository-supported newer version
- CGO enabled for `-race`
- no Kubernetes deployment is required
## Command
```bash
bash scripts/run-phase171-checkpoint-correctness-gate.sh
```
## Required Evidence
```text
focused_repetitions=20
focused_status=pass
sigkill_windows=after_extent_sync,after_checkpoint_pwrite,after_checkpoint_sync,after_tail_publish
sigkill_repetitions=20
sigkill_status=pass
race_repetitions=10
race_status=pass
storage_recovery_transport_replication_regression=pass
go_vet_storage=pass
checkpoint_metadata_durable_before_tail_reuse=true
stale_or_corrupt_dirty_record_fails_closed=true
close_lifecycle_fence=true
direct_base_ownership_restart_safe=true
phase171_checkpoint_correctness_status=ok
```
Report FAIL for any acknowledged-data loss, checkpoint/tail progress after a
failed metadata publication, dirty-state deletion after record corruption,
mutation escaping the Close fence, direct BASE bytes reverting after restart,
race finding, or regression failure.
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
RESULT_DIR="${ROOT_DIR}/results/phase171-checkpoint-correctness-gate"
SUMMARY="${RESULT_DIR}/phase171-checkpoint-correctness-summary.txt"
rm -rf "${RESULT_DIR}"
mkdir -p "${RESULT_DIR}"
: >"${SUMMARY}"
write_summary() {
printf '%s\n' "$1" | tee -a "${SUMMARY}"
}
write_summary "phase171_checkpoint_correctness_status=running"
write_summary "go_version=$(go version)"
write_summary "goos=$(go env GOOS)"
write_summary "goarch=$(go env GOARCH)"
if [[ "$(go env GOOS)" != "linux" ]]; then
write_summary "phase171_checkpoint_correctness_status=unsupported"
write_summary "unsupported_reason=linux_sigkill_required"
exit 2
fi
go test ./core/storage \
-run 'TestCheckpointPublicationCrashWindowsRemainRecoverable|TestFlusherCheckpointMetadataFailureDoesNotPublishOrRecycle|TestFlusherWALSlotMismatchFailsClosed|TestFlusherRejectsCorruptOrUnsupportedDirtyRecord|TestWALStoreClosePerformsFinalFlush|TestWALStoreCloseWaitsForInflightSync|TestWALStoreMutationAPIsRejectAfterClose|TestWALStoreCloseReturnsFinalMetadataFailure|TestWriteExtentDirect|TestRunningFlusherCannotOverwriteDirectBase|TestFlusherSnapshotCannotOverwriteLaterDirectBase' \
-count=20 \
>"${RESULT_DIR}/focused.log" 2>&1
write_summary "focused_repetitions=20"
write_summary "focused_status=pass"
go test ./core/storage \
-run '^TestWALStoreCheckpointSIGKILLCrashWindows$' \
-count=20 \
>"${RESULT_DIR}/sigkill.log" 2>&1
write_summary "sigkill_windows=after_extent_sync,after_checkpoint_pwrite,after_checkpoint_sync,after_tail_publish"
write_summary "sigkill_repetitions=20"
write_summary "sigkill_status=pass"
go test -race ./core/storage \
-run 'TestWALStoreCloseWaitsForInflightSync|TestRunningFlusherCannotOverwriteDirectBase|TestFlusher_ConcurrentWriteRaceLBAStaysFresh' \
-count=10 \
>"${RESULT_DIR}/race.log" 2>&1
write_summary "race_repetitions=10"
write_summary "race_status=pass"
go test ./core/storage ./core/recovery ./core/transport ./core/replication/... ./core/frontend/durable \
-count=1 \
>"${RESULT_DIR}/regression.log" 2>&1
write_summary "storage_recovery_transport_replication_regression=pass"
go vet ./core/storage >"${RESULT_DIR}/vet.log" 2>&1
write_summary "go_vet_storage=pass"
write_summary "checkpoint_metadata_durable_before_tail_reuse=true"
write_summary "stale_or_corrupt_dirty_record_fails_closed=true"
write_summary "close_lifecycle_fence=true"
write_summary "direct_base_ownership_restart_safe=true"
write_summary "phase171_checkpoint_correctness_status=ok"