mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
filer: refuse a forwarded no-replace rename over a target this filer has
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
815ead68c1
commit
5534b55439
2 files changed
+47
No files matched your search
@@ -213,3 +213,38 @@ func TestForwardedRenameWaitsForOwnerEvents(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A rename that must not replace its target is refused when this filer has
|
||||
// the target, even though the owner has not replayed it.
|
||||
func TestForwardedAtomicRenameEntryTargetExistsHere(t *testing.T) {
|
||||
c := newTwoFilers(t)
|
||||
storeB := separateStores(c)
|
||||
sharedWriteRing(c)
|
||||
p := c.keyOwnedBy(t, c.addrB, c.addrB)
|
||||
dir, name := p.DirAndName()
|
||||
ctx := context.Background()
|
||||
|
||||
create := &filer_pb.CreateEntryRequest{Directory: dir, OExcl: true, Entry: &filer_pb.Entry{
|
||||
Name: name, Attributes: &filer_pb.FuseAttributes{Mtime: 1700000000, FileMode: 0644},
|
||||
}}
|
||||
if resp, err := c.fsA.CreateEntry(ctx, create); err != nil || resp.GetError() != "" {
|
||||
t.Fatalf("create via A: resp=%v err=%v", resp, err)
|
||||
}
|
||||
target := p + ".target"
|
||||
if err := c.store.InsertEntry(ctx, newFileEntry(string(target), 7)); err != nil {
|
||||
t.Fatalf("seed A's target: %v", err)
|
||||
}
|
||||
|
||||
_, err := c.fsA.AtomicRenameEntry(ctx, &filer_pb.AtomicRenameEntryRequest{
|
||||
OldDirectory: dir, OldName: name, NewDirectory: dir, NewName: target.Name(), FailIfTargetExists: true,
|
||||
})
|
||||
if err == nil || !strings.Contains(err.Error(), filer_pb.ErrEntryAlreadyExists.Error()) {
|
||||
t.Fatalf("rename over a target A has: %v", err)
|
||||
}
|
||||
if _, err := storeB.FindEntry(ctx, p); err != nil {
|
||||
t.Fatalf("a refused rename moved the source on the owner: %v", err)
|
||||
}
|
||||
if _, err := storeB.FindEntry(ctx, target); err != filer_pb.ErrNotFound {
|
||||
t.Fatalf("a refused rename wrote the target on the owner: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,10 @@ package weed_server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -75,7 +77,17 @@ func (fs *FilerServer) forwardDeleteEntry(ctx context.Context, req *filer_pb.Del
|
||||
// forwardAtomicRenameEntry sends the rename to its source's write owner.
|
||||
// handled=false means this filer is the owner and applies it.
|
||||
func (fs *FilerServer) forwardAtomicRenameEntry(ctx context.Context, req *filer_pb.AtomicRenameEntryRequest, oldPath util.FullPath) (*filer_pb.AtomicRenameEntryResponse, bool, error) {
|
||||
newPath := util.FullPath(filepath.ToSlash(req.NewDirectory)).Child(req.NewName)
|
||||
handled, err := fs.forwardToWriteOwner(ctx, entryRouteKey(oldPath), func(owner pb.ServerAddress) error {
|
||||
// The owner checks the target against its own store, which may not
|
||||
// have replayed one this filer already has.
|
||||
if req.FailIfTargetExists && newPath != oldPath {
|
||||
if _, findErr := fs.filer.FindEntry(ctx, newPath); findErr == nil {
|
||||
return fmt.Errorf("%s: %w", newPath, filer_pb.ErrEntryAlreadyExists)
|
||||
} else if findErr != filer_pb.ErrNotFound {
|
||||
return findErr
|
||||
}
|
||||
}
|
||||
glog.V(2).InfofCtx(ctx, "AtomicRenameEntry %s: forwarding to owner %s", oldPath, owner)
|
||||
req.IsMoved = true
|
||||
return pb.WithFilerClient(false, 0, owner, fs.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
||||
|
||||
Reference in new issue
Block a user