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 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-11-19 21:16:28 -08:00
1 parent 42eed77d12
commit 1f9cd2c76d
2 files changed
+32 -1

No files matched your search

+7 -1
View File
@@ -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
})
+25
View File
@@ -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")
}