mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-30 17:00:48 +01:00
* mount: refuse to attach opens to a draining file handle With the writeback cache, releasing the last open of a file leaves the shared FileHandle in the map at counter zero while an async flush drains it; the worker removes the map entries once the flush commits. AcquireHandle waits for a pending flush and then attaches, but the two steps are not atomic: a release can slip in between, drop the counter to zero, and queue the drain while the opener goes on to mint a new file-handle id on the draining handle. When the drain completes, RemoveFileHandle deletes every fh id for the inode -- including the one just minted. The kernel still holds that id, so its next FUSE_READ gets ENOENT from GetHandle; the failed read leaves the folio not uptodate and the kernel surfaces EIO to userspace. This was the flaky TestWritebackCacheConcurrentMixedOps failure. AcquireFileHandle now refuses to attach when the shared handle has reached a zero counter and reports it as draining. AcquireHandle and the Create path retry the whole wait-resolve-attach sequence; the next pass blocks on the pending flush (flag registration and the counter drop share pendingAsyncFlushMu) and builds a fresh handle from the post-flush entry. The DLM-failure release in AcquireHandle also goes through ReleaseHandle so it cannot strand a counter-zero handle outside the drain bookkeeping. Removes the refreshEntryForRead retry from #12206, which worked around the symptom by refetching the entry after the fh id was already gone. Test: TestAcquireFileHandleRefusesDrainingHandle covers the refusal and fresh-handle path; TestWritebackCacheConcurrentMixedOps and an amplified concurrent-overwrite repro run clean. * mount: keep refresh-on-error retry for stale-chunk reads
44 lines
1.7 KiB
Go
44 lines
1.7 KiB
Go
package mount
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// A handle whose last open closed with a deferred flush stays in the map while
|
|
// the drain runs so rename/unlink can find it. A new open must NOT attach to it:
|
|
// the fh id it would mint is dropped by RemoveFileHandle, leaving kernel reads
|
|
// to fail with ENOENT — which the kernel reports to read() as EIO.
|
|
func TestAcquireFileHandleRefusesDrainingHandle(t *testing.T) {
|
|
wfs := &WFS{option: &Option{}}
|
|
fhMap := NewFileHandleToInode()
|
|
inode := uint64(12345)
|
|
|
|
fh, _, existed, draining := fhMap.AcquireFileHandle(wfs, inode, nil, 0, 0)
|
|
if existed || draining || fh == nil {
|
|
t.Fatalf("first acquire: fh=%v existed=%v draining=%v", fh, existed, draining)
|
|
}
|
|
fh.asyncFlushPending = true
|
|
|
|
// Last release with a deferred flush keeps the draining handle in the map.
|
|
released := fhMap.ReleaseByHandle(fh.fh)
|
|
if released != fh {
|
|
t.Fatalf("ReleaseByHandle returned %v, want the draining handle", released)
|
|
}
|
|
if _, found := fhMap.FindFileHandle(inode); !found {
|
|
t.Fatal("draining handle should stay in the map for rename/unlink")
|
|
}
|
|
|
|
// A new open must not resurrect the draining handle.
|
|
fh2, openFh, existed, draining := fhMap.AcquireFileHandle(wfs, inode, nil, 0, 0)
|
|
if !draining || fh2 != nil {
|
|
t.Fatalf("acquire during drain: fh=%v openFh=%v existed=%v draining=%v, want draining", fh2, openFh, existed, draining)
|
|
}
|
|
|
|
// After the drain removes the handle, the next acquire creates a fresh one.
|
|
fhMap.RemoveFileHandle(fh.fh, inode)
|
|
fh3, _, existed, draining := fhMap.AcquireFileHandle(wfs, inode, nil, 0, 0)
|
|
if draining || existed || fh3 == nil || fh3 == fh {
|
|
t.Fatalf("acquire after drain: fh=%v existed=%v draining=%v, want fresh handle", fh3, existed, draining)
|
|
}
|
|
}
|