Files
seaweedfs/weed/mount/weedfs_write_test.go
T
6adc9f0a21 mount: read chunks with filer-issued exact-file read tokens (#12800)
* 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>
2026-11-22 23:07:14 -08:00

38 lines
1.4 KiB
Go

package mount
import (
"testing"
"github.com/seaweedfs/seaweedfs/weed/util/chunk_cache"
)
// TestShouldCacheUploadedChunk pins the chunk-caching decision. The read-auth
// case is the one 0005 adds: a keyless mount must cache every uploaded chunk
// (not only the first) so a read-after-write of a non-first chunk is served
// from the cache before the chunk's entry is published and a token exists.
func TestShouldCacheUploadedChunk(t *testing.T) {
cache := &chunk_cache.TieredChunkCache{}
for _, tc := range []struct {
name string
chunkCache *chunk_cache.TieredChunkCache
peerAnnouncer *PeerAnnouncer
readAuth *ReadAuth
offset int64
want bool
}{
{"no cache configured", nil, nil, nil, 0, false},
{"first chunk, plain mount", cache, nil, nil, 0, true},
{"non-first chunk, plain mount", cache, nil, nil, 1 << 20, false},
{"non-first chunk, peer sharing", cache, &PeerAnnouncer{}, nil, 1 << 20, true},
{"non-first chunk, read-auth mount", cache, nil, &ReadAuth{}, 1 << 20, true},
{"read-auth but cache disabled", nil, nil, &ReadAuth{}, 1 << 20, false},
} {
t.Run(tc.name, func(t *testing.T) {
wfs := &WFS{chunkCache: tc.chunkCache, peerAnnouncer: tc.peerAnnouncer, readAuth: tc.readAuth}
if got := wfs.shouldCacheUploadedChunk(tc.offset); got != tc.want {
t.Fatalf("shouldCacheUploadedChunk(offset=%d)=%v, want %v", tc.offset, got, tc.want)
}
})
}
}