mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
* mount: read chunks with filer-issued exact-file read tokens * mount: preserve read authorization across delayed lookups and hard links * mount: retain response tokens across read cache eviction * mount: keep a shared read-token lookup alive when its first caller is cancelled Token refreshes for one entry share a singleflight lookup that ran under the first caller's context. An interrupted read cancelled that lookup, so every other read of the entry waiting on it got no token, went out unauthenticated, and failed with EIO on a volume server enforcing read JWTs. Run the lookup detached from the caller (each attempt stays bounded by the filer RPC wait) and let a cancelled caller stop waiting at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: serve a cached chunk past the cache cutoff instead of fetching it The full-chunk read path consulted the chunk cache only for chunks below the cache size cutoff. Read-auth and peer-sharing mounts cache every chunk they upload, so a read-after-write of a high-offset chunk went to the volume, where a read-auth mount has no token before the entry is published. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: re-track read tokens when this mount renames an open file Writeback mounts skip their own rename event, so only the subscriber path re-tracked an open handle's chunks. After a local rename a token refresh looked up the vacated name and the read failed. The rename response, the subscriber rename and the surviving hard link now share ReadAuth.TrackHandle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
108 lines
2.9 KiB
Go
108 lines
2.9 KiB
Go
package mount
|
|
|
|
import (
|
|
"context"
|
|
"runtime"
|
|
"strings"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
)
|
|
|
|
type readAuthLookupFiler struct {
|
|
filer_pb.UnimplementedSeaweedFilerServer
|
|
fid string
|
|
token string
|
|
calls atomic.Int32
|
|
entered chan struct{}
|
|
release chan struct{}
|
|
}
|
|
|
|
func (f *readAuthLookupFiler) LookupDirectoryEntries(ctx context.Context, req *filer_pb.LookupDirectoryEntriesRequest) (*filer_pb.LookupDirectoryEntriesResponse, error) {
|
|
f.calls.Add(1)
|
|
f.entered <- struct{}{}
|
|
select {
|
|
case <-f.release:
|
|
return &filer_pb.LookupDirectoryEntriesResponse{ReadAuth: map[string]string{f.fid: f.token}}, nil
|
|
case <-ctx.Done():
|
|
return nil, ctx.Err()
|
|
}
|
|
}
|
|
|
|
// parkedTokenCallers counts goroutines blocked inside ReadAuth.Token, either
|
|
// waiting on a token lookup or running one.
|
|
func parkedTokenCallers() int {
|
|
buf := make([]byte, 1<<20)
|
|
buf = buf[:runtime.Stack(buf, true)]
|
|
parked := 0
|
|
for _, g := range strings.Split(string(buf), "\n\n") {
|
|
header, _, _ := strings.Cut(g, "\n")
|
|
if strings.Contains(g, "(*ReadAuth).Token(") && (strings.Contains(header, "[select") || strings.Contains(header, "WaitGroup.Wait")) {
|
|
parked++
|
|
}
|
|
}
|
|
return parked
|
|
}
|
|
|
|
// A read cancelled while its token lookup is in flight must not leave the
|
|
// other reads waiting on that lookup without a token.
|
|
func TestReadAuthCancelledCallerKeepsSharedLookup(t *testing.T) {
|
|
fid := "3,01637037d6"
|
|
fake := &readAuthLookupFiler{
|
|
fid: fid,
|
|
token: makeUnsignedJwtWithExp(t, time.Now().Add(time.Minute).Unix()),
|
|
entered: make(chan struct{}, 4),
|
|
release: make(chan struct{}),
|
|
}
|
|
wfs := newLookupCacheTestWFS(t, 60)
|
|
startFakeFiler(t, wfs, fake)
|
|
ra := newReadAuth(wfs)
|
|
ra.Track(util.FullPath("/dir/file"), []*filer_pb.FileChunk{{FileId: fid}})
|
|
|
|
cancelledCtx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
cancelled := make(chan string, 1)
|
|
go func() { cancelled <- ra.Token(cancelledCtx, fid) }()
|
|
select {
|
|
case <-fake.entered:
|
|
case <-time.After(10 * time.Second):
|
|
t.Fatal("token lookup never reached the filer")
|
|
}
|
|
|
|
waiter := make(chan string, 1)
|
|
go func() { waiter <- ra.Token(context.Background(), fid) }()
|
|
deadline := time.Now().Add(10 * time.Second)
|
|
for parkedTokenCallers() < 2 {
|
|
if time.Now().After(deadline) {
|
|
t.Fatal("second reader never joined the in-flight lookup")
|
|
}
|
|
runtime.Gosched()
|
|
}
|
|
|
|
cancel()
|
|
select {
|
|
case got := <-cancelled:
|
|
if got != "" {
|
|
t.Fatalf("cancelled caller got %q, want no token", got)
|
|
}
|
|
case <-time.After(10 * time.Second):
|
|
t.Fatal("cancelled caller kept waiting on the lookup")
|
|
}
|
|
close(fake.release)
|
|
|
|
select {
|
|
case got := <-waiter:
|
|
if got != fake.token {
|
|
t.Fatalf("waiting reader got %q, want the looked-up token", got)
|
|
}
|
|
case <-time.After(10 * time.Second):
|
|
t.Fatal("waiting reader never got a token")
|
|
}
|
|
if calls := fake.calls.Load(); calls != 1 {
|
|
t.Fatalf("filer lookups = %d, want 1 shared lookup", calls)
|
|
}
|
|
}
|