mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9342ee3778 | ||
|
|
f17314ab51 | ||
|
|
421db36ba2 | ||
|
|
bc9e2ff20e | ||
|
|
6626597e93 | ||
|
|
d4736f27b2 | ||
|
|
08c0a55265 | ||
|
|
ac31753a68 | ||
|
|
ec21b897c9 |
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
Reference in new issue
Block a user