mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
* wdclient: keep a volume's live replicas readable while another volume cannot be found A filer's "volume not found" answer counted as a filer failure, so three of them opened the circuit breaker on a healthy filer. With its only filer in the cool-down, every lookup then failed without asking, as "all 1 filer(s) failed with non-retryable error: %!w(<nil>)". And a refresh whose lookup failed left the cache without the volume's live replicas, since InvalidateCache had already dropped them with the dead one. The breaker now counts only failures to reach the filer, and asks the filers anyway when all of them are in their cool-down. InvalidateCache keeps what it removed; a lookup that errors puts it back unless the volume was learned again, the epoch moved, or a reset would have expired it, and leaves out locations fenced by a pushed removal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * wdclient: set invalidated locations aside in the map instead of copying them out The first commit kept what InvalidateCache removed in a side map and put it back when the lookup failed. The copy left the map's lock, so a removal the master pushed between the take and the put-back was undone: the removed server came back into the cache. The entry now stays in the map with a state. entryStale hides it from readers and releases its server references, as a delete did. A pushed removal edits it like any other entry. When the lookup after the invalidation returns an error, the entry becomes entryRevived and is served again. A stale or revived entry holds only what was known before the read failed, so the next thing learned replaces it: a lookup answer drops it before the answer is cached, including an answer with no locations and an answer to a lookup that was in flight when another one failed, and a pushed add replaces it instead of merging. LookupVolumeIdsWithFallback returns no error when every volume it was asked for has locations after the revive, so the filer's LookupVolume handler sends its response instead of an error status. The not-found breaker test now checks the failure count itself. Without that, a regression of the classification passed, because a lone filer in its cool-down is asked anyway. On the first commit, TestPushedRemovalRacingFailedRefreshes failed in 8 of 8 runs under -race: four with "got [live:8080 old:8080], want [live:8080]", four with "got [], want [live:8080]". Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * wdclient: retry a filer lookup pass that asked no filer The pass decides once whether to skip unhealthy filers. A filer whose breaker trips after that decision, as when a concurrent lookup records its failure, is still skipped. With every filer skipped the pass ended with no error and failed the lookup as non-retryable with "%!w(<nil>)". Such a pass now counts as Unavailable, so the lookup retries and the next pass asks the filers anyway. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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> * wdclient: keep set-aside locations learned after a lookup was asked A successful lookup dropped every stale or revived entry of the volumes it asked for, however old the answer was. A lookup asked before the master confirmed new locations could, on finishing, delete those locations after a read had set them aside and a failed refresh had revived them, and its own answer was not cached because the epoch had moved. Entries now record when their locations were learned, and an answer drops only what was learned before it was asked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * wdclient: keep an older answer from replacing locations set aside after it was askedfdcde25keeps dropSetAside from deleting set-aside locations that were learned after a lookup was asked. The answer's insertion still replaced them: fillLocations adds each location with vidMap.addLocation, and addLocationToMap replaces a stale or revived entry whatever its learnedAt. The epoch does not stop this when the newer locations came from another lookup's answer or, on the master client, from a pushed add, since neither moves it. The master client's provider also caches its answer itself, before LookupVolumeIdsWithFallback reaches dropSetAside. vidMap.addAnswer adds an answer's locations under one lock, and adds none of them while vid has a stale or revived entry learned after the lookup was asked. fillLocations uses it, and the master client's provider passes the learned mark it takes next to its epoch. An answer with nothing newer in the way still replaces what was set aside, with every location it reports. Onfdcde25, TestOlderAnswerDoesNotReplaceNewerRevivedLocations and the "newer location revived during the lookup" case of TestMasterAnswerAgainstSetAsideLocations fail with "got [old:8080], want [new:8080]". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * wdclient: move addAnswer next to dropSetAside Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
489 lines
17 KiB
Go
489 lines
17 KiB
Go
package wdclient
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"sort"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
// stubProvider answers lookups with locations, with no locations, or with an
|
|
// error, as the test sets it. beforeAnswer, when set, runs inside the lookup
|
|
// before it returns, the way a pushed update lands while a lookup is in flight.
|
|
// answer, when set, decides each call by its number instead.
|
|
type stubProvider struct {
|
|
mu sync.Mutex
|
|
locations map[string][]Location
|
|
err error
|
|
calls int
|
|
beforeAnswer func()
|
|
answer func(call int) (map[string][]Location, error)
|
|
}
|
|
|
|
func (p *stubProvider) LookupVolumeIds(ctx context.Context, volumeIds []string) (map[string][]Location, error) {
|
|
p.mu.Lock()
|
|
p.calls++
|
|
call, err, beforeAnswer, answer := p.calls, p.err, p.beforeAnswer, p.answer
|
|
p.mu.Unlock()
|
|
if answer != nil {
|
|
return answer(call)
|
|
}
|
|
if beforeAnswer != nil {
|
|
beforeAnswer()
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := make(map[string][]Location)
|
|
for _, vid := range volumeIds {
|
|
result[vid] = p.locations[vid]
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
var errNoAnswer = errors.New("filer unavailable")
|
|
|
|
func sortedUrls(locations []Location) []string {
|
|
urls := make([]string, 0, len(locations))
|
|
for _, loc := range locations {
|
|
urls = append(urls, loc.Url)
|
|
}
|
|
sort.Strings(urls)
|
|
return urls
|
|
}
|
|
|
|
func requireLocations(t *testing.T, vc *vidMapClient, vid uint32, want ...string) {
|
|
t.Helper()
|
|
locations, found := vc.GetLocations(vid)
|
|
if len(want) == 0 {
|
|
if found {
|
|
t.Fatalf("volume %d: got %v, want no locations", vid, sortedUrls(locations))
|
|
}
|
|
return
|
|
}
|
|
got := sortedUrls(locations)
|
|
if !found || len(got) != len(want) {
|
|
t.Fatalf("volume %d: got %v, want %v", vid, got, want)
|
|
}
|
|
for i := range want {
|
|
if got[i] != want[i] {
|
|
t.Fatalf("volume %d: got %v, want %v", vid, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// refresh does what a read does after a replica failed: invalidate the
|
|
// volume, then look it up again.
|
|
func refresh(vc *vidMapClient) error {
|
|
vc.InvalidateCache("5,0102")
|
|
_, err := vc.LookupFileIdWithFallback(context.Background(), "5,0102")
|
|
return err
|
|
}
|
|
|
|
// A read that finds one replica dead invalidates the volume and looks it up
|
|
// again. If that lookup gets no answer, the cache must keep the replicas it
|
|
// had: before the fix it was left empty, and every later read of the volume
|
|
// failed although its other replica was serving.
|
|
func TestInvalidateKeepsLocationsWhenRelookupFails(t *testing.T) {
|
|
provider := &stubProvider{err: errNoAnswer}
|
|
vc := newVidMapClient(provider, "", DefaultVidMapCacheSize)
|
|
vc.addLocation(5, Location{Url: "dead:8080"})
|
|
vc.addLocation(5, Location{Url: "live:8080"})
|
|
|
|
vc.InvalidateCache("5,0102")
|
|
requireLocations(t, vc, 5)
|
|
|
|
urls, err := vc.LookupFileIdWithFallback(context.Background(), "5,0102")
|
|
if err != nil {
|
|
t.Fatalf("lookup after a failed refresh: %v", err)
|
|
}
|
|
if len(urls) != 2 {
|
|
t.Fatalf("urls = %v, want both replicas", urls)
|
|
}
|
|
requireLocations(t, vc, 5, "dead:8080", "live:8080")
|
|
if provider.calls != 1 {
|
|
t.Fatalf("provider asked %d times, want 1", provider.calls)
|
|
}
|
|
}
|
|
|
|
// A lookup that recovered every volume it was asked for reports no error: a
|
|
// gRPC handler that returns one drops the locations along with it. A volume
|
|
// that stays unresolved is still an error, next to what was recovered.
|
|
func TestFailedRelookupReportsOnlyUnresolvedVolumes(t *testing.T) {
|
|
provider := &stubProvider{err: errNoAnswer}
|
|
vc := newVidMapClient(provider, "", DefaultVidMapCacheSize)
|
|
vc.addLocation(5, Location{Url: "live:8080"})
|
|
|
|
vc.InvalidateCache("5,0102")
|
|
locations, err := vc.LookupVolumeIdsWithFallback(context.Background(), []string{"5"})
|
|
if err != nil || len(locations["5"]) != 1 {
|
|
t.Fatalf("recovered lookup: locations %v, err %v", locations, err)
|
|
}
|
|
|
|
vc.InvalidateCache("5,0102")
|
|
locations, err = vc.LookupVolumeIdsWithFallback(context.Background(), []string{"5", "6"})
|
|
if err == nil {
|
|
t.Fatal("volume 6 has no locations, want an error")
|
|
}
|
|
if len(locations["5"]) != 1 || len(locations["6"]) != 0 {
|
|
t.Fatalf("locations %v, want volume 5 only", locations)
|
|
}
|
|
}
|
|
|
|
// An answer replaces what was set aside, and a later failed refresh brings
|
|
// back that answer rather than the older locations.
|
|
func TestRelookupAnswerReplacesStaleLocations(t *testing.T) {
|
|
provider := &stubProvider{locations: map[string][]Location{"5": {{Url: "live:8080"}}}}
|
|
vc := newVidMapClient(provider, "", DefaultVidMapCacheSize)
|
|
vc.addLocation(5, Location{Url: "dead:8080"})
|
|
vc.addLocation(5, Location{Url: "live:8080"})
|
|
|
|
if err := refresh(vc); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
requireLocations(t, vc, 5, "live:8080")
|
|
|
|
provider.err = errNoAnswer
|
|
if err := refresh(vc); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
requireLocations(t, vc, 5, "live:8080")
|
|
}
|
|
|
|
// A provider that answers that the volume has no locations is believed: what
|
|
// was set aside does not come back, then or on a later failed lookup.
|
|
func TestRelookupNotFoundAnswerIsBelieved(t *testing.T) {
|
|
provider := &stubProvider{locations: map[string][]Location{}}
|
|
vc := newVidMapClient(provider, "", DefaultVidMapCacheSize)
|
|
vc.addLocation(5, Location{Url: "gone:8080"})
|
|
|
|
if err := refresh(vc); err == nil {
|
|
t.Fatal("lookup succeeded, want not found")
|
|
}
|
|
requireLocations(t, vc, 5)
|
|
|
|
provider.err = errNoAnswer
|
|
if _, err := vc.LookupFileIdWithFallback(context.Background(), "5,0102"); err == nil {
|
|
t.Fatal("a later failed lookup brought back locations the provider said were gone")
|
|
}
|
|
}
|
|
|
|
// Two lookups of one volume can overlap under different batch keys. When one
|
|
// fails and brings the old locations back while the other is still in flight,
|
|
// the other's answer is the newer knowledge and replaces them.
|
|
func TestAnswerReplacesLocationsRevivedMeanwhile(t *testing.T) {
|
|
for name, tc := range map[string]struct {
|
|
answer []Location
|
|
want []string
|
|
}{
|
|
"no locations": {nil, nil},
|
|
"one replica": {[]Location{{Url: "live:8080"}}, []string{"live:8080"}},
|
|
} {
|
|
t.Run(name, func(t *testing.T) {
|
|
provider := &stubProvider{}
|
|
vc := newVidMapClient(provider, "", DefaultVidMapCacheSize)
|
|
vc.addLocation(5, Location{Url: "dead:8080"})
|
|
vc.addLocation(5, Location{Url: "live:8080"})
|
|
provider.answer = func(call int) (map[string][]Location, error) {
|
|
if call > 1 {
|
|
return nil, errNoAnswer
|
|
}
|
|
// While this lookup is in flight, another one fails and
|
|
// falls back to what was set aside.
|
|
if _, err := vc.LookupVolumeIdsWithFallback(context.Background(), []string{"5"}); err != nil {
|
|
t.Errorf("overlapping lookup: %v", err)
|
|
}
|
|
if locations, _ := vc.GetLocations(5); len(locations) != 2 {
|
|
t.Errorf("overlapping lookup revived %v, want both replicas", locations)
|
|
}
|
|
return map[string][]Location{"5": tc.answer, "6": {{Url: "six:8080"}}}, nil
|
|
}
|
|
|
|
vc.InvalidateCache("5,0102")
|
|
vc.LookupVolumeIdsWithFallback(context.Background(), []string{"5", "6"})
|
|
|
|
requireLocations(t, vc, 5, tc.want...)
|
|
requireLocations(t, vc, 6, "six:8080")
|
|
})
|
|
}
|
|
}
|
|
|
|
// masterClientWith is a MasterClient whose cache is fed by pushes, as from the
|
|
// master's stream, and whose lookups go to provider.
|
|
func masterClientWith(provider VolumeLocationProvider) *MasterClient {
|
|
return &MasterClient{vidMapClient: newVidMapClient(provider, "", DefaultVidMapCacheSize)}
|
|
}
|
|
|
|
// A removal the master pushes must hold however it is ordered against a
|
|
// refresh whose lookup gets no answer: the removed server stays out of the
|
|
// cache, and the volume's other servers still come back.
|
|
func TestPushedRemovalHoldsAcrossFailedRefresh(t *testing.T) {
|
|
type push struct{ newVids, deletedVids, newEcVids, deletedEcVids []uint32 }
|
|
forms := map[string]struct{ add, remove push }{
|
|
"regular": {push{newVids: []uint32{5}}, push{deletedVids: []uint32{5}}},
|
|
"ec": {push{newEcVids: []uint32{5}}, push{deletedEcVids: []uint32{5}}},
|
|
}
|
|
send := func(mc *MasterClient, url string, p push) {
|
|
pushVolumeLocation(mc, url, p.newVids, p.deletedVids, p.newEcVids, p.deletedEcVids)
|
|
}
|
|
|
|
for form, pushes := range forms {
|
|
for _, tc := range []struct {
|
|
name string
|
|
servers []string
|
|
want []string
|
|
}{
|
|
{"another replica left", []string{"old:8080", "live:8080"}, []string{"live:8080"}},
|
|
{"only replica", []string{"old:8080"}, nil},
|
|
} {
|
|
setup := func() (*MasterClient, *stubProvider) {
|
|
provider := &stubProvider{err: errNoAnswer}
|
|
mc := masterClientWith(provider)
|
|
for _, url := range tc.servers {
|
|
send(mc, url, pushes.add)
|
|
}
|
|
return mc, provider
|
|
}
|
|
check := func(t *testing.T, mc *MasterClient) {
|
|
t.Helper()
|
|
requireLocations(t, mc.vidMapClient, 5, tc.want...)
|
|
// and it does not come back on the refreshes that follow
|
|
refresh(mc.vidMapClient)
|
|
requireLocations(t, mc.vidMapClient, 5, tc.want...)
|
|
}
|
|
|
|
t.Run(form+"/"+tc.name+"/removed before the lookup", func(t *testing.T) {
|
|
mc, _ := setup()
|
|
mc.InvalidateCache("5,0102")
|
|
send(mc, "old:8080", pushes.remove)
|
|
mc.LookupFileIdWithFallback(context.Background(), "5,0102")
|
|
check(t, mc)
|
|
})
|
|
|
|
t.Run(form+"/"+tc.name+"/removed during the lookup", func(t *testing.T) {
|
|
mc, provider := setup()
|
|
var once sync.Once
|
|
provider.beforeAnswer = func() {
|
|
once.Do(func() { send(mc, "old:8080", pushes.remove) })
|
|
}
|
|
refresh(mc.vidMapClient)
|
|
check(t, mc)
|
|
})
|
|
|
|
t.Run(form+"/"+tc.name+"/removed after the lookup", func(t *testing.T) {
|
|
mc, _ := setup()
|
|
refresh(mc.vidMapClient)
|
|
send(mc, "old:8080", pushes.remove)
|
|
check(t, mc)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
// The same through a filer client that hears the master's pushes: the removal
|
|
// fences the server and takes it out of what was set aside.
|
|
func TestFencedRemovalHoldsAcrossFailedRefresh(t *testing.T) {
|
|
old := Location{Url: "old:8080"}
|
|
live := Location{Url: "live:8080"}
|
|
provider := &stubProvider{locations: map[string][]Location{"5": {old, live}}}
|
|
mc := moveClient()
|
|
fc := hookedFilerClient(mc, provider)
|
|
pushVolumeLocation(mc, old.Url, []uint32{5}, nil, nil, nil)
|
|
pushVolumeLocation(mc, live.Url, []uint32{5}, nil, nil, nil)
|
|
if _, err := fc.LookupFileIdWithFallback(context.Background(), "5,0102"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
requireLocations(t, fc.vidMapClient, 5, "live:8080", "old:8080")
|
|
|
|
provider.err = errNoAnswer
|
|
fc.InvalidateCache("5,0102")
|
|
pushVolumeLocation(mc, old.Url, nil, []uint32{5}, nil, nil)
|
|
if _, err := fc.LookupFileIdWithFallback(context.Background(), "5,0102"); err != nil {
|
|
t.Fatalf("lookup after a failed refresh: %v", err)
|
|
}
|
|
requireLocations(t, fc.vidMapClient, 5, "live:8080")
|
|
}
|
|
|
|
// A removal racing refreshes that get no answer: whatever the interleaving,
|
|
// the removed server is gone once both are done. Run with -race.
|
|
func TestPushedRemovalRacingFailedRefreshes(t *testing.T) {
|
|
for i := 0; i < 300; i++ {
|
|
mc := masterClientWith(&stubProvider{err: errNoAnswer})
|
|
pushVolumeLocation(mc, "old:8080", []uint32{5}, nil, nil, nil)
|
|
pushVolumeLocation(mc, "live:8080", []uint32{5}, nil, nil, nil)
|
|
|
|
var wg sync.WaitGroup
|
|
wg.Add(2)
|
|
go func() {
|
|
defer wg.Done()
|
|
for j := 0; j < 10; j++ {
|
|
refresh(mc.vidMapClient)
|
|
}
|
|
}()
|
|
go func() {
|
|
defer wg.Done()
|
|
pushVolumeLocation(mc, "old:8080", nil, []uint32{5}, nil, nil)
|
|
}()
|
|
wg.Wait()
|
|
|
|
refresh(mc.vidMapClient)
|
|
requireLocations(t, mc.vidMapClient, 5, "live:8080")
|
|
}
|
|
}
|
|
|
|
// A pushed add after the invalidation means the volume is being learned
|
|
// again: it replaces what was set aside, in both forms, as it did when the
|
|
// invalidation deleted the entries.
|
|
func TestPushedAddReplacesStaleLocations(t *testing.T) {
|
|
mc := masterClientWith(&stubProvider{err: errNoAnswer})
|
|
pushVolumeLocation(mc, "dead:8080", []uint32{5}, nil, nil, nil)
|
|
pushVolumeLocation(mc, "live:8080", []uint32{5}, nil, nil, nil)
|
|
pushVolumeLocation(mc, "shard:8080", nil, nil, []uint32{5}, nil)
|
|
|
|
mc.InvalidateCache("5,0102")
|
|
pushVolumeLocation(mc, "new:8080", []uint32{5}, nil, nil, nil)
|
|
requireLocations(t, mc.vidMapClient, 5, "new:8080")
|
|
|
|
if mc.vidMap.reviveStale(5) {
|
|
t.Fatal("a stale entry outlived the volume being learned again")
|
|
}
|
|
requireLocations(t, mc.vidMapClient, 5, "new:8080")
|
|
|
|
// The same once a failed refresh has brought the old locations back.
|
|
refresh(mc.vidMapClient)
|
|
requireLocations(t, mc.vidMapClient, 5, "new:8080")
|
|
pushVolumeLocation(mc, "newer:8080", []uint32{5}, nil, nil, nil)
|
|
requireLocations(t, mc.vidMapClient, 5, "newer:8080")
|
|
}
|
|
|
|
// A stale entry follows the map's own rules while it is set aside: it holds
|
|
// no server references, a removal edits it without touching another volume's
|
|
// references, a newer answer drops it revived or not, and a clear or enough
|
|
// resets end it like any other entry.
|
|
func TestStaleEntryLifecycle(t *testing.T) {
|
|
a, b := Location{Url: "a:8080"}, Location{Url: "b:8080"}
|
|
|
|
t.Run("server references", func(t *testing.T) {
|
|
vm := newVidMap("", DefaultVidMapCacheSize)
|
|
vm.addLocation(5, a)
|
|
vm.addEcLocation(5, b)
|
|
vm.addLocation(6, a)
|
|
|
|
vm.markStale(5)
|
|
if !vm.hasVolumeServer("a:8080") || vm.hasVolumeServer("b:8080") {
|
|
t.Fatal("markStale must release volume 5's references and only those")
|
|
}
|
|
vm.deleteLocation(5, a)
|
|
if !vm.hasVolumeServer("a:8080") {
|
|
t.Fatal("a removal from a stale entry released volume 6's reference")
|
|
}
|
|
if !vm.reviveStale(5) {
|
|
t.Fatal("nothing revived")
|
|
}
|
|
if locations, found := vm.GetLocations(5); !found || len(locations) != 1 || locations[0].Url != "b:8080" {
|
|
t.Fatalf("revived %v, want the ec entry on b only", locations)
|
|
}
|
|
if !vm.hasVolumeServer("b:8080") {
|
|
t.Fatal("reviveStale did not take the references back")
|
|
}
|
|
vm.deleteLocation(6, a)
|
|
if vm.hasVolumeServer("a:8080") {
|
|
t.Fatal("a:8080 still referenced after its last volume left")
|
|
}
|
|
})
|
|
|
|
t.Run("superseded", func(t *testing.T) {
|
|
vm := newVidMap("", DefaultVidMapCacheSize)
|
|
vm.addLocation(5, a)
|
|
vm.addLocation(6, b)
|
|
vm.markStale(5)
|
|
vm.reviveStale(5)
|
|
asked := vm.learnedSoFar()
|
|
vm.dropSetAside(5, asked)
|
|
vm.dropSetAside(6, asked)
|
|
if _, found := vm.GetLocations(5); found || vm.hasVolumeServer("a:8080") {
|
|
t.Fatal("a revived entry or its server reference outlived a newer answer")
|
|
}
|
|
if _, found := vm.GetLocations(6); !found {
|
|
t.Fatal("dropSetAside deleted an entry that was learned")
|
|
}
|
|
})
|
|
|
|
t.Run("cleared", func(t *testing.T) {
|
|
vm := newVidMap("", DefaultVidMapCacheSize)
|
|
vm.addLocation(5, a)
|
|
vm.markStale(5)
|
|
vm.clear()
|
|
if vm.reviveStale(5) {
|
|
t.Fatal("revived an entry the clear dropped")
|
|
}
|
|
})
|
|
|
|
t.Run("expired", func(t *testing.T) {
|
|
vm := newVidMap("", 2)
|
|
vm.addLocation(5, a)
|
|
vm.markStale(5)
|
|
for i := 0; i < 3; i++ {
|
|
vm.reset()
|
|
}
|
|
if vm.reviveStale(5) {
|
|
t.Fatal("revived an entry older than the retained generations")
|
|
}
|
|
if vm.hasVolumeServer("a:8080") {
|
|
t.Fatal("expiring a stale entry left a server reference")
|
|
}
|
|
})
|
|
}
|
|
|
|
// 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")
|
|
}
|
|
|
|
// An answer to a lookup asked before the volume was learned again is older
|
|
// than what that learning set aside. When a failed lookup revives those newer
|
|
// locations, the older answer must not delete them.
|
|
func TestOlderAnswerKeepsLocationsLearnedMeanwhile(t *testing.T) {
|
|
provider := &stubProvider{}
|
|
vc := newVidMapClient(provider, "", DefaultVidMapCacheSize)
|
|
provider.answer = func(call int) (map[string][]Location, error) {
|
|
if call > 1 {
|
|
return nil, errNoAnswer
|
|
}
|
|
// While this lookup is in flight, the master confirms new locations,
|
|
// a read invalidates them, and the refresh that follows gets no
|
|
// answer and revives them.
|
|
vc.confirmLocations(5, []Location{{Url: "new:8080"}})
|
|
vc.InvalidateCache("5,0102")
|
|
if _, err := vc.LookupVolumeIdsWithFallback(context.Background(), []string{"5"}); err != nil {
|
|
t.Errorf("overlapping lookup: %v", err)
|
|
}
|
|
return map[string][]Location{"5": {{Url: "old:8080"}}, "6": {{Url: "six:8080"}}}, nil
|
|
}
|
|
|
|
vc.LookupVolumeIdsWithFallback(context.Background(), []string{"5", "6"})
|
|
|
|
requireLocations(t, vc, 5, "new:8080")
|
|
}
|