mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-19 02:15:02 +01:00
* mount: answer an interrupted read with EINTR, not EIO The kernel's FUSE contract (Documentation/filesystems/fuse/fuse.rst, "Interrupting filesystem operations") lets a filesystem either ignore an INTERRUPT or honor it by replying EINTR to the original request. Read did neither: the FUSE cancel channel cancels the read's context, the chunk fetch fails with "context canceled", and every error became EIO. Interrupts come from any signal the reader handles. Go's runtime sends SIGURG for goroutine preemption, so Go programs reading under load hit this on healthy data: on a 128-thread 64 KiB random-read test about 250 of 5 million reads failed with EIO, and none with GODEBUG=asyncpreemptoff=1. Read now returns EINTR when its own context was cancelled, the way dirReadStatus already does for directory reads and lookups do since #11717. Go's os.File retries EINTR, so those readers see no error. A cancelled read also skips the entry refresh retry, and neither read log line reports an interrupt as a warning or error. Failures without an interrupt stay EIO. Tests: TestReadInterruptedReturnsEINTR (fails on the old code with EIO), TestReadFailureWithoutInterruptReturnsEIO; weed/mount/... passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: require the failed-read test to reach the filer Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: skip the read retry once the request is interrupted Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
110 lines
3.3 KiB
Go
110 lines
3.3 KiB
Go
package mount
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/go-fuse/v2/fuse"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// remoteReadFiler answers the download of an uncached remote file: stalled
|
|
// parks it until the caller's context ends, otherwise it fails at once.
|
|
type remoteReadFiler struct {
|
|
filer_pb.UnimplementedSeaweedFilerServer
|
|
stalled bool
|
|
started chan struct{}
|
|
}
|
|
|
|
func (s *remoteReadFiler) CacheRemoteObjectToLocalCluster(ctx context.Context, req *filer_pb.CacheRemoteObjectToLocalClusterRequest) (*filer_pb.CacheRemoteObjectToLocalClusterResponse, error) {
|
|
select {
|
|
case <-s.started:
|
|
default:
|
|
close(s.started)
|
|
}
|
|
if !s.stalled {
|
|
return nil, status.Error(codes.NotFound, "remote object gone")
|
|
}
|
|
<-ctx.Done()
|
|
return nil, status.Error(codes.Canceled, ctx.Err().Error())
|
|
}
|
|
|
|
// startRemoteRead opens /dir/file as an uncached remote entry and reads it
|
|
// in the background with the given FUSE cancel channel.
|
|
func startRemoteRead(t *testing.T, fake *remoteReadFiler, cancel chan struct{}) <-chan fuse.Status {
|
|
t.Helper()
|
|
wfs := newInvalidateTestWFS(t)
|
|
startFakeFiler(t, wfs, fake)
|
|
|
|
root := util.FullPath("/")
|
|
wfs.inodeToPath.MarkChildrenCached(root)
|
|
wfs.inodeToPath.Lookup(util.FullPath("/dir"), time.Now().Unix(), true, false, 0, false)
|
|
wfs.inodeToPath.MarkChildrenCached(util.FullPath("/dir"))
|
|
inode := wfs.inodeToPath.Lookup(util.FullPath("/dir/file"), time.Now().Unix(), false, false, 0, false)
|
|
fh, _, _, _ := wfs.fhMap.AcquireFileHandle(wfs, inode, &filer_pb.Entry{
|
|
Name: "file",
|
|
Attributes: &filer_pb.FuseAttributes{FileSize: 4096},
|
|
RemoteEntry: &filer_pb.RemoteEntry{RemoteSize: 4096},
|
|
}, 0, 0)
|
|
|
|
done := make(chan fuse.Status, 1)
|
|
go func() {
|
|
_, code := wfs.Read(cancel, &fuse.ReadIn{
|
|
InHeader: fuse.InHeader{NodeId: inode},
|
|
Fh: uint64(fh.fh),
|
|
Size: 4096,
|
|
}, make([]byte, 4096))
|
|
done <- code
|
|
}()
|
|
return done
|
|
}
|
|
|
|
// The kernel's FUSE contract answers an interrupted request with EINTR on the
|
|
// original request. Interrupts come from any handled signal, Go's preemption
|
|
// SIGURG included, so EIO here would fail healthy reads.
|
|
func TestReadInterruptedReturnsEINTR(t *testing.T) {
|
|
fake := &remoteReadFiler{stalled: true, started: make(chan struct{})}
|
|
cancel := make(chan struct{})
|
|
done := startRemoteRead(t, fake, cancel)
|
|
|
|
select {
|
|
case <-fake.started:
|
|
case <-time.After(10 * time.Second):
|
|
t.Fatal("read never reached the filer")
|
|
}
|
|
close(cancel)
|
|
|
|
select {
|
|
case code := <-done:
|
|
if code != fuse.EINTR {
|
|
t.Fatalf("interrupted read returned %v, want EINTR", code)
|
|
}
|
|
case <-time.After(10 * time.Second):
|
|
t.Fatal("Read still blocked after the FUSE request was interrupted")
|
|
}
|
|
}
|
|
|
|
// A read that fails without an interrupt is a real I/O error and stays EIO.
|
|
func TestReadFailureWithoutInterruptReturnsEIO(t *testing.T) {
|
|
fake := &remoteReadFiler{started: make(chan struct{})}
|
|
done := startRemoteRead(t, fake, make(chan struct{}))
|
|
|
|
select {
|
|
case code := <-done:
|
|
if code != fuse.EIO {
|
|
t.Fatalf("failed read returned %v, want EIO", code)
|
|
}
|
|
select {
|
|
case <-fake.started:
|
|
default:
|
|
t.Fatal("read failed before it reached the filer")
|
|
}
|
|
case <-time.After(30 * time.Second):
|
|
t.Fatal("failed read never returned")
|
|
}
|
|
}
|