Files
seaweedfs/weed/mount/peer_fake_cache_test.go
T
Chris LuandGitHub fe9ca35bbd peer chunk sharing 5/8: mount chunk-directory shard (#9134)
mount: tier-2 chunk directory + FetchChunk streaming on one gRPC port

Collapses the old two-port design (HTTP peer-serve + separate gRPC
directory) into a single gRPC service that handles every mount-to-
mount exchange: ChunkAnnounce, ChunkLookup, and the new FetchChunk
byte stream.

* peer_directory.go: fid -> holders shard, HRW-gated; returns holders
  in LRU order; capacity-bounded; Sweep handles eviction under
  write-lock while Lookup runs under RLock (hot path is concurrent).

* peer_grpc.go: single MountPeer gRPC server implementing all three
  RPCs. FetchChunk frames bytes at 1 MiB per Send so the default
  4 MiB message cap does not constrain chunk size; cache miss
  returns gRPC NOT_FOUND so clients distinguish miss from transport
  error. Reuses pb.NewGrpcServer for consistent keepalive + msg-size
  tuning.

* peer_bytepool.go: sync.Pool wrapper around *[]byte that the server
  uses to avoid a fresh 8 MiB allocation per FetchChunk call.

* WFS wiring starts the gRPC server on option.PeerListen (the single
  peer port) using the advertise address resolved in PR #3 as the
  HRW identity. A background sweeper evicts expired directory
  entries every 60 s.
2026-04-18 20:18:38 -07:00

42 lines
979 B
Go

package mount
// fakeChunkCache satisfies chunk_cache.ChunkCache with a simple in-memory
// map keyed by fid. Just enough to exercise the peer-serve handler paths.
type fakeChunkCache struct {
chunks map[string][]byte
}
func newFakeChunkCache() *fakeChunkCache {
return &fakeChunkCache{chunks: map[string][]byte{}}
}
func (f *fakeChunkCache) Put(fid string, data []byte) {
buf := make([]byte, len(data))
copy(buf, data)
f.chunks[fid] = buf
}
func (f *fakeChunkCache) ReadChunkAt(data []byte, fileId string, offset uint64) (int, error) {
b, ok := f.chunks[fileId]
if !ok {
return 0, nil
}
if int(offset) >= len(b) {
return 0, nil
}
return copy(data, b[offset:]), nil
}
func (f *fakeChunkCache) SetChunk(fileId string, data []byte) {
f.Put(fileId, data)
}
func (f *fakeChunkCache) IsInCache(fileId string, lockNeeded bool) bool {
_, ok := f.chunks[fileId]
return ok
}
func (f *fakeChunkCache) GetMaxFilePartSizeInCache() uint64 {
return 8 * 1024 * 1024
}