Compare commits

...
Author SHA1 Message Date
Chris LuandClaude Opus 5.5 9342ee3778 wdclient: drop cached locations the master no longer lists when an answer matches
A disjoint answer can fill an empty entry; a later answer the master
confirms must replace that location rather than merge beside it, since
cache hits are not filtered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 04:13:23 -08:00
Chris LuandClaude Opus 5.5 f17314ab51 wdclient: keep the re-lookup mark when a stale-epoch answer completes
An answer that crossed a cache reset is served but not cached, so it
must not consume the mark the next, cacheable answer needs to bypass
the master filter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 04:12:56 -08:00
Chris LuandClaude Opus 5.5 421db36ba2 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 <noreply@anthropic.com>
2026-11-17 03:44:11 -08:00
Chris LuandClaude Opus 5.5 bc9e2ff20e wdclient: gate the master lookup provider's cache writes on the map epoch
The provider wrote each answer straight into the vid map, so a lookup sent
before a master reset and answered after it landed in the new generation,
which a gateway's FilerClient now reads as the current master's view. The
answer now goes through fillLocations, which drops it once a reset passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 03:35:29 -08:00
Chris LuandClaude Opus 5.5 6626597e93 wdclient: do not cache an answer that shares no server with the master view
Overlapping lookups can answer from different filer snapshots. One that
completes after a pushed add adopted the master's view, and names none of
its servers, was merged back into the adopted entry. It is still served,
so a gateway whose master link lags keeps reading, but it is not cached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 03:34:52 -08:00
Chris LuandClaude Opus 5.5 d4736f27b2 wdclient: set the re-lookup mark and drop the entry under one lock
A lookup in flight could fill between the two, consume the mark and cache
the whole answer, which the delete then erased, leaving the failed read's
own re-lookup filtered again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 03:34:22 -08:00
Chris LuandClaude Opus 5.5 08c0a55265 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 <noreply@anthropic.com>
2026-11-17 03:24:05 -08:00
Chris LuandClaude Opus 5.5 ac31753a68 wdclient: serve a looked-up volume from the servers the master relearned
A lookup made after the gateway's master client relearned a volume can
still reach a filer that answers from the previous leader's view, and no
later add would correct what it cached. Once the master has relearned the
volume, a lookup answer now keeps only the servers the master lists, with
the master's fields. An answer naming none of them is served as before,
so a gateway whose own master link lags is not narrowed to its stale view.

The check runs under the same lock as the adoption, so a push landing
while a lookup is in flight is not undone by its fill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 03:18:48 -08:00
Chris LuandClaude Opus 5.5 ec21b897c9 wdclient: let master-pushed adds replace a volume's lookup-cached locations
After a master reconnect the FilerClient cache is cleared and refilled by
filer lookups. A filer whose own master client has not relearned a volume
yet still answers with the previous leader's view, so a server lost with
that leader gets cached. The new leader never knew it and never pushes its
removal, so it stays until a read of every such volume fails on it.

Once the gateway's master client has relearned a volume since its last
reset, an add pushed for it now replaces what lookups cached for that
volume with the master's view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 03:18:26 -08:00
5 changed files with 290 additions and 21 deletions

No files matched your search

