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)) }