mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
filer.sync: retry an update whose destination lookup failed transiently
FilerSink.UpdateEntry reported every lookup error as a missing entry, so the replicator and filer.sync deleted the destination key and created it again. For a directory, a canceled or unavailable lookup removed it with everything under it. Only a real not-found now lets the caller recreate the key; other lookup errors are returned for retry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
977513cf35
commit
0b3bb80be8
2 files changed
+68
-5
No files matched your search
@@ -290,10 +290,7 @@ func (fs *FilerSink) entryMissing(key string) (bool, error) {
|
||||
if lookupErr == nil {
|
||||
return nil
|
||||
}
|
||||
// The string check is a deliberate compatibility fallback: a cross-cluster
|
||||
// gRPC error often arrives as a plain status string that no longer wraps the
|
||||
// filer_pb.ErrNotFound sentinel, so errors.Is alone would miss it.
|
||||
if errors.Is(lookupErr, filer_pb.ErrNotFound) || strings.Contains(lookupErr.Error(), filer_pb.ErrNotFound.Error()) {
|
||||
if isEntryNotFound(lookupErr) {
|
||||
missing = true
|
||||
return nil
|
||||
}
|
||||
@@ -302,6 +299,14 @@ func (fs *FilerSink) entryMissing(key string) (bool, error) {
|
||||
return missing, err
|
||||
}
|
||||
|
||||
// isEntryNotFound reports a lookup not-found. The string check is a deliberate
|
||||
// compatibility fallback: a cross-cluster gRPC error often arrives as a plain
|
||||
// status string that no longer wraps the filer_pb.ErrNotFound sentinel, so
|
||||
// errors.Is alone would miss it.
|
||||
func isEntryNotFound(err error) bool {
|
||||
return errors.Is(err, filer_pb.ErrNotFound) || strings.Contains(err.Error(), filer_pb.ErrNotFound.Error())
|
||||
}
|
||||
|
||||
func (fs *FilerSink) CreateEntry(key string, entry *filer_pb.Entry, signatures []int32) error {
|
||||
return fs.createEntry(key, entry, signatures, true)
|
||||
}
|
||||
@@ -420,7 +425,10 @@ func (fs *FilerSink) UpdateEntry(key string, oldEntry *filer_pb.Entry, newParent
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("lookup %s: %w", key, err)
|
||||
// Only a real not-found lets the caller delete and recreate the key; any
|
||||
// other lookup error must be retried, or a transient failure would wipe
|
||||
// a directory with everything under it.
|
||||
return !isEntryNotFound(err), fmt.Errorf("lookup %s: %w", key, err)
|
||||
}
|
||||
|
||||
glog.V(4).Infof("entry %s: old %q new %q existing %q", key, oldEntry.GetName(), newEntry.GetName(), existingEntry.GetName())
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package filersink
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type lookupErrFiler struct {
|
||||
filer_pb.UnimplementedSeaweedFilerServer
|
||||
err error
|
||||
}
|
||||
|
||||
func (f *lookupErrFiler) LookupDirectoryEntry(context.Context, *filer_pb.LookupDirectoryEntryRequest) (*filer_pb.LookupDirectoryEntryResponse, error) {
|
||||
return nil, f.err
|
||||
}
|
||||
|
||||
func TestUpdateEntryRecreatesOnlyOnNotFound(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
err error
|
||||
wantFound bool
|
||||
}{
|
||||
{"not found", status.Error(codes.NotFound, filer_pb.ErrNotFound.Error()), false},
|
||||
{"canceled", status.Error(codes.Canceled, "context canceled"), true},
|
||||
{"unavailable", status.Error(codes.Unavailable, "connection refused"), true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
lis, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
srv := grpc.NewServer()
|
||||
filer_pb.RegisterSeaweedFilerServer(srv, &lookupErrFiler{err: tc.err})
|
||||
go srv.Serve(lis)
|
||||
defer srv.Stop()
|
||||
|
||||
fs := &FilerSink{grpcAddress: lis.Addr().String(), grpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials())}
|
||||
dir := &filer_pb.Entry{Name: "object.versions", IsDirectory: true}
|
||||
found, err := fs.UpdateEntry("/buckets/b/object.versions", dir, "/buckets/b", dir, true, nil)
|
||||
if err == nil {
|
||||
t.Fatal("expected the lookup error")
|
||||
}
|
||||
if found != tc.wantFound {
|
||||
t.Fatalf("foundExistingEntry = %v, want %v (err %v)", found, tc.wantFound, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user