mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
Preserve map validation cleanup failures
This commit is contained in:
1 parent
6d61690df0
commit
ee03f83c53
1 file changed
+61
@@ -0,0 +1,61 @@
|
||||
//go:build linux
|
||||
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestChunkMapValidationKeepsTheCloseFailure(t *testing.T) {
|
||||
for _, failClose := range []bool{false, true} {
|
||||
t.Run(strconv.FormatBool(failClose), func(t *testing.T) {
|
||||
s, path := newMappedCheckpointStoreV3(t)
|
||||
d := s.v3.pub.current()
|
||||
crashStore(t, s)
|
||||
other := d
|
||||
other.UUID[0] ^= 1 // definite validation refusal, independent of I/O
|
||||
closed := false
|
||||
ctx := WithRecoveryProgress(context.Background(), func(phase RecoveryPhase, _ uint64) {
|
||||
if phase != RecoveryOpenMap || !failClose || closed {
|
||||
return
|
||||
}
|
||||
// Close only this test's map descriptor underneath its os.File.
|
||||
// The later os.File.Close must report EBADF, exercising the real
|
||||
// opener's cleanup instead of mocking error composition.
|
||||
fds, err := os.ReadDir("/proc/self/fd")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, fd := range fds {
|
||||
target, err := os.Readlink("/proc/self/fd/" + fd.Name())
|
||||
if err != nil || target != path+".chunkmap" {
|
||||
continue
|
||||
}
|
||||
n, err := strconv.Atoi(fd.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := syscall.Close(n); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
closed = true
|
||||
return
|
||||
}
|
||||
t.Fatal("owned validation handle not found")
|
||||
})
|
||||
m, _, err := openDescriptorMapV3Progress(path+".chunkmap", d, &other, newRecoveryReporter(ctx, RecoveryOpenMap))
|
||||
if m != nil {
|
||||
m.Close()
|
||||
t.Fatal("invalid fallback identity returned an open map")
|
||||
}
|
||||
if !errors.Is(err, ErrMapInvalid) || errors.Is(err, syscall.EBADF) != failClose || closed != failClose {
|
||||
t.Fatalf("close fault=%v injected=%v: error=%v", failClose, closed, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user