mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
storage: a failed fsync is sticky for the open walstore
The WAL and the extent share one file, and on Linux a failed fsync may already have dropped dirty pages of that file, so a later successful fsync proves nothing about them (the fsyncgate pattern). The first failure of any fsync on the file (WAL batch, flusher extent, checkpoint, recovered bounds, direct frontier, frontier seed) now latches ErrFsyncFailed, wrapped in a SubstrateIO RecoveryFailure (io_error). Until the store is reopened: Sync refuses without another fsync, writes, batch writes, ApplyEntry and WriteExtentDirect refuse, the flusher advances no checkpoint, Recover and the frontier seed refuse, and Close writes no final superblock. A reopen recovers from what is on disk. Tests that asserted a same-instance retry after an injected fsync failure now assert the sticky refusal and a reopen: the generation sync tests, the checkpoint and direct-frontier metadata tests, the frontier seed test, the recovered-bounds test and the two restore seed tests (whose real EINVAL fsync now requires a reopen before the restore succeeds). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
721b496d7a
commit
98d7fd8181
10 files changed
+214
-71
No files matched your search
@@ -139,16 +139,26 @@ func TestRestoreFailedSeedSyncRetryCaptureAndReopen(t *testing.T) {
|
||||
if got := ws.NextLSN(); got != 1 {
|
||||
t.Errorf("failed seed published allocator watermark %d, want 1", got)
|
||||
}
|
||||
if _, err := p.RecoverVolume(ctx, "v1"); err != nil {
|
||||
t.Fatal("same-handle retry:", err)
|
||||
// The failed fsync is sticky for the open store (storage.ErrFsyncFailed,
|
||||
// io_error): no same-handle retry; a reopen restores from HEAD.
|
||||
if _, err := p.RecoverVolume(ctx, "v1"); !errors.Is(err, storage.ErrFsyncFailed) {
|
||||
t.Fatalf("same-handle retry after a failed fsync: %v; want ErrFsyncFailed", err)
|
||||
}
|
||||
if r, _, h := ws.Boundaries(); r != 7 || h != 7 {
|
||||
t.Errorf("retry did not durably seed HEAD: R=%d H=%d", r, h)
|
||||
if r, _, h := ws.Boundaries(); r != 0 || h != 0 {
|
||||
t.Errorf("refused retry published R=%d H=%d", r, h)
|
||||
}
|
||||
if cut, err := p.CaptureVolume(ctx, "v1"); err != nil || cut != 7 {
|
||||
t.Errorf("retry cut=%d err=%v, want 7", cut, err)
|
||||
_ = p.Close()
|
||||
p1 := makeProvider(remote)
|
||||
if _, err := p1.EnsureStorage("v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.Close(); err != nil {
|
||||
if _, err := p1.RecoverVolume(ctx, "v1"); err != nil {
|
||||
t.Fatal("restore after a reopen:", err)
|
||||
}
|
||||
if cut, err := p1.CaptureVolume(ctx, "v1"); err != nil || cut != 7 {
|
||||
t.Errorf("cut after a reopen=%d err=%v, want 7", cut, err)
|
||||
}
|
||||
if err := p1.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p2 := makeProvider(remote)
|
||||
@@ -219,10 +229,28 @@ func TestRestoreFailedSeedNeverTakesOwnership(t *testing.T) {
|
||||
if _, err := p.Backend("v1").Read(ctx, 0, make([]byte, 4096)); !errors.Is(err, frontend.ErrNotReady) {
|
||||
t.Fatal("failed seed admitted I/O", err)
|
||||
}
|
||||
if _, err := p.RecoverVolume(ctx, "v1"); err != nil {
|
||||
t.Fatal("same-store retry", err)
|
||||
// The failed fsync is sticky (storage.ErrFsyncFailed): the same-store
|
||||
// retry refuses and still takes no ownership; a reopen takes it once.
|
||||
if _, err := p.RecoverVolume(ctx, "v1"); !errors.Is(err, storage.ErrFsyncFailed) {
|
||||
t.Fatalf("same-store retry after a failed fsync: %v; want ErrFsyncFailed", err)
|
||||
}
|
||||
if calls != 0 {
|
||||
t.Fatal("a refused retry took ownership", calls)
|
||||
}
|
||||
_ = p.Close()
|
||||
p2, err := durable.NewDurableProvider(durable.ProviderConfig{Impl: durable.ImplWALStoreChunk, StorageRoot: root, NumBlocks: 64, BlockSize: 4096, ChunkBlocks: 4, WALRecoveryTestDisableFlusher: true,
|
||||
ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return watched, nil }}, v1View())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer p2.Close()
|
||||
if _, err = p2.EnsureStorage("v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p2.RecoverVolume(ctx, "v1"); err != nil {
|
||||
t.Fatal("restore after a reopen", err)
|
||||
}
|
||||
if calls != 1 {
|
||||
t.Fatal("successful retry must take ownership exactly once", calls)
|
||||
t.Fatal("restore after a reopen must take ownership exactly once", calls)
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,9 @@ func (s *WALStore) SeedChunkFrontier(lsn uint64) error {
|
||||
if s.closed || s.chunk.Load() != nil {
|
||||
return errors.New("storage: seed frontier requires an open, unattached store")
|
||||
}
|
||||
if err := s.stickyFsyncFault(); err != nil {
|
||||
return err
|
||||
}
|
||||
if lsn == ^uint64(0) || lsn < s.checkpointLSN || s.walHead > s.checkpointLSN || s.nextLSN > lsn+1 {
|
||||
return errors.New("storage: seed frontier cannot replace local writes or wrap LSN")
|
||||
}
|
||||
@@ -41,7 +44,7 @@ func (s *WALStore) SeedChunkFrontier(lsn uint64) error {
|
||||
if _, err := next.writeTo(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.syncDirectFrontierMetadata(buf.bytes()); err != nil {
|
||||
if err := s.noteFsyncFailure(s.syncDirectFrontierMetadata(buf.bytes())); err != nil {
|
||||
return fmt.Errorf("storage: seed metadata sync: %w", err)
|
||||
}
|
||||
*s.sb = next
|
||||
|
||||
@@ -19,19 +19,16 @@ func TestSeedChunkFrontierMetadataFailureRetry(t *testing.T) {
|
||||
if r, _, h := s.Boundaries(); r != 0 || h != 0 {
|
||||
t.Fatal("failed seed published frontier", r, h)
|
||||
}
|
||||
if _, err := s.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The failed fsync is sticky for this open store (ErrFsyncFailed):
|
||||
// neither a same-store Recover nor a seed retry may run on it.
|
||||
s.syncDirectFrontierMetadata = syncMetadata
|
||||
if err := s.SeedChunkFrontier(7); err != nil {
|
||||
t.Fatal(err)
|
||||
if _, err := s.Recover(); !errors.Is(err, ErrFsyncFailed) {
|
||||
t.Fatalf("same-store Recover after a failed fsync: %v; want ErrFsyncFailed", err)
|
||||
}
|
||||
if s.NextLSN() != 8 {
|
||||
t.Fatal("retry not seeded")
|
||||
}
|
||||
if err := s.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
if err := s.SeedChunkFrontier(7); !errors.Is(err, ErrFsyncFailed) {
|
||||
t.Fatalf("same-store seed retry after a failed fsync: %v; want ErrFsyncFailed", err)
|
||||
}
|
||||
_ = s.Close()
|
||||
reopened, err := OpenWALStore(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -40,7 +37,10 @@ func TestSeedChunkFrontierMetadataFailureRetry(t *testing.T) {
|
||||
if _, err := reopened.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := reopened.SeedChunkFrontier(7); err != nil {
|
||||
t.Fatalf("seed after a reopen: %v", err)
|
||||
}
|
||||
if reopened.NextLSN() != 8 {
|
||||
t.Fatal("durable seed missing after reopen")
|
||||
t.Fatal("seed after a reopen not applied")
|
||||
}
|
||||
}
|
||||
@@ -155,6 +155,9 @@ func (f *flusher) flushOnceAllowClosed() error {
|
||||
func (f *flusher) flushOnceInternal(allowClosed bool) (err error) {
|
||||
cycleStart := time.Now()
|
||||
store := f.store
|
||||
if err := store.stickyFsyncFault(); err != nil {
|
||||
return err // no checkpoint advance after a failed fsync
|
||||
}
|
||||
store.mu.RLock()
|
||||
if store.closed && !allowClosed {
|
||||
store.mu.RUnlock()
|
||||
@@ -216,7 +219,7 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) {
|
||||
// Step 2: one fsync covers all extent writes in this batch
|
||||
// (and any other in-flight WAL writes since they share a file).
|
||||
syncStart := time.Now()
|
||||
syncErr := store.syncExtentFile()
|
||||
syncErr := store.noteFsyncFailure(store.syncExtentFile())
|
||||
f.instr.recordExtentSync(time.Since(syncStart), syncErr)
|
||||
if syncErr != nil {
|
||||
return fmt.Errorf("flusher: fsync after extent writes: %w", syncErr)
|
||||
|
||||
@@ -184,7 +184,12 @@ func NewWALRecycledFailure(cause error, detail string) *RecoveryFailure {
|
||||
|
||||
// NewSubstrateIOFailure wraps a substrate IO error in the typed
|
||||
// envelope. Use when ScanLBAs failed mid-scan with a read/decode error.
|
||||
// ErrFsyncFailed: declared for the RED tests; nothing returns it yet.
|
||||
// ErrFsyncFailed is the sticky fault of an open store after any fsync of
|
||||
// its file failed. The kernel may already have dropped the dirty pages, so a
|
||||
// later successful fsync proves nothing about them: the store acknowledges
|
||||
// no further Sync, accepts no write and advances no checkpoint until it is
|
||||
// reopened (and recovered from what is on disk). It comes wrapped in a
|
||||
// SubstrateIO RecoveryFailure, so hosts report it as io_error.
|
||||
var ErrFsyncFailed = errors.New("storage: fsync failed earlier on this open store; reopen to recover")
|
||||
|
||||
func NewSubstrateIOFailure(cause error, detail string) *RecoveryFailure {
|
||||
|
||||
@@ -141,6 +141,8 @@ type WALStore struct {
|
||||
// syncExtentFile is the flusher's fsync after extent writes (the same
|
||||
// file as the WAL); a seam for fault injection.
|
||||
syncExtentFile func() error
|
||||
// fsyncFault latches the first fsync failure of the file (ErrFsyncFailed).
|
||||
fsyncFault atomic.Pointer[RecoveryFailure]
|
||||
// Generations cover completed append attempts and recovery publication.
|
||||
walMutation atomic.Uint64
|
||||
durableMutation atomic.Uint64
|
||||
@@ -454,7 +456,7 @@ func (s *WALStore) persistCheckpointReleasing(highestLSN, entryPhys, entryLen ui
|
||||
return fmt.Errorf("storage: pwrite superblock: %w", err)
|
||||
}
|
||||
checkpointSyncStart := time.Now()
|
||||
err = s.syncSuperblockMetadata()
|
||||
err = s.noteFsyncFailure(s.syncSuperblockMetadata())
|
||||
if s.flusher != nil {
|
||||
s.flusher.instr.recordCheckpointSync(time.Since(checkpointSyncStart), err)
|
||||
}
|
||||
@@ -541,6 +543,10 @@ func (s *WALStore) Recover() (uint64, error) {
|
||||
if s.closed {
|
||||
return 0, errors.New("storage: Recover after Close")
|
||||
}
|
||||
if err := s.stickyFsyncFault(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Recovery can republish a prefix left by a failed append (including on
|
||||
// this same open file). Invalidate before releasing publication, even on
|
||||
// a failed scan; the next successful sync establishes a reusable new cut.
|
||||
@@ -574,7 +580,7 @@ func (s *WALStore) Recover() (uint64, error) {
|
||||
s.dm.clear()
|
||||
return 0, fmt.Errorf("storage: pwrite recovered superblock: %w", err)
|
||||
}
|
||||
if err := s.syncSuperblockMetadata(); err != nil {
|
||||
if err := s.noteFsyncFailure(s.syncSuperblockMetadata()); err != nil {
|
||||
s.dm.clear()
|
||||
return 0, fmt.Errorf("storage: fsync recovered superblock: %w", err)
|
||||
}
|
||||
@@ -615,6 +621,9 @@ func (s *WALStore) Write(lba uint32, data []byte) (uint64, error) {
|
||||
defer s.captureMu.RUnlock()
|
||||
s.lifecycleMu.RLock()
|
||||
defer s.lifecycleMu.RUnlock()
|
||||
if err := s.stickyFsyncFault(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if uint64(lba) >= uint64(s.sb.VolumeSize/uint64(s.sb.BlockSize)) {
|
||||
return 0, fmt.Errorf("storage: LBA %d out of range", lba)
|
||||
}
|
||||
@@ -679,6 +688,9 @@ func (s *WALStore) WriteBatch(startLBA uint32, blocks [][]byte) ([]uint64, error
|
||||
defer s.captureMu.RUnlock()
|
||||
s.lifecycleMu.RLock()
|
||||
defer s.lifecycleMu.RUnlock()
|
||||
if err := s.stickyFsyncFault(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(blocks) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -942,6 +954,10 @@ func (s *WALStore) Sync() (uint64, error) {
|
||||
s.mu.RUnlock()
|
||||
return 0, errors.New("storage: Sync after Close")
|
||||
}
|
||||
if err := s.stickyFsyncFault(); err != nil {
|
||||
s.mu.RUnlock()
|
||||
return 0, err
|
||||
}
|
||||
targetHead := s.walHead
|
||||
targetDirectFrontier := s.pendingDirectFrontierLSN
|
||||
s.mu.RUnlock()
|
||||
@@ -982,7 +998,7 @@ func (s *WALStore) Sync() (uint64, error) {
|
||||
s.mu.Unlock()
|
||||
return 0, fmt.Errorf("storage: encode superblock: %w", err)
|
||||
}
|
||||
if err := s.syncDirectFrontierMetadata(buf.bytes()); err != nil {
|
||||
if err := s.noteFsyncFailure(s.syncDirectFrontierMetadata(buf.bytes())); err != nil {
|
||||
s.mu.Unlock()
|
||||
return 0, err
|
||||
}
|
||||
@@ -1120,6 +1136,9 @@ func (s *WALStore) WriteExtentDirect(lba uint32, data []byte) error {
|
||||
defer s.captureMu.RUnlock()
|
||||
s.lifecycleMu.RLock()
|
||||
defer s.lifecycleMu.RUnlock()
|
||||
if err := s.stickyFsyncFault(); err != nil {
|
||||
return err
|
||||
}
|
||||
maxLBA := uint32(s.sb.VolumeSize / uint64(s.sb.BlockSize))
|
||||
if lba >= maxLBA {
|
||||
return fmt.Errorf("storage: WriteExtentDirect LBA %d out of range", lba)
|
||||
@@ -1174,6 +1193,9 @@ func (s *WALStore) ApplyEntry(lba uint32, data []byte, lsn uint64) error {
|
||||
defer s.captureMu.RUnlock()
|
||||
s.lifecycleMu.RLock()
|
||||
defer s.lifecycleMu.RUnlock()
|
||||
if err := s.stickyFsyncFault(); err != nil {
|
||||
return err
|
||||
}
|
||||
maxLBA := uint32(s.sb.VolumeSize / uint64(s.sb.BlockSize))
|
||||
if lba >= maxLBA {
|
||||
return fmt.Errorf("storage: apply LBA %d out of range", lba)
|
||||
@@ -1337,7 +1359,10 @@ func (s *WALStore) Close() error {
|
||||
if flushErr != nil {
|
||||
closeErrors = append(closeErrors, fmt.Errorf("storage: final flush: %w", flushErr))
|
||||
}
|
||||
if s.fd != nil {
|
||||
if fault := s.stickyFsyncFault(); fault != nil {
|
||||
closeErrors = append(closeErrors, fault)
|
||||
}
|
||||
if s.fd != nil && s.stickyFsyncFault() == nil {
|
||||
// Persist current head/tail back into the superblock so a
|
||||
// subsequent OpenWALStore can find the WAL bounds without
|
||||
// relying solely on the defensive scan.
|
||||
@@ -1353,6 +1378,8 @@ func (s *WALStore) Close() error {
|
||||
closeErrors = append(closeErrors, fmt.Errorf("storage: fsync final superblock: %w", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
if s.fd != nil {
|
||||
closeErr := s.fd.Close()
|
||||
s.fd = nil
|
||||
if closeErr != nil {
|
||||
@@ -1388,8 +1415,29 @@ func (s *WALStore) syncWALBatch() error {
|
||||
start := time.Now()
|
||||
defer func() { s.fileSyncLatency.Observe(time.Since(start)) }()
|
||||
if err := s.syncWALFile(); err != nil {
|
||||
return err
|
||||
return s.noteFsyncFailure(err)
|
||||
}
|
||||
s.durableMutation.Store(cut)
|
||||
return nil
|
||||
}
|
||||
|
||||
// noteFsyncFailure latches the first fsync failure of the store's file as
|
||||
// the sticky ErrFsyncFailed fault and returns err unchanged (nil stays nil).
|
||||
func (s *WALStore) noteFsyncFailure(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
s.fsyncFault.CompareAndSwap(nil, NewSubstrateIOFailure(
|
||||
fmt.Errorf("%w: %w", ErrFsyncFailed, err),
|
||||
"fsync failed; the open store refuses further Syncs, writes and checkpoints",
|
||||
))
|
||||
return err
|
||||
}
|
||||
|
||||
// stickyFsyncFault reports the latched fsync fault, if any.
|
||||
func (s *WALStore) stickyFsyncFault() error {
|
||||
if f := s.fsyncFault.Load(); f != nil {
|
||||
return f
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -73,6 +73,17 @@ func TestFlusherCheckpointMetadataFailureDoesNotPublishOrRecycle(t *testing.T) {
|
||||
|
||||
s.writeSuperblockMetadata = savedWrite
|
||||
s.syncSuperblockMetadata = savedSync
|
||||
if tt.name == "sync" {
|
||||
// A failed fsync is sticky (ErrFsyncFailed): no checkpoint
|
||||
// retry on this open store.
|
||||
if err := s.flusher.flushOnce(); !errors.Is(err, ErrFsyncFailed) {
|
||||
t.Fatalf("retry flush after a failed fsync: %v; want ErrFsyncFailed", err)
|
||||
}
|
||||
if got := s.CheckpointLSN(); got != 0 {
|
||||
t.Fatalf("checkpoint after a refused retry=%d want 0", got)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err := s.flusher.flushOnce(); err != nil {
|
||||
t.Fatalf("retry flush: %v", err)
|
||||
}
|
||||
|
||||
@@ -427,21 +427,43 @@ func TestWALStoreRecoverBoundsPersistFailureRefusesAppendsUntilRetry(t *testing.
|
||||
}
|
||||
|
||||
r.writeSuperblockMetadata, r.syncSuperblockMetadata = realWrite, realSync
|
||||
if _, err := r.Recover(); err != nil {
|
||||
t.Fatalf("same-instance Recover retry: %v", err)
|
||||
live := r
|
||||
if seam == "sync" {
|
||||
// A failed fsync is sticky (ErrFsyncFailed): no same-instance
|
||||
// retry; the bounds are persisted by the recovery of a reopen.
|
||||
if _, err := r.Recover(); !errors.Is(err, ErrFsyncFailed) {
|
||||
t.Fatalf("same-instance Recover after a failed fsync: %v; want ErrFsyncFailed", err)
|
||||
}
|
||||
crashRecoveryHardeningStore(t, r)
|
||||
rClosed = true
|
||||
r2, err := OpenWALStore(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r2.DisableAutoFlushForRecoveryTest()
|
||||
t.Cleanup(func() {
|
||||
if live == r2 && !rClosed {
|
||||
_ = r2.Close()
|
||||
}
|
||||
})
|
||||
rClosed = false
|
||||
live = r2
|
||||
}
|
||||
if _, err := live.Recover(); err != nil {
|
||||
t.Fatalf("Recover retry: %v", err)
|
||||
}
|
||||
disk := diskSuperblockForTest(t, path)
|
||||
if tail, h := r.wal.logicalTailValue(), r.wal.logicalHeadValue(); disk.WALTail != tail || disk.WALHead != h {
|
||||
if tail, h := live.wal.logicalTailValue(), live.wal.logicalHeadValue(); disk.WALTail != tail || disk.WALHead != h {
|
||||
t.Fatalf("after the retry: persisted tail=%d head=%d, writer tail=%d head=%d", disk.WALTail, disk.WALHead, tail, h)
|
||||
}
|
||||
r.admissionTimeout = 30 * time.Second
|
||||
if _, err := r.Write(5, makeBlock(blockSize, 0x55)); err != nil {
|
||||
live.admissionTimeout = 30 * time.Second
|
||||
if _, err := live.Write(5, makeBlock(blockSize, 0x55)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := r.Sync(); err != nil {
|
||||
if _, err := live.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
crashRecoveryHardeningStore(t, r)
|
||||
crashRecoveryHardeningStore(t, live)
|
||||
rClosed = true
|
||||
|
||||
q, err := OpenWALStore(path)
|
||||
|
||||
@@ -136,17 +136,25 @@ func TestWALGenerationSyncFailureAndShutdown(t *testing.T) {
|
||||
if r, _, _ := s.Boundaries(); r != 0 {
|
||||
t.Fatalf("failed sync published R=%d", r)
|
||||
}
|
||||
if n, err := s.Sync(); err != nil || n != 1 {
|
||||
t.Fatalf("retry frontier=%d err=%v", n, err)
|
||||
// A failed fsync is sticky (ErrFsyncFailed): the retry is refused
|
||||
// without another physical fsync, and nothing is published.
|
||||
if n, err := s.Sync(); !errors.Is(err, ErrFsyncFailed) || n != 0 {
|
||||
t.Fatalf("retry after a failed fsync frontier=%d err=%v; want ErrFsyncFailed", n, err)
|
||||
}
|
||||
if attempts.Load() != 2 {
|
||||
t.Fatalf("error was cached: attempts=%d", attempts.Load())
|
||||
if attempts.Load() != 1 {
|
||||
t.Fatalf("a retry after a failed fsync fsynced again: attempts=%d", attempts.Load())
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
if r, _, _ := s.Boundaries(); r != 0 {
|
||||
t.Fatalf("refused retry published R=%d", r)
|
||||
}
|
||||
_ = s.Close()
|
||||
|
||||
s = newGenerationStore(t)
|
||||
if _, err := s.Write(0, makeBlock(4096, 0x61)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if attempts.Load() != 2 {
|
||||
t.Fatal("durable duplicate resynced")
|
||||
if n, err := s.Sync(); err != nil || n != 1 {
|
||||
t.Fatalf("sync frontier=%d err=%v", n, err)
|
||||
}
|
||||
s.committer.Stop()
|
||||
if _, err := s.Sync(); !errors.Is(err, ErrGroupCommitShutdown) {
|
||||
@@ -273,15 +281,14 @@ func TestWALGenerationPartialAppendRecoverySync(t *testing.T) {
|
||||
if !errors.Is(err, fault) || attempts != 1 {
|
||||
t.Fatalf("next Sync skipped required physical I/O/error: err=%v attempts=%d", err, attempts)
|
||||
}
|
||||
// The failed fsync is sticky (ErrFsyncFailed): no retry ack and
|
||||
// no further physical fsync on this open store.
|
||||
before := s.WALSyncCount()
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
if _, err := s.Sync(); !errors.Is(err, ErrFsyncFailed) {
|
||||
t.Fatalf("retry after a failed fsync: %v; want ErrFsyncFailed", err)
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n := s.WALSyncCount() - before; n != 1 {
|
||||
t.Fatalf("retry+duplicate physical syncs=%d want1", n)
|
||||
if n := s.WALSyncCount() - before; n != 0 {
|
||||
t.Fatalf("a refused retry fsynced %d times", n)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -309,13 +316,28 @@ func TestWALGenerationSameOpenRecoverInvalidatesCoverage(t *testing.T) {
|
||||
if !errors.Is(err, fault) || attempts != 1 {
|
||||
t.Fatalf("Recover reused old sync coverage: err=%v attempts=%d", err, attempts)
|
||||
}
|
||||
before := s.WALSyncCount()
|
||||
for i := 0; i < 2; i++ {
|
||||
if _, err := s.Sync(); err != nil {
|
||||
// The failed fsync is sticky (ErrFsyncFailed); dedup after a Recover is
|
||||
// checked on a store whose syncs succeed.
|
||||
if _, err := s.Sync(); !errors.Is(err, ErrFsyncFailed) {
|
||||
t.Fatalf("retry after a failed fsync: %v; want ErrFsyncFailed", err)
|
||||
}
|
||||
s2 := newGenerationStore(t)
|
||||
if _, err := s2.Write(0, makeBlock(4096, 0x92)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s2.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s2.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before := s2.WALSyncCount()
|
||||
for i := 0; i < 3; i++ {
|
||||
if _, err := s2.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if n := s.WALSyncCount() - before; n != 1 {
|
||||
if n := s2.WALSyncCount() - before; n != 1 {
|
||||
t.Fatalf("Recover permanently disabled dedup: syncs=%d want1", n)
|
||||
}
|
||||
}
|
||||
@@ -138,31 +138,32 @@ func TestWALStore_DirectFrontierMetadataFailureRetainsRetryState(t *testing.T) {
|
||||
t.Fatalf("durable frontier=%d want 0 after failed metadata sync", R)
|
||||
}
|
||||
|
||||
// The failed fsync is sticky (ErrFsyncFailed): the retry is refused, the
|
||||
// in-memory frontier is never published, and a reopen starts from what
|
||||
// is on disk.
|
||||
s.syncDirectFrontierMetadata = savedSync
|
||||
frontier, err := s.Sync()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
if _, err := s.Sync(); !errors.Is(err, ErrFsyncFailed) {
|
||||
t.Fatalf("retry after a failed metadata fsync: %v; want ErrFsyncFailed", err)
|
||||
}
|
||||
if frontier != 10 || s.checkpointLSN != 10 || s.pendingDirectFrontierLSN != 0 {
|
||||
t.Fatalf("retry frontier=%d checkpoint=%d pending=%d want 10/10/0",
|
||||
frontier, s.checkpointLSN, s.pendingDirectFrontierLSN)
|
||||
}
|
||||
if got, want := s.sb.WALHead, s.wal.logicalHeadValue(); got != want {
|
||||
t.Fatalf("superblock WALHead byte cursor=%d want %d", got, want)
|
||||
}
|
||||
if s.sb.WALHead == frontier {
|
||||
t.Fatalf("superblock WALHead=%d incorrectly stores LSN frontier", s.sb.WALHead)
|
||||
}
|
||||
if err := s.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
if s.checkpointLSN != 0 {
|
||||
t.Fatalf("refused retry published checkpoint %d", s.checkpointLSN)
|
||||
}
|
||||
_ = s.Close()
|
||||
reopened, err := OpenWALStore(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = reopened.Close() })
|
||||
if got := reopened.CheckpointLSN(); got != 10 {
|
||||
t.Fatalf("reopened checkpointLSN=%d want 10", got)
|
||||
if got := reopened.CheckpointLSN(); got != 0 {
|
||||
t.Fatalf("reopened checkpointLSN=%d want 0 (the frontier was never durable)", got)
|
||||
}
|
||||
reopened.AdvanceFrontier(10)
|
||||
frontier, err := reopened.Sync()
|
||||
if err != nil || frontier != 10 || reopened.CheckpointLSN() != 10 {
|
||||
t.Fatalf("frontier after a reopen=%d checkpoint=%d err=%v want 10/10", frontier, reopened.CheckpointLSN(), err)
|
||||
}
|
||||
if got, want := reopened.sb.WALHead, reopened.wal.logicalHeadValue(); got != want {
|
||||
t.Fatalf("superblock WALHead byte cursor=%d want %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user