From 1f9cd2c76d1ed0fa8d99bc537b7b0b53bbf31e47 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 19 Nov 2026 21:16:28 -0800 Subject: [PATCH] wdclient: believe a provider answer that reports errors for some volumes The master provider answers a batch with a map of the volumes it knows and an error naming the ones it does not. The failed-lookup branch took that as no answer and revived what InvalidateCache had set aside, so a volume the master reported as absent came back with its old locations, and the batch could return them with a nil error. Only a nil map now means no answer. Otherwise the answer replaces what was set aside, and the provider's error is still returned. Co-Authored-By: Claude Opus 5.5 --- weed/wdclient/vidmap_client.go | 8 +++++++- weed/wdclient/vidmap_relookup_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/weed/wdclient/vidmap_client.go b/weed/wdclient/vidmap_client.go index 60332cfcd5..000dd51adc 100644 --- a/weed/wdclient/vidmap_client.go +++ b/weed/wdclient/vidmap_client.go @@ -244,7 +244,10 @@ func (vc *vidMapClient) LookupVolumeIdsWithFallback(ctx context.Context, volumeI glog.V(2).Infof("Looking up %d volumes from provider: %v", len(stillNeedLookup), stillNeedLookup) providerResults, err := vc.provider.LookupVolumeIds(ctx, stillNeedLookup) - if err != nil { + // A nil map means the provider got no answer. A provider that did get + // one can still report errors for some volumes, such as one the master + // does not know, and that answer replaces what was set aside. + if err != nil && providerResults == nil { // Without an answer, the locations InvalidateCache set aside are // still the best knowledge there is: one dead replica must not // take the volume's other replicas out of the cache with it. @@ -286,6 +289,9 @@ func (vc *vidMapClient) LookupVolumeIdsWithFallback(ctx context.Context, volumeI batchResult[vidString] = live } } + if err != nil { + return batchResult, fmt.Errorf("provider lookup failed: %w", err) + } return batchResult, nil }) diff --git a/weed/wdclient/vidmap_relookup_test.go b/weed/wdclient/vidmap_relookup_test.go index 9014631531..2a47adb5c4 100644 --- a/weed/wdclient/vidmap_relookup_test.go +++ b/weed/wdclient/vidmap_relookup_test.go @@ -434,3 +434,28 @@ func TestStaleEntryLifecycle(t *testing.T) { } }) } + +// The master answers a batch with an error for each volume it does not know, +// next to the locations of the volumes it does. That is an answer: a volume it +// does not know must not get what was set aside back, and a volume it does +// know is served from the answer. +func TestRelookupAnswerWithVolumeErrorsIsBelieved(t *testing.T) { + provider := &stubProvider{answer: func(call int) (map[string][]Location, error) { + return map[string][]Location{"6": {{Url: "new:8080"}}}, errors.New("master volume lookup errors: volume 5: volume id 5 not found") + }} + vc := newVidMapClient(provider, "", DefaultVidMapCacheSize) + vc.addLocation(5, Location{Url: "gone:8080"}) + vc.addLocation(6, Location{Url: "old:8080"}) + vc.InvalidateCache("5,0102") + vc.InvalidateCache("6,0102") + + locations, err := vc.LookupVolumeIdsWithFallback(context.Background(), []string{"5", "6"}) + if err == nil { + t.Fatal("volume 5 is not known to the master, want an error") + } + if len(locations["5"]) != 0 || len(sortedUrls(locations["6"])) != 1 || locations["6"][0].Url != "new:8080" { + t.Fatalf("locations %v, want volume 6 at new:8080 only", locations) + } + requireLocations(t, vc, 5) + requireLocations(t, vc, 6, "new:8080") +}