From 421db36ba28e207d51344dec5a6cf095581aeba6 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 17 Nov 2026 03:44:11 -0800 Subject: [PATCH] wdclient: let a disjoint answer fill an empty cache entry Skipping the cache for every answer that shares no server with the master view made each read of such a volume another filer lookup, even with no adopted entry to protect. The answer is now cached when nothing is. Co-Authored-By: Claude Opus 5.5 --- weed/wdclient/filer_client_test.go | 15 +++++++++++++++ weed/wdclient/vidmap_client.go | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/weed/wdclient/filer_client_test.go b/weed/wdclient/filer_client_test.go index c2d0a3ac2c..c2806f04a4 100644 --- a/weed/wdclient/filer_client_test.go +++ b/weed/wdclient/filer_client_test.go @@ -670,3 +670,18 @@ func TestDisjointAnswerDoesNotUndoAdoption(t *testing.T) { t.Fatalf("cache holds %v, want only %v", cached, a) } } + +// With nothing cached there is no adopted entry to protect, so a disjoint +// answer fills the cache instead of costing a lookup per read. +func TestDisjointAnswerFillsEmptyCache(t *testing.T) { + a := Location{Url: "a:8080"} + b := Location{Url: "b:8080"} + mc := moveClient() + fc := hookedFilerClient(mc, &testLocationProvider{locations: map[string][]Location{"5": {b}}}) + pushVolumeLocation(mc, a.Url, []uint32{5}, nil, nil, nil) + + expectServed(t, fc, "5", b) + if cached, _ := fc.GetLocations(5); len(cached) != 1 || cached[0].Url != b.Url { + t.Fatalf("cache holds %v, want %v", cached, b) + } +} diff --git a/weed/wdclient/vidmap_client.go b/weed/wdclient/vidmap_client.go index ddb957b699..b774171808 100644 --- a/weed/wdclient/vidmap_client.go +++ b/weed/wdclient/vidmap_client.go @@ -455,7 +455,7 @@ func (vc *vidMapClient) fillLocations(vid uint32, locations []Location, epoch ui if current, found := vc.authority.GetCurrentLocations(vid); found { if listed := listedLocations(locations, current); len(listed) > 0 { locations = listed - } else { + } else if _, cached := vc.vidMap.GetLocations(vid); cached { // Served, but not merged into what a pushed add adopted. cache = false }