mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
test: disk full lead review: a disk that never fills fails case 1; the seal is checked by its generation and verify; teardown kills holders, fails if anything is left; kernel cleanup at connect; per-read deadlines; no t.Fatal off the test goroutine; mount and still-full guards; %w so timeouts are seen; verdict test untagged
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d2d44a3bd3
commit
652f25b370
5 files changed
+133
-44
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// diskFullVerdict decides a defect row. A known defect that still reproduces
|
||||
// passes; an unknown one fails; a known one that no longer reproduces fails
|
||||
// too, so the list cannot go stale and hide a later regression.
|
||||
func diskFullVerdict(known map[int]bool, issue int, bad bool, msg string) (fail bool, line string) {
|
||||
switch {
|
||||
case bad && known[issue]:
|
||||
return false, fmt.Sprintf("KNOWN FINDING #%d: %s", issue, msg)
|
||||
case bad:
|
||||
return true, fmt.Sprintf("FINDING #%d: %s", issue, msg)
|
||||
case known[issue]:
|
||||
return true, fmt.Sprintf("FIXED #%d: no longer reproduces; remove it from knownDiskFullFindings so this row is strict", issue)
|
||||
}
|
||||
return false, ""
|
||||
}
|
||||
|
||||
func TestDiskFullVerdict(t *testing.T) {
|
||||
known := map[int]bool{1: true}
|
||||
for _, c := range []struct {
|
||||
issue int
|
||||
bad bool
|
||||
fail bool
|
||||
line string
|
||||
}{
|
||||
{1, true, false, "KNOWN FINDING #1"},
|
||||
{1, false, true, "FIXED #1"},
|
||||
{2, true, true, "FINDING #2"},
|
||||
{2, false, false, ""},
|
||||
} {
|
||||
fail, line := diskFullVerdict(known, c.issue, c.bad, "m")
|
||||
if fail != c.fail || !strings.HasPrefix(line, c.line) || (c.line == "" && line != "") {
|
||||
t.Errorf("issue %d bad %v: fail=%v line=%q", c.issue, c.bad, fail, line)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ package main_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -58,6 +59,9 @@ func TestProcedureLocalDiskFull(t *testing.T) {
|
||||
if root == "" || limit == "" {
|
||||
t.Fatalf("SWBLOCK_DISKFULL_ROOT=%q and SWBLOCK_DISKFULL_LIMIT=%q must be set together", root, limit)
|
||||
}
|
||||
for _, m := range []string{root, limit} {
|
||||
requireSmallDedicatedMount(t, m)
|
||||
}
|
||||
env := startHandoffEnvWith(t, 1, []string{"v2"})
|
||||
if d := os.Getenv("SWBLOCK_REPLAY_LOGS"); d != "" {
|
||||
t.Cleanup(func() { copyLogs(t, env.h.dir, d) })
|
||||
@@ -134,7 +138,7 @@ func TestProcedureLocalDiskFull(t *testing.T) {
|
||||
// behind it a guest would retry for ever: a wrong class, reported.
|
||||
switch {
|
||||
case firstErr == nil:
|
||||
t.Logf("case 1: no error in %d writes with 2 MiB free", next)
|
||||
t.Fatalf("case 1: no write failed in %d writes with 2 MiB free: the disk never filled, so this case tested nothing", next)
|
||||
case strings.Contains(firstErr.Error(), "status 0x800c"):
|
||||
diskFullFinding(t, 484, false, "case 1: the guest saw the permanent 0x800c for ENOSPC")
|
||||
case strings.Contains(firstErr.Error(), "status 0x0104"):
|
||||
@@ -175,6 +179,7 @@ func TestProcedureLocalDiskFull(t *testing.T) {
|
||||
// within the bound naming the full disk; never damage acknowledged data.
|
||||
fill = fillDisk(t, root, 0)
|
||||
holder.kill(t)
|
||||
requireDiskFull(t, root, "case 1b, at the restart")
|
||||
holder = env.start(t, "blockvolume-v1-restart-full", "s1")
|
||||
served := false
|
||||
for end := time.Now().Add(60 * time.Second); ; time.Sleep(500 * time.Millisecond) {
|
||||
@@ -219,6 +224,7 @@ func TestProcedureLocalDiskFull(t *testing.T) {
|
||||
for ch := 0; ch < cutCrashChunks; ch++ {
|
||||
for i := 0; i < cutCrashPer; i++ {
|
||||
lba := uint64(ch*ladderChunkBlocks + i)
|
||||
_ = c.io.SetDeadline(time.Now().Add(diskFullBound))
|
||||
got := c.read(t, lba, 4096)
|
||||
if w, ok := want[lba]; ok {
|
||||
if !bytes.Equal(got, w) {
|
||||
@@ -230,6 +236,7 @@ func TestProcedureLocalDiskFull(t *testing.T) {
|
||||
}
|
||||
}
|
||||
for lba, w := range want {
|
||||
_ = c.io.SetDeadline(time.Now().Add(diskFullBound))
|
||||
if !bytes.Equal(c.read(t, lba, 4096), w) {
|
||||
t.Fatalf("case 1: flush-acknowledged LBA %d lost after the disk filled", lba)
|
||||
}
|
||||
@@ -292,8 +299,13 @@ func TestProcedureLocalDiskFull(t *testing.T) {
|
||||
}
|
||||
done := make(chan cutResult, 1)
|
||||
g0 := headGen()
|
||||
go func() {
|
||||
out, errOut, rc := env.h.run(t, cut...)
|
||||
go func() { // off the test goroutine: no t.Fatal here
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 150*time.Second)
|
||||
defer cancel()
|
||||
out, errOut, rc, err := runCLI(ctx, env.h, cut...)
|
||||
if err != nil {
|
||||
rc, errOut = -1, errOut+err.Error()
|
||||
}
|
||||
done <- cutResult{out + errOut, rc}
|
||||
}()
|
||||
func() {
|
||||
@@ -321,7 +333,15 @@ func TestProcedureLocalDiskFull(t *testing.T) {
|
||||
t.Logf("case 3: cut with the host-limit dir full exited %d; guest write+flush succeeded meanwhile", r.rc)
|
||||
// The seal of a planned hand-over must not depend on the limit directory.
|
||||
out, errOut, rc := env.h.run(t, "ops", "chunk", "detach", "--plain", "--volume", "v1", "--status-addr", env.hosts["s1"].status, "--timeout", "120s")
|
||||
diskFullFinding(t, 486, rc != 0, "case 3: detach --plain with the host-limit dir full exited %d:\n%s\n%s", rc, out, errOut)
|
||||
sealed, sealErr := sealedGen(out, errOut, e)
|
||||
diskFullFinding(t, 486, rc != 0 || sealErr != nil || sealed <= g0,
|
||||
"case 3: detach --plain with the host-limit dir full exited %d, sealed gen %d (HEAD was %d, %v):\n%s\n%s", rc, sealed, g0, sealErr, out, errOut)
|
||||
if g := headGen(); rc == 0 && g != sealed {
|
||||
t.Fatalf("case 3: detach --plain reported gen %d but HEAD is at gen %d", sealed, g)
|
||||
}
|
||||
if o, eo, vrc := env.h.run(t, verify...); rc == 0 && vrc != 0 {
|
||||
t.Fatalf("case 3: the sealed HEAD does not verify (exit %d):\n%s\n%s", vrc, o, eo)
|
||||
}
|
||||
fill.free(t)
|
||||
t.Logf("slowest guest command answer: %s (bound %s)", diskFullSlowest, diskFullBound)
|
||||
if !t.Failed() {
|
||||
@@ -345,41 +365,6 @@ func diskFullFinding(t *testing.T, issue int, bad bool, format string, args ...a
|
||||
}
|
||||
}
|
||||
|
||||
// diskFullVerdict decides a defect row. A known defect that still reproduces
|
||||
// passes; an unknown one fails; a known one that no longer reproduces fails
|
||||
// too, so the list cannot go stale and hide a later regression.
|
||||
func diskFullVerdict(known map[int]bool, issue int, bad bool, msg string) (fail bool, line string) {
|
||||
switch {
|
||||
case bad && known[issue]:
|
||||
return false, fmt.Sprintf("KNOWN FINDING #%d: %s", issue, msg)
|
||||
case bad:
|
||||
return true, fmt.Sprintf("FINDING #%d: %s", issue, msg)
|
||||
case known[issue]:
|
||||
return true, fmt.Sprintf("FIXED #%d: no longer reproduces; remove it from knownDiskFullFindings so this row is strict", issue)
|
||||
}
|
||||
return false, ""
|
||||
}
|
||||
|
||||
func TestDiskFullVerdict(t *testing.T) {
|
||||
known := map[int]bool{1: true}
|
||||
for _, c := range []struct {
|
||||
issue int
|
||||
bad bool
|
||||
fail bool
|
||||
line string
|
||||
}{
|
||||
{1, true, false, "KNOWN FINDING #1"},
|
||||
{1, false, true, "FIXED #1"},
|
||||
{2, true, true, "FINDING #2"},
|
||||
{2, false, false, ""},
|
||||
} {
|
||||
fail, line := diskFullVerdict(known, c.issue, c.bad, "m")
|
||||
if fail != c.fail || !strings.HasPrefix(line, c.line) || (c.line == "" && line != "") {
|
||||
t.Errorf("issue %d bad %v: fail=%v line=%q", c.issue, c.bad, fail, line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
errDiskFullHang = errors.New("no answer within the bound")
|
||||
diskFullSlowest time.Duration
|
||||
@@ -440,6 +425,9 @@ func fillDisk(t *testing.T, dir string, keep int64) diskFiller {
|
||||
var st syscall.Statfs_t
|
||||
_ = syscall.Statfs(dir, &st)
|
||||
t.Logf("filled %s: filler %d MiB, %d KiB free", dir, n>>20, int64(st.Bavail)*int64(st.Bsize)>>10)
|
||||
if free := int64(st.Bavail) * int64(st.Bsize); free > keep+(1<<20) {
|
||||
t.Fatalf("filled %s but %d bytes are still free (want about %d)", dir, free, keep)
|
||||
}
|
||||
return diskFiller{path: path}
|
||||
}
|
||||
|
||||
@@ -449,3 +437,35 @@ func (d diskFiller) free(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// requireDiskFull fails unless dir's file system has (almost) no free space.
|
||||
func requireDiskFull(t *testing.T, dir, what string) {
|
||||
t.Helper()
|
||||
var st syscall.Statfs_t
|
||||
if err := syscall.Statfs(dir, &st); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if free := int64(st.Bavail) * int64(st.Bsize); free > 64<<10 {
|
||||
t.Fatalf("%s: the disk is not full (%d bytes free)", what, free)
|
||||
}
|
||||
}
|
||||
|
||||
// requireSmallDedicatedMount guards the fill: dir must be the root of its own
|
||||
// small file system, so the filler can only fill the harness's mount.
|
||||
func requireSmallDedicatedMount(t *testing.T, dir string) {
|
||||
t.Helper()
|
||||
var fs syscall.Statfs_t
|
||||
var self, parent syscall.Stat_t
|
||||
if err := syscall.Statfs(dir, &fs); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := syscall.Stat(dir, &self); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := syscall.Stat(filepath.Dir(dir), &parent); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if size := int64(fs.Blocks) * int64(fs.Bsize); self.Dev == parent.Dev || size > 2<<30 {
|
||||
t.Fatalf("%s must be a dedicated mount of at most 2 GiB (own device %v, size %d)", dir, self.Dev != parent.Dev, size)
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,16 @@ func TestProcedureLocalDiskFullKernelInitiator(t *testing.T) {
|
||||
if out := sh("echo " + connect + " > /dev/nvme-fabrics && echo connected"); !strings.Contains(out, "connected") {
|
||||
t.Fatalf("kernel connect: %s", out)
|
||||
}
|
||||
// Registered at once, by NQN: a later failure must not leave the
|
||||
// controller connected.
|
||||
t.Cleanup(func() {
|
||||
ctrls, _ := filepath.Glob("/sys/class/nvme/nvme*")
|
||||
for _, c := range ctrls {
|
||||
if b, _ := os.ReadFile(filepath.Join(c, "subsysnqn")); strings.TrimSpace(string(b)) == plannedHandoffNQN {
|
||||
_ = os.WriteFile(filepath.Join(c, "delete_controller"), []byte("1"), 0o200)
|
||||
}
|
||||
}
|
||||
})
|
||||
var ctrl, dev string
|
||||
for end := time.Now().Add(30 * time.Second); dev == "" || ctrl == ""; time.Sleep(500 * time.Millisecond) {
|
||||
ctrls, _ := filepath.Glob("/sys/class/nvme/nvme*")
|
||||
@@ -90,7 +100,6 @@ func TestProcedureLocalDiskFullKernelInitiator(t *testing.T) {
|
||||
t.Fatalf("no namespace device for %s (controller %q, device %q)", plannedHandoffNQN, ctrl, dev)
|
||||
}
|
||||
}
|
||||
t.Cleanup(func() { _ = os.WriteFile(filepath.Join(ctrl, "delete_controller"), []byte("1"), 0o200) })
|
||||
t.Logf("KERNEL: %s connected as %s (%s); multipath=%s io_timeout=%ss max_retries=%s", plannedHandoffNQN, dev, ctrl,
|
||||
sh("cat /sys/module/nvme_core/parameters/multipath"), sh("cat /sys/module/nvme_core/parameters/io_timeout"),
|
||||
sh("cat /sys/module/nvme_core/parameters/max_retries"))
|
||||
|
||||
@@ -629,7 +629,10 @@ func (c *nvmeInitiator) tryWrite(lba uint64, data []byte) error {
|
||||
}
|
||||
ch, err := c.r.Dequeue()
|
||||
if err != nil || ch.Type != 0x9 {
|
||||
return fmt.Errorf("nvme Write: want R2T, got type %v err %v", ch, err)
|
||||
if err != nil {
|
||||
return fmt.Errorf("nvme Write: want R2T: %w", err)
|
||||
}
|
||||
return fmt.Errorf("nvme Write: want R2T, got type %v", ch)
|
||||
}
|
||||
var r2t nvme.R2THeader
|
||||
if err := c.r.Receive(&r2t); err != nil {
|
||||
@@ -653,7 +656,11 @@ func (c *nvmeInitiator) tryFlush() error {
|
||||
func (c *nvmeInitiator) tryStatus(op string) error {
|
||||
ch, err := c.r.Dequeue()
|
||||
if err != nil || ch.Type != 0x5 {
|
||||
return fmt.Errorf("nvme %s response: type %v err %v", op, ch, err)
|
||||
if err != nil {
|
||||
// %w: a deadline on the queue stays a net timeout for errors.As.
|
||||
return fmt.Errorf("nvme %s response: %w", op, err)
|
||||
}
|
||||
return fmt.Errorf("nvme %s response: type %v", op, ch)
|
||||
}
|
||||
var resp nvme.CapsuleResponse
|
||||
if err := c.r.Receive(&resp); err != nil {
|
||||
|
||||
+13
-2
@@ -17,11 +17,22 @@ for c in losetup mkfs.ext4 mount umount mountpoint truncate; do command -v "$c"
|
||||
mkdir "$work/root" "$work/limit" "$work/logs"
|
||||
loops=()
|
||||
cleanup() {
|
||||
local rc=$? failed=0
|
||||
set +e
|
||||
for m in "$work/root" "$work/limit"; do mountpoint -q "$m" && umount "$m"; done
|
||||
for l in "${loops[@]}"; do losetup -d "$l"; done
|
||||
for m in "$work/root" "$work/limit"; do
|
||||
mountpoint -q "$m" || continue
|
||||
# A blockvolume that outlived a killed test would hold the mount busy.
|
||||
command -v fuser >/dev/null && fuser -km "$m" >/dev/null 2>&1
|
||||
umount "$m" 2>/dev/null || { sleep 1; umount "$m"; } || { umount -l "$m"; failed=1; }
|
||||
done
|
||||
for l in "${loops[@]}"; do losetup -d "$l" || failed=1; done
|
||||
# Only the sparse images this script created under WORKDIR.
|
||||
rm -f -- "$work/root.img" "$work/limit.img"
|
||||
if [ "$failed" = 1 ] || losetup -a | grep -qF "$work/"; then
|
||||
echo "diskfull.sh: teardown incomplete (busy mount or loop device left)" >&2
|
||||
exit 3
|
||||
fi
|
||||
exit $rc
|
||||
}
|
||||
trap cleanup EXIT
|
||||
for fs in root:512M limit:8M; do
|
||||
|
||||
Reference in new issue
Block a user