SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
fuse mount: avoid lookup nil entry
Chris Lu8645283a7b8a
diff --git a/weed/filer2/filer_client_util.go b/weed/filer2/filer_client_util.goindex e80c4bf365..04da240b68 100644--- a/weed/filer2/filer_client_util.go+++ b/weed/filer2/filer_client_util.go@@ -102,9 +102,9 @@ func GetEntry(filerClient FilerClient, fullFilePath FullPath) (entry *filer_pb.E}// glog.V(3).Infof("read %s request: %v", fullFilePath, request)- resp, err := client.LookupDirectoryEntry(context.Background(), request)+ resp, err := filer_pb.LookupEntry(client, request)if err != nil {- if err == ErrNotFound || strings.Contains(err.Error(), ErrNotFound.Error()) {+ if err == ErrNotFound {return nil}glog.V(3).Infof("read %s %v: %v", fullFilePath, resp, err)diff --git a/weed/filesys/xattr.go b/weed/filesys/xattr.goindex 3ccecdf98f..993e7ad93c 100644--- a/weed/filesys/xattr.go+++ b/weed/filesys/xattr.go@@ -1,9 +1,6 @@package filesysimport (- "context"- "strings"-"github.com/chrislusf/seaweedfs/weed/filer2""github.com/chrislusf/seaweedfs/weed/glog""github.com/chrislusf/seaweedfs/weed/pb/filer_pb"@@ -124,9 +121,9 @@ func (wfs *WFS) maybeLoadEntry(dir, name string) (entry *filer_pb.Entry, err errDirectory: dir,}- resp, err := client.LookupDirectoryEntry(context.Background(), request)- if err != nil || resp == nil || resp.Entry == nil {- if err == filer2.ErrNotFound || strings.Contains(err.Error(), filer2.ErrNotFound.Error()) {+ resp, err := filer_pb.LookupEntry(client, request)+ if err != nil {+ if err == filer2.ErrNotFound {glog.V(3).Infof("file attr read not found file %v: %v", request, err)return fuse.ENOENT}diff --git a/weed/pb/filer_pb/filer_pb_helper.go b/weed/pb/filer_pb/filer_pb_helper.goindex 408caadcd4..b69a83354b 100644--- a/weed/pb/filer_pb/filer_pb_helper.go+++ b/weed/pb/filer_pb/filer_pb_helper.go@@ -3,7 +3,9 @@ package filer_pbimport ("context""fmt"+ "strings"+ "github.com/chrislusf/seaweedfs/weed/filer2""github.com/chrislusf/seaweedfs/weed/glog""github.com/chrislusf/seaweedfs/weed/storage/needle")@@ -84,3 +86,25 @@ func CreateEntry(client SeaweedFilerClient, request *CreateEntryRequest) error {}return nil}++func LookupEntry(client SeaweedFilerClient, request *LookupDirectoryEntryRequest) (*LookupDirectoryEntryResponse, error) {+ resp, err := filer_pb.LookupEntry(client, request)+ if err != nil {+ if err == filer2.ErrNotFound || strings.Contains(err.Error(), ErrNotFound.Error()) {+ return nil, filer2.ErrNotFound+ }+ glog.V(3).Infof("read %s/%v: %v", request.Directory, request.Entry.Name, err)+ return nil, fmt.Errorf("LookupEntry1: %v", err)+ }+ if resp.Error != "" && strings.Contains(resp.Error, ErrNotFound.Error()) {+ return nil, filer2.ErrNotFound+ }+ if resp.Error != "" {+ glog.V(3).Infof("lookup %s/%v: %v", request.Directory, request.Entry.Name, err)+ return nil, fmt.Errorf("LookupEntry2: %v", err)+ }+ if resp.Entry == nil {+ return nil, filer2.ErrNotFound+ }+ return resp, nil+}diff --git a/weed/replication/sink/filersink/filer_sink.go b/weed/replication/sink/filersink/filer_sink.goindex 6b82b90dfe..838c2c4416 100644--- a/weed/replication/sink/filersink/filer_sink.go+++ b/weed/replication/sink/filersink/filer_sink.go@@ -98,7 +98,7 @@ func (fs *FilerSink) CreateEntry(key string, entry *filer_pb.Entry) error {Name: name,}glog.V(1).Infof("lookup: %v", lookupRequest)- if resp, err := client.LookupDirectoryEntry(context.Background(), lookupRequest); err == nil && resp.Entry != nil {+ if resp, err := filer_pb.LookupEntry(client, lookupRequest); err == nil {if filer2.ETag(resp.Entry.Chunks) == filer2.ETag(entry.Chunks) {glog.V(0).Infof("already replicated %s", key)return nil@@ -148,14 +148,11 @@ func (fs *FilerSink) UpdateEntry(key string, oldEntry *filer_pb.Entry, newParent}glog.V(4).Infof("lookup entry: %v", request)- resp, err := client.LookupDirectoryEntry(context.Background(), request)+ resp, err := filer_pb.LookupEntry(client, request)if err != nil {glog.V(0).Infof("lookup %s: %v", key, err)return err}- if resp.Entry == nil {- return filer2.ErrNotFound- }existingEntry = resp.Entrydiff --git a/weed/s3api/filer_util.go b/weed/s3api/filer_util.goindex b94b30a87f..d43ca8e5db 100644--- a/weed/s3api/filer_util.go+++ b/weed/s3api/filer_util.go@@ -8,6 +8,7 @@ import ("strings""time"+ "github.com/chrislusf/seaweedfs/weed/filer2""github.com/chrislusf/seaweedfs/weed/glog""github.com/chrislusf/seaweedfs/weed/pb/filer_pb")@@ -202,15 +203,15 @@ func (s3a *S3ApiServer) exists(parentDirectoryPath string, entryName string, isD}glog.V(4).Infof("exists entry %v/%v: %v", parentDirectoryPath, entryName, request)- resp, err := client.LookupDirectoryEntry(context.Background(), request)+ resp, err := filer_pb.LookupEntry(client, request)if err != nil {+ if err == filer2.ErrNotFound {+ exists = false+ return nil+ }glog.V(0).Infof("exists entry %v: %v", request, err)return fmt.Errorf("exists entry %s/%s: %v", parentDirectoryPath, entryName, err)}- if resp.Entry == nil {- exists = false- return nil- }exists = resp.Entry.IsDirectory == isDirectorydiff --git a/weed/s3api/s3api_bucket_handlers.go b/weed/s3api/s3api_bucket_handlers.goindex a40c6244cf..c165ae2c41 100644--- a/weed/s3api/s3api_bucket_handlers.go+++ b/weed/s3api/s3api_bucket_handlers.go@@ -13,6 +13,7 @@ import ("github.com/aws/aws-sdk-go/service/s3""github.com/gorilla/mux"+ "github.com/chrislusf/seaweedfs/weed/filer2""github.com/chrislusf/seaweedfs/weed/glog""github.com/chrislusf/seaweedfs/weed/pb/filer_pb")@@ -117,7 +118,10 @@ func (s3a *S3ApiServer) HeadBucketHandler(w http.ResponseWriter, r *http.Request}glog.V(1).Infof("lookup bucket: %v", request)- if resp, err := client.LookupDirectoryEntry(context.Background(), request); err != nil || resp.Entry == nil {+ if _, err := filer_pb.LookupEntry(client, request); err != nil {+ if err == filer2.ErrNotFound {+ return filer2.ErrNotFound+ }return fmt.Errorf("lookup bucket %s/%s: %v", s3a.option.BucketsPath, bucket, err)}diff --git a/weed/shell/command_fs_cat.go b/weed/shell/command_fs_cat.goindex 8364e0de16..3db4879791 100644--- a/weed/shell/command_fs_cat.go+++ b/weed/shell/command_fs_cat.go@@ -1,7 +1,6 @@package shellimport (- "context""fmt""io""math"@@ -50,13 +49,10 @@ func (c *commandFsCat) Do(args []string, commandEnv *CommandEnv, writer io.WriteName: name,Directory: dir,}- respLookupEntry, err := client.LookupDirectoryEntry(context.Background(), request)+ respLookupEntry, err := filer_pb.LookupEntry(client, request)if err != nil {return err}- if respLookupEntry.Entry == nil {- return fmt.Errorf("file not found: %s", path)- }return filer2.StreamContent(commandEnv.MasterClient, writer, respLookupEntry.Entry.Chunks, 0, math.MaxInt32)diff --git a/weed/shell/command_fs_meta_cat.go b/weed/shell/command_fs_meta_cat.goindex ec5a093df0..52e2ee6c0e 100644--- a/weed/shell/command_fs_meta_cat.go+++ b/weed/shell/command_fs_meta_cat.go@@ -49,13 +49,10 @@ func (c *commandFsMetaCat) Do(args []string, commandEnv *CommandEnv, writer io.WName: name,Directory: dir,}- respLookupEntry, err := client.LookupDirectoryEntry(context.Background(), request)+ respLookupEntry, err := filer_pb.LookupEntry(client, request)if err != nil {return err}- if respLookupEntry.Entry == nil {- return fmt.Errorf("file not found: %s", path)- }m := jsonpb.Marshaler{EmitDefaults: true,diff --git a/weed/shell/command_fs_mv.go b/weed/shell/command_fs_mv.goindex 9b74e85e9d..85275058ea 100644--- a/weed/shell/command_fs_mv.go+++ b/weed/shell/command_fs_mv.go@@ -58,12 +58,12 @@ func (c *commandFsMv) Do(args []string, commandEnv *CommandEnv, writer io.WriterName: destinationDir,Directory: destinationName,}- respDestinationLookupEntry, err := client.LookupDirectoryEntry(context.Background(), destinationRequest)+ respDestinationLookupEntry, err := filer_pb.LookupEntry(client, destinationRequest)var targetDir, targetName string// moving a file or folder- if err == nil && respDestinationLookupEntry.Entry != nil && respDestinationLookupEntry.Entry.IsDirectory {+ if err == nil && respDestinationLookupEntry.Entry.IsDirectory {// to a directorytargetDir = filepath.ToSlash(filepath.Join(destinationDir, destinationName))targetName = sourceNamediff --git a/weed/shell/commands.go b/weed/shell/commands.goindex 93a4c94bbe..2239fa4352 100644--- a/weed/shell/commands.go+++ b/weed/shell/commands.go@@ -71,7 +71,7 @@ func (ce *CommandEnv) checkDirectory(filerServer string, filerPort int64, path sreturn ce.withFilerClient(filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {- resp, lookupErr := client.LookupDirectoryEntry(context.Background(), &filer_pb.LookupDirectoryEntryRequest{+ resp, lookupErr := filer_pb.LookupEntry(client, &filer_pb.LookupDirectoryEntryRequest{Directory: dir,Name: name,})@@ -79,10 +79,6 @@ func (ce *CommandEnv) checkDirectory(filerServer string, filerPort int64, path sreturn lookupErr}- if resp.Entry == nil {- return fmt.Errorf("entry not found")- }-if !resp.Entry.IsDirectory {return fmt.Errorf("not a directory")}