From 08c0a552655e611c7a2aa366e3d2254ebb197f53 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 17 Nov 2026 03:24:05 -0800 Subject: [PATCH] wdclient: serve a failed read's re-lookup without the master filter The master drops a pushed update when a client's channel is full, so the gateway's view of a volume can lack a live replica. Filtering lookups by that view would then hand a read that failed on the listed server the same server again, and the read path retries only when the locations change. InvalidateCache now marks the volume, and its next provider answer is served whole. Co-Authored-By: Claude Opus 5.5 --- weed/wdclient/filer_client_test.go | 17 +++++++++++++++++ weed/wdclient/vidmap_client.go | 16 +++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/weed/wdclient/filer_client_test.go b/weed/wdclient/filer_client_test.go index 95e1a6b8b8..2ea6297f36 100644 --- a/weed/wdclient/filer_client_test.go +++ b/weed/wdclient/filer_client_test.go @@ -632,3 +632,20 @@ func TestPushedAddLeavesUncachedVolumeAlone(t *testing.T) { t.Fatalf("an add cached volume 5 at %v", cached) } } + +// A master that dropped a replica's add lists only the other one. A read +// failing there re-looks the volume up, and that answer must reach the +// replica the master did not list. +func TestRelookupAfterFailedReadServesWholeAnswer(t *testing.T) { + a := Location{Url: "a:8080"} + b := Location{Url: "b:8080"} + provider := &testLocationProvider{locations: map[string][]Location{"5": {a, b}}} + mc := moveClient() + fc := hookedFilerClient(mc, provider) + pushVolumeLocation(mc, a.Url, []uint32{5}, nil, nil, nil) + expectServed(t, fc, "5", a) + + fc.InvalidateCache("5,01") + + expectServed(t, fc, "5", a, b) +} diff --git a/weed/wdclient/vidmap_client.go b/weed/wdclient/vidmap_client.go index d957cb7953..c38a4cfe32 100644 --- a/weed/wdclient/vidmap_client.go +++ b/weed/wdclient/vidmap_client.go @@ -46,6 +46,10 @@ type vidMapClient struct { // answered: that answer may still carry an earlier master's view, and a // server the current master never knew is never pushed as removed. authority *vidMap + // relookups holds vids a failed read invalidated. Their next provider + // answer is served whole, since the authority may lack a replica whose + // add the master dropped on a full client channel. + relookups map[uint32]struct{} } type recentDelete struct { @@ -444,7 +448,9 @@ func (vc *vidMapClient) fillLocations(vid uint32, locations []Location, epoch ui vc.recentDeletesMu.Lock() defer vc.recentDeletesMu.Unlock() vc.expireRecentDeletes(time.Now()) - if vc.authority != nil { + if _, relookup := vc.relookups[vid]; relookup { + delete(vc.relookups, vid) + } else if vc.authority != nil { if current, found := vc.authority.GetCurrentLocations(vid); found { if listed := listedLocations(locations, current); len(listed) > 0 { locations = listed @@ -498,5 +504,13 @@ func (vc *vidMapClient) InvalidateCache(fileId string) { if err != nil { return } + if vc.authority != nil { + vc.recentDeletesMu.Lock() + if vc.relookups == nil { + vc.relookups = make(map[uint32]struct{}) + } + vc.relookups[uint32(vid)] = struct{}{} + vc.recentDeletesMu.Unlock() + } vc.vidMap.deleteVid(uint32(vid)) }