+7 -2
View File
@@ -186,6 +186,9 @@ func NewFilerClient(filerAddresses []pb.ServerAddress, grpcDialOption grpc.DialO
}
fc.vidMapClient = newVidMapClient(provider, dataCenter, cacheSize)
if masterClient != nil {
fc.vidMapClient.authority = masterClient.vidMap
}
return fc
}
@@ -528,8 +531,9 @@ func (fc *FilerClient) applyDiscoveredFilersLocked(discoveredFilers map[pb.Serve
}
// OnVolumeLocationChange applies master-pushed changes to the lookup-fed cache,
// so a retired server stops being tried before a read against it fails. Adds
// only lift the removal fence; locations are still learned by lookup.
// so a retired server stops being tried before a read against it fails. An add
// lifts the removal fence and replaces what lookups cached for the volume with
// the master's view.
func (fc *FilerClient) OnVolumeLocationChange(loc Location, addedVids, deletedVids []uint32) {
for _, vid := range deletedVids {
fc.tombstone(vid, loc)
@@ -537,6 +541,7 @@ func (fc *FilerClient) OnVolumeLocationChange(loc Location, addedVids, deletedVi
}
for _, vid := range addedVids {
fc.untombstone(vid, loc)
fc.adoptLocations(vid)
}
}
+161
View File
@@ -444,6 +444,7 @@ func TestOnVolumeLocationChangeReaddClearsTombstone(t *testing.T) {
func hookedFilerClient(mc *MasterClient, provider VolumeLocationProvider) *FilerClient {
fc := newTestFilerClient()
fc.vidMapClient = newVidMapClient(provider, "", 0)
fc.vidMapClient.authority = mc.vidMap
mc.SetOnVolumeLocationChangeFn(fc.OnVolumeLocationChange)
mc.SetOnVidMapResetFn(fc.OnVidMapReset)
return fc
@@ -561,3 +562,163 @@ func TestReconnectReplayLiftsFence(t *testing.T) {
expectServed(t, fc, "5", a)
}
// A new leader never knew a server lost with the old one, so no removal names
// it; a lookup answered from the old view before the adds arrived must not
// keep it cached once they do.
func TestPushedAddsReplaceStaleLookup(t *testing.T) {
a := Location{Url: "a:8080"}
b := Location{Url: "b:8080"}
dead := Location{Url: "dead:8080"}
provider := &testLocationProvider{locations: map[string][]Location{"5": {a, b, dead}}}
mc := moveClient()
fc := hookedFilerClient(mc, provider)
for _, url := range []string{a.Url, b.Url, dead.Url} {
pushVolumeLocation(mc, url, []uint32{5}, nil, nil, nil)
}
mc.resetVidMap()
expectServed(t, fc, "5", a, b, dead)
pushVolumeLocation(mc, a.Url, []uint32{5}, nil, nil, nil)
pushVolumeLocation(mc, b.Url, []uint32{5}, nil, nil, nil)
if cached, _ := fc.GetLocations(5); len(cached) != 2 || cached[0].Url != a.Url || cached[1].Url != b.Url {
t.Fatalf("cache holds %v, want %v and %v", cached, a, b)
}
}
// A filer still serving the old leader's view answers a lookup made after the
// adds arrived.
func TestLookupServesOnlyRelearnedServers(t *testing.T) {
a := Location{Url: "a:8080"}
dead := Location{Url: "dead:8080"}
provider := &testLocationProvider{locations: map[string][]Location{"5": {a, dead}}}
mc := moveClient()
fc := hookedFilerClient(mc, provider)
pushVolumeLocation(mc, dead.Url, []uint32{5}, nil, nil, nil)
mc.resetVidMap()
pushVolumeLocation(mc, a.Url, []uint32{5}, nil, nil, nil)
expectServed(t, fc, "5", a)
if cached, _ := fc.GetLocations(5); len(cached) != 1 || cached[0].Url != a.Url {
t.Fatalf("cache holds %v, want only %v", cached, a)
}
}
// Volumes the master has not relearned, or for which it lists none of the
// answered servers, are served as the lookup answered.
func TestLookupKeepsAnswerTheMasterCannotConfirm(t *testing.T) {
a := Location{Url: "a:8080"}
b := Location{Url: "b:8080"}
provider := &testLocationProvider{locations: map[string][]Location{"5": {a}, "6": {a}}}
mc := moveClient()
fc := hookedFilerClient(mc, provider)
pushVolumeLocation(mc, a.Url, []uint32{5}, nil, nil, nil)
mc.resetVidMap()
pushVolumeLocation(mc, b.Url, []uint32{6}, nil, nil, nil)
expectServed(t, fc, "5", a)
expectServed(t, fc, "6", a)
}
// Adds only correct what lookups cached, they do not fill the cache.
func TestPushedAddLeavesUncachedVolumeAlone(t *testing.T) {
mc := moveClient()
fc := hookedFilerClient(mc, &testLocationProvider{})
pushVolumeLocation(mc, "a:8080", []uint32{5}, nil, nil, nil)
if cached, found := fc.GetLocations(5); found {
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)
}
// Overlapping lookups can answer from different filer snapshots. One that
// lands after an add adopted the master's view, and names none of its
// servers, is served but must not merge back into the adopted entry.
func TestDisjointAnswerDoesNotUndoAdoption(t *testing.T) {
a := Location{Url: "a:8080"}
dead := Location{Url: "dead:8080"}
provider := &testLocationProvider{locations: map[string][]Location{"5": {a, dead}}}
mc := moveClient()
fc := hookedFilerClient(mc, provider)
expectServed(t, fc, "5", a, dead)
epoch := fc.mapEpoch()
pushVolumeLocation(mc, a.Url, []uint32{5}, nil, nil, nil)
if live := fc.fillLocations(5, []Location{dead}, epoch); len(live) != 1 || live[0].Url != dead.Url {
t.Fatalf("disjoint answer served as %v, want %v", live, dead)
}
if cached, _ := fc.GetLocations(5); len(cached) != 1 || cached[0].Url != a.Url {
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)
}
}
// A lookup that crossed a cache reset is not cached, so it must leave the
// re-lookup mark for the answer that will be.
func TestStaleAnswerKeepsRelookupMark(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)
epoch := fc.mapEpoch()
fc.clearVidMap()
fc.InvalidateCache("5,01")
fc.fillLocations(5, []Location{a}, epoch)
expectServed(t, fc, "5", a, b)
}
// A disjoint answer that filled the cache is dropped once an answer the
// master confirms arrives, instead of staying merged beside it.
func TestMatchingAnswerDropsCachedDisjointLocation(t *testing.T) {
a := Location{Url: "a:8080"}
dead := Location{Url: "dead:8080"}
mc := moveClient()
fc := hookedFilerClient(mc, &testLocationProvider{})
pushVolumeLocation(mc, a.Url, []uint32{5}, nil, nil, nil)
epoch := fc.mapEpoch()
fc.fillLocations(5, []Location{dead}, epoch)
if live := fc.fillLocations(5, []Location{a, dead}, epoch); len(live) != 1 || live[0].Url != a.Url {
t.Fatalf("matching answer served as %v, want %v", live, a)
}
if cached, _ := fc.GetLocations(5); len(cached) != 1 || cached[0].Url != a.Url {
t.Fatalf("cache holds %v, want only %v", cached, a)
}
}
+2 -2
View File
@@ -72,6 +72,7 @@ func (p *masterVolumeProvider) LookupVolumeIds(ctx context.Context, volumeIds []
func() error {
result = make(map[string][]Location)
lookupErrors = nil
epoch := p.masterClient.mapEpoch()
// Per-attempt timeout bounds both master resolution and the RPC
// so a single attempt cannot consume the entire retry budget.
@@ -124,10 +125,9 @@ func (p *masterVolumeProvider) LookupVolumeIds(ctx context.Context, volumeIds []
ReadOnly: masterLoc.ReadOnly,
ReadOnlyCanDelete: masterLoc.ReadOnlyCanDelete,
}
// Update cache with the location
p.masterClient.addLocation(uint32(vid), loc)
locations = append(locations, loc)
}
p.masterClient.fillLocations(uint32(vid), locations, epoch)
if len(locations) > 0 {
result[vidOnly] = locations
+42
View File
@@ -178,11 +178,27 @@ func (vc *vidMap) GetVidLocations(vid string) (locations []Location, err error)
// answering from the stale copy. Returns found=false when nothing remains,
// including when only an older-generation entry would otherwise apply.
func (vc *vidMap) GetLocations(vid uint32) (locations []Location, found bool) {
return vc.getLocations(vid, false)
}
// GetCurrentLocations only returns locations refreshed in the active Master
// session. Ordinary callers may intentionally use retained generations during
// topology churn; cache retirement callers must not trust an older positive
// after reconnecting and potentially missing a DeletedVids update.
func (vc *vidMap) GetCurrentLocations(vid uint32) (locations []Location, found bool) {
return vc.getLocations(vid, true)
}
func (vc *vidMap) getLocations(vid uint32, currentOnly bool) (locations []Location, found bool) {
vc.RLock()
defer vc.RUnlock()
regular, hasRegular := lookupEntry(vc.vid2Locations, vid)
ec, hasEc := lookupEntry(vc.ecVid2Locations, vid)
if currentOnly {
hasRegular = hasRegular && regular.generation == vc.generation
hasEc = hasEc && ec.generation == vc.generation
}
switch {
case hasRegular && hasEc:
@@ -387,6 +403,32 @@ func (vc *vidMap) deleteVid(vid uint32) {
}
}
// replaceLocations sets the locations of a vid already cached, as one regular
// entry of the current generation.
func (vc *vidMap) replaceLocations(vid uint32, locations []Location) {
vc.Lock()
defer vc.Unlock()
regular, hasRegular := vc.vid2Locations[vid]
ec, hasEc := vc.ecVid2Locations[vid]
if !hasRegular && !hasEc {
return
}
if hasRegular {
vc.releaseEntry(regular)
}
if hasEc {
vc.releaseEntry(ec)
delete(vc.ecVid2Locations, vid)
}
replaced := make([]Location, len(locations))
copy(replaced, locations)
vc.vid2Locations[vid] = &locationsEntry{locations: replaced, generation: vc.generation}
for _, loc := range replaced {
vc.incrementServerRef(locationServerKey(loc))
}
}
// clear drops every location, keeping no history to fall back to.
func (vc *vidMap) clear() {
vc.Lock()
+78 -17
View File
@@ -41,6 +41,15 @@ type vidMapClient struct {
recentDeletes map[vidLocationKey]*list.Element
recentDeleteOrder *list.List // of recentDelete, oldest first
vidMapEpoch uint64
// authority, when set, is the vid map a master keeps pushing. Its view of
// a volume relearned since its last reset replaces what a provider
// 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 {
@@ -243,14 +252,7 @@ func (vc *vidMapClient) LookupVolumeIdsWithFallback(ctx context.Context, volumeI
continue
}
var live []Location
for _, loc := range locations {
if vc.fillLocation(uint32(vid), loc, fillEpoch) {
live = append(live, loc)
}
}
if len(live) > 0 {
if live := vc.fillLocations(uint32(vid), locations, fillEpoch); len(live) > 0 {
batchResult[vidString] = live
}
}
@@ -438,20 +440,71 @@ func (vc *vidMapClient) untombstone(vid uint32, loc Location) {
}
}
// fillLocation reports whether a provider answer may be served, and caches it
// unless a reset or clear happened since epoch. Holding recentDeletesMu across
// the check and the add keeps a concurrent removal from being undone.
func (vc *vidMapClient) fillLocation(vid uint32, loc Location, epoch uint64) bool {
// fillLocations returns the part of a provider answer that may be served, and
// caches it unless a reset or clear happened since epoch. Holding
// recentDeletesMu across the checks and the adds keeps a concurrent removal or
// adoption from being undone.
func (vc *vidMapClient) fillLocations(vid uint32, locations []Location, epoch uint64) (live []Location) {
vc.recentDeletesMu.Lock()
defer vc.recentDeletesMu.Unlock()
vc.expireRecentDeletes(time.Now())
if _, found := vc.recentDeletes[vidLocationKey{vid: vid, url: loc.Url}]; found {
return false
cache := vc.vidMapEpoch == epoch
if _, relookup := vc.relookups[vid]; relookup {
if cache {
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
if cached, found := vc.vidMap.GetLocations(vid); found && cache {
if kept := listedLocations(cached, current); len(kept) < len(cached) {
vc.vidMap.replaceLocations(vid, kept)
}
}
} else if _, cached := vc.vidMap.GetLocations(vid); cached {
// Served, but not merged into what a pushed add adopted.
cache = false
}
}
}
if vc.vidMapEpoch == epoch {
vc.vidMap.addLocation(vid, loc)
for _, loc := range locations {
if _, found := vc.recentDeletes[vidLocationKey{vid: vid, url: loc.Url}]; found {
continue
}
if cache {
vc.vidMap.addLocation(vid, loc)
}
live = append(live, loc)
}
return true
return live
}
// adoptLocations replaces what is cached for vid with the authority's view,
// once the authority has relearned vid since its last reset.
func (vc *vidMapClient) adoptLocations(vid uint32) {
if vc.authority == nil {
return
}
vc.recentDeletesMu.Lock()
defer vc.recentDeletesMu.Unlock()
if current, found := vc.authority.GetCurrentLocations(vid); found {
vc.vidMap.replaceLocations(vid, current)
}
}
// listedLocations returns the entries of current whose server also appears in
// locations.
func listedLocations(locations, current []Location) (listed []Location) {
for _, c := range current {
for _, loc := range locations {
if loc.Url == c.Url {
listed = append(listed, c)
break
}
}
}
return listed
}
// InvalidateCache removes all cached locations for a volume ID
@@ -462,5 +515,13 @@ func (vc *vidMapClient) InvalidateCache(fileId string) {
if err != nil {
return
}
vc.recentDeletesMu.Lock()
defer vc.recentDeletesMu.Unlock()
if vc.authority != nil {
if vc.relookups == nil {
vc.relookups = make(map[uint32]struct{})
}
vc.relookups[uint32(vid)] = struct{}{}
}
vc.vidMap.deleteVid(uint32(vid))
}