mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
* filer: stamp rename stream responses with the move's commit stamp The responses carried time.Now(), but the client applies them against the versions its earlier writes left at their log stamps. Stamps are drawn as max(now, last+1), so on a coarse clock (Windows) they run ahead of the wall clock, and a rename right after a flush of its source was stamped below that flush. The mount's version fence then kept the source in its cache: a renamed-away file still stat'ed and listed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: test rename responses stamp above earlier events Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci: run the Windows mount on changes to the filer's rename handler Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
150 lines
5.5 KiB
Go
150 lines
5.5 KiB
Go
package weed_server
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
// renameTestStream collects what StreamRenameEntry sends.
|
|
type renameTestStream struct {
|
|
grpc.ServerStream
|
|
sent []*filer_pb.StreamRenameEntryResponse
|
|
}
|
|
|
|
func (s *renameTestStream) Context() context.Context { return context.Background() }
|
|
func (s *renameTestStream) Send(resp *filer_pb.StreamRenameEntryResponse) error {
|
|
s.sent = append(s.sent, resp)
|
|
return nil
|
|
}
|
|
|
|
func streamRename(t *testing.T, store filer.FilerStore, oldName, newName string) (*renameTestStream, error) {
|
|
t.Helper()
|
|
server := &FilerServer{filer: newRenameTestFiler(t, store), entryLockTable: util.NewLockTable[util.FullPath]()}
|
|
stream := &renameTestStream{}
|
|
err := server.StreamRenameEntry(&filer_pb.StreamRenameEntryRequest{
|
|
OldDirectory: "/",
|
|
OldName: oldName,
|
|
NewDirectory: "/",
|
|
NewName: newName,
|
|
}, stream)
|
|
return stream, err
|
|
}
|
|
|
|
// A directory renamed onto a non-empty directory is refused. The refusal has
|
|
// to end the rename's transaction: a SQL store otherwise keeps it open, and
|
|
// with it one of its pool's connections, for the life of the filer.
|
|
func TestStreamRenameOntoNonEmptyDirectoryEndsItsTransaction(t *testing.T) {
|
|
store := newRenameTestStore()
|
|
store.strictTx = true
|
|
store.entries["/a"] = newDirectoryEntry("/a", 101)
|
|
store.entries["/b"] = newDirectoryEntry("/b", 102)
|
|
store.entries["/b/x.txt"] = newFileEntry("/b/x.txt", 103)
|
|
|
|
stream, err := streamRename(t, store, "a", "b")
|
|
if err == nil || !strings.Contains(err.Error(), "is not empty") {
|
|
t.Fatalf("StreamRenameEntry error = %v, want \"is not empty\"", err)
|
|
}
|
|
if n := store.openTransactions(); n != 0 {
|
|
t.Fatalf("%d transaction(s) left open after the refusal", n)
|
|
}
|
|
if len(stream.sent) != 0 {
|
|
t.Fatalf("sent %d responses for a refused rename", len(stream.sent))
|
|
}
|
|
if _, err := store.FindEntry(context.Background(), "/a"); err != nil {
|
|
t.Fatalf("source after the refusal: %v", err)
|
|
}
|
|
}
|
|
|
|
// The other ways out of StreamRenameEntry end the transaction too.
|
|
func TestStreamRenameEndsItsTransaction(t *testing.T) {
|
|
t.Run("onto a file", func(t *testing.T) {
|
|
store := newRenameTestStore()
|
|
store.strictTx = true
|
|
store.entries["/a"] = newDirectoryEntry("/a", 101)
|
|
store.entries["/c.txt"] = newFileEntry("/c.txt", 102)
|
|
if _, err := streamRename(t, store, "a", "c.txt"); err == nil || !strings.Contains(err.Error(), "is not directory") {
|
|
t.Fatalf("StreamRenameEntry error = %v, want \"is not directory\"", err)
|
|
}
|
|
if n := store.openTransactions(); n != 0 {
|
|
t.Fatalf("%d transaction(s) left open", n)
|
|
}
|
|
})
|
|
t.Run("onto an empty directory", func(t *testing.T) {
|
|
store := newRenameTestStore()
|
|
store.strictTx = true
|
|
store.entries["/a"] = newDirectoryEntry("/a", 101)
|
|
store.entries["/a/y.txt"] = newFileEntry("/a/y.txt", 102)
|
|
store.entries["/e"] = newDirectoryEntry("/e", 103)
|
|
if _, err := streamRename(t, store, "a", "e"); err != nil {
|
|
t.Fatalf("StreamRenameEntry: %v", err)
|
|
}
|
|
if n := store.openTransactions(); n != 0 {
|
|
t.Fatalf("%d transaction(s) left open", n)
|
|
}
|
|
if _, err := store.FindEntry(context.Background(), "/e/y.txt"); err != nil {
|
|
t.Fatalf("moved child: %v", err)
|
|
}
|
|
})
|
|
}
|
|
|
|
// The client applies each response at its TsNs over versions its own writes
|
|
// left at their log stamps. Where the wall clock is coarse (Windows), those
|
|
// stamps run ahead of it: a response stamped from the clock lands below the
|
|
// source's last write, and the client keeps the name the rename took away.
|
|
func TestStreamRenameResponsesStampAboveEarlierEvents(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
store func() *renameTestStore
|
|
oldName, newName string
|
|
}{
|
|
{"file over a file", func() *renameTestStore {
|
|
store := newRenameTestStore()
|
|
store.entries["/dir"] = newDirectoryEntry("/dir", 100)
|
|
store.entries["/dir/src.txt"] = newFileEntry("/dir/src.txt", 101)
|
|
store.entries["/dir/dst.txt"] = newFileEntry("/dir/dst.txt", 102)
|
|
return store
|
|
}, "src.txt", "dst.txt"},
|
|
{"file over a file in place", func() *renameTestStore {
|
|
store := newInPlaceRenameStore()
|
|
store.entries["/dir/dst.txt"] = fileEntryWithChunk("/dir/dst.txt", 202, "2,0b02")
|
|
return store
|
|
}, "src.txt", "dst.txt"},
|
|
{"directory with a child", func() *renameTestStore {
|
|
store := newRenameTestStore()
|
|
store.entries["/dir"] = newDirectoryEntry("/dir", 100)
|
|
store.entries["/dir/a"] = newDirectoryEntry("/dir/a", 101)
|
|
store.entries["/dir/a/x.txt"] = newFileEntry("/dir/a/x.txt", 102)
|
|
return store
|
|
}, "a", "b"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
f := newRenameTestFiler(t, tc.store())
|
|
earlier := f.LocalDeliveredThroughTsNs(time.Now().Add(time.Hour).UnixNano())
|
|
server := &FilerServer{filer: f, entryLockTable: util.NewLockTable[util.FullPath]()}
|
|
stream := &renameTestStream{}
|
|
if err := server.StreamRenameEntry(&filer_pb.StreamRenameEntryRequest{
|
|
OldDirectory: "/dir", OldName: tc.oldName, NewDirectory: "/dir", NewName: tc.newName,
|
|
}, stream); err != nil {
|
|
t.Fatalf("StreamRenameEntry: %v", err)
|
|
}
|
|
if len(stream.sent) == 0 {
|
|
t.Fatal("no responses")
|
|
}
|
|
for i, resp := range stream.sent {
|
|
if resp.TsNs <= earlier {
|
|
t.Errorf("response %d (%s -> %s) stamped %d, not above %d stamped before the rename", i,
|
|
resp.EventNotification.GetOldEntry().GetName(), resp.EventNotification.GetNewEntry().GetName(), resp.TsNs, earlier)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|