mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
filer: wait for an owner this filer no longer follows before answering a forwarded rename
PeersCaughtUpTo counts an untracked peer as caught up. An owner whose stream was down long enough to be dropped has replayed nothing here, so a forwarded rename answered then could leave a follow-up unlink through this filer missing the target. Require the owner to be tracked with a watermark at or past the rename, still bounded by ownerEventsCatchUpCap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5534b55439
commit
cea3f6ebee
3 files changed
+59
-3
No files matched your search
@@ -460,6 +460,15 @@ func (ma *MetaAggregator) PeersCaughtUpTo(peers []pb.ServerAddress, tsNs int64)
|
||||
return true
|
||||
}
|
||||
|
||||
// PeerDeliveredThrough is PeersCaughtUpTo for one peer, except that a peer no
|
||||
// longer tracked has delivered nothing: its stream may reconnect and replay.
|
||||
func (ma *MetaAggregator) PeerDeliveredThrough(peer pb.ServerAddress, tsNs int64) bool {
|
||||
ma.peerWatermarksLock.Lock()
|
||||
defer ma.peerWatermarksLock.Unlock()
|
||||
ts, found := ma.peerWatermarks[peer]
|
||||
return found && ts >= tsNs
|
||||
}
|
||||
|
||||
func (ma *MetaAggregator) HasRemotePeers() bool {
|
||||
ma.peerChansLock.Lock()
|
||||
defer ma.peerChansLock.Unlock()
|
||||
|
||||
@@ -214,6 +214,53 @@ func TestForwardedRenameWaitsForOwnerEvents(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// An owner this filer no longer follows, its stream down long enough to be
|
||||
// dropped, has replayed nothing here: the rename waits for it to come back.
|
||||
func TestForwardedRenameWaitsForUntrackedOwner(t *testing.T) {
|
||||
c := newTwoFilers(t)
|
||||
storeB := separateStores(c)
|
||||
sharedWriteRing(c)
|
||||
ma := filer.NewMetaAggregator(c.fsA.filer, c.addrA, c.dial)
|
||||
c.fsA.filer.MetaAggregator = ma
|
||||
t.Cleanup(ma.Shutdown)
|
||||
|
||||
p := c.keyOwnedBy(t, c.addrB, c.addrB)
|
||||
dir, name := p.DirAndName()
|
||||
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(context.Background(), create); err != nil || resp.GetError() != "" {
|
||||
t.Fatalf("create via A: resp=%v err=%v", resp, err)
|
||||
}
|
||||
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := c.fsA.AtomicRenameEntry(context.Background(), &filer_pb.AtomicRenameEntryRequest{
|
||||
OldDirectory: dir, OldName: name, NewDirectory: dir, NewName: name + ".renamed",
|
||||
})
|
||||
done <- err
|
||||
}()
|
||||
select {
|
||||
case err := <-done:
|
||||
t.Fatalf("rename answered while A did not follow the owner: %v", err)
|
||||
case <-time.After(300 * time.Millisecond):
|
||||
}
|
||||
if _, err := storeB.FindEntry(context.Background(), p+".renamed"); err != nil {
|
||||
t.Fatalf("the owner has no renamed entry: %v", err)
|
||||
}
|
||||
|
||||
ma.TrackPeerForTesting(c.addrB)
|
||||
ma.ReportPeerWatermarksForTesting(c.addrB, c.fsB.filer.LocalMetaLogBuffer.LastTsNs.Load(), 0)
|
||||
select {
|
||||
case err := <-done:
|
||||
if err != nil {
|
||||
t.Fatalf("rename via A: %v", err)
|
||||
}
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("rename still waiting after A replayed the owner's events")
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
@@ -145,7 +145,8 @@ func (fs *FilerServer) forwardStreamRenameEntry(req *filer_pb.StreamRenameEntryR
|
||||
const ownerEventsCatchUpCap = 5 * time.Second
|
||||
|
||||
// ownerEventsPollInterval re-checks the owner's watermark, which can rise
|
||||
// without lifting the low watermark that wakes the wait.
|
||||
// without lifting the low watermark that wakes the wait, or reappear when
|
||||
// the owner's stream reconnects.
|
||||
const ownerEventsPollInterval = 10 * time.Millisecond
|
||||
|
||||
// awaitOwnerEvents waits until this filer has replayed the owner's metadata
|
||||
@@ -157,14 +158,13 @@ func (fs *FilerServer) awaitOwnerEvents(ctx context.Context, owner pb.ServerAddr
|
||||
if ma == nil || tsNs <= 0 {
|
||||
return
|
||||
}
|
||||
peers := []pb.ServerAddress{owner}
|
||||
deadline := time.NewTimer(ownerEventsCatchUpCap)
|
||||
defer deadline.Stop()
|
||||
poll := time.NewTicker(ownerEventsPollInterval)
|
||||
defer poll.Stop()
|
||||
for {
|
||||
advanced := ma.DeliveryWatermarkAdvancedChan()
|
||||
if ma.PeersCaughtUpTo(peers, tsNs) {
|
||||
if ma.PeerDeliveredThrough(owner, tsNs) {
|
||||
return
|
||||
}
|
||||
select {
|
||||
|
||||
Reference in new issue
Block a user