mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-30 03:35:37 +00:00
filer: clean up manifest resolve error propagation and add webdav tes… (#11297)
filer: clean up manifest resolve error propagation and add webdav test (#78) Drop GitHub issue references from comments and trim verbose comments. Replace the viewFromChunksOrErr helper with the existing NonOverlappingVisibleIntervals + ViewFromVisibleIntervals at the stream call sites, and add a WebDavFile.Read regression test for the manifest resolution failure path. Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
This commit is contained in:
@@ -570,7 +570,6 @@ func (f *WebDavFile) Read(p []byte) (readSize int, err error) {
|
||||
if f.visibleIntervals == nil {
|
||||
f.visibleIntervals, err = filer.NonOverlappingVisibleIntervals(f.ctx, f.fs.filerClient.GetLookupFileIdFunction(), f.entry.GetChunks(), 0, fileSize)
|
||||
if err != nil {
|
||||
// fail instead of streaming zeros for unresolved manifest chunks
|
||||
return 0, err
|
||||
}
|
||||
f.reader = nil
|
||||
|
||||
@@ -2,13 +2,20 @@ package weed_server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/webdav"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
"github.com/seaweedfs/seaweedfs/weed/wdclient"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestToFileInfoName(t *testing.T) {
|
||||
@@ -54,3 +61,46 @@ func TestFileInfoETag(t *testing.T) {
|
||||
t.Errorf("ETag() = %v, want the stat error", err)
|
||||
}
|
||||
}
|
||||
|
||||
type noVolumeFiler struct {
|
||||
filer_pb.UnimplementedSeaweedFilerServer
|
||||
}
|
||||
|
||||
func (f *noVolumeFiler) LookupVolume(_ context.Context, _ *filer_pb.LookupVolumeRequest) (*filer_pb.LookupVolumeResponse, error) {
|
||||
return &filer_pb.LookupVolumeResponse{LocationsMap: map[string]*filer_pb.Locations{}}, nil
|
||||
}
|
||||
|
||||
func startFakeWebDavFiler(t *testing.T, impl filer_pb.SeaweedFilerServer) pb.ServerAddress {
|
||||
t.Helper()
|
||||
lis, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
srv := grpc.NewServer()
|
||||
filer_pb.RegisterSeaweedFilerServer(srv, impl)
|
||||
go srv.Serve(lis)
|
||||
t.Cleanup(srv.Stop)
|
||||
port := lis.Addr().(*net.TCPAddr).Port
|
||||
return pb.ServerAddress(fmt.Sprintf("127.0.0.1:1.%d", port))
|
||||
}
|
||||
|
||||
// WebDavFile.Read must fail when chunk manifest resolution fails, instead of streaming zeros.
|
||||
func TestWebDavFile_Read_ManifestResolveFailure(t *testing.T) {
|
||||
filerAddr := startFakeWebDavFiler(t, &noVolumeFiler{})
|
||||
fc := wdclient.NewFilerClient([]pb.ServerAddress{filerAddr}, grpc.WithTransportCredentials(insecure.NewCredentials()), "")
|
||||
t.Cleanup(fc.Close)
|
||||
|
||||
fs := &WebDavFileSystem{filerClient: fc}
|
||||
entry := &filer_pb.Entry{
|
||||
Name: "file",
|
||||
Attributes: &filer_pb.FuseAttributes{FileSize: 1 << 20},
|
||||
Chunks: []*filer_pb.FileChunk{
|
||||
{FileId: "1,1679011dc64abd40", IsChunkManifest: true, Offset: 0, Size: 1 << 20},
|
||||
},
|
||||
}
|
||||
f := &WebDavFile{fs: fs, name: "/file", entry: entry, ctx: context.Background()}
|
||||
|
||||
n, err := f.Read(make([]byte, 16))
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, 0, n)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user