mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
master: one status snapshot reconciles the grant waits at a time
The waiting set and its first-seen times are computed and reconciled under one lock, so a concurrent snapshot never drops an entry another just started (its wait would restart). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9f5988d03f
commit
d16bd533d5
3 files changed
+32
-13
No files matched your search
@@ -196,6 +196,13 @@ type grantWaitEntry struct {
|
||||
func (h *Host) grantWaits(placements []lifecycle.PlacementIntent, now time.Time) map[string][]grantWaitEntry {
|
||||
out := map[string][]grantWaitEntry{}
|
||||
live := map[string]bool{}
|
||||
// One snapshot at a time computes the set and reconciles against it, so
|
||||
// a concurrent snapshot never drops an entry this one just started.
|
||||
h.grantWaitMu.Lock()
|
||||
defer h.grantWaitMu.Unlock()
|
||||
if h.grantWait == nil {
|
||||
h.grantWait = map[string]time.Time{}
|
||||
}
|
||||
if h.formatLevel() > 0 {
|
||||
window := h.grantStartupWindow()
|
||||
for _, p := range placements {
|
||||
@@ -211,18 +218,21 @@ func (h *Host) grantWaits(placements []lifecycle.PlacementIntent, now time.Time)
|
||||
}
|
||||
key := slot.ServerID + "\x00" + p.VolumeID
|
||||
live[key] = true
|
||||
v, _ := h.grantWait.LoadOrStore(key, now)
|
||||
waited := now.Sub(v.(time.Time))
|
||||
first, seen := h.grantWait[key]
|
||||
if !seen {
|
||||
first = now
|
||||
h.grantWait[key] = now
|
||||
}
|
||||
waited := now.Sub(first)
|
||||
out[slot.ServerID] = append(out[slot.ServerID], grantWaitEntry{volume: p.VolumeID, waited: waited, late: waited > window})
|
||||
}
|
||||
}
|
||||
}
|
||||
h.grantWait.Range(func(k, _ any) bool {
|
||||
if !live[k.(string)] {
|
||||
h.grantWait.Delete(k)
|
||||
for k := range h.grantWait {
|
||||
if !live[k] {
|
||||
delete(h.grantWait, k)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
for server := range out {
|
||||
sort.Slice(out[server], func(i, j int) bool { return out[server][i].volume < out[server][j].volume })
|
||||
}
|
||||
|
||||
@@ -289,10 +289,18 @@ func TestGrantWaitsAreReconciledPerServerAndVolume(t *testing.T) {
|
||||
if c, ok := cond(late, "node-c"); ok {
|
||||
t.Fatalf("node-c after vc's process reported: %+v; want no wait", c)
|
||||
}
|
||||
if _, kept := r.m.grantWait.Load("node-c\x00vc"); kept {
|
||||
if kept := r.m.grantWaitKept("node-c\x00vc"); kept {
|
||||
t.Fatal("vc's wait timer outlived its process's report")
|
||||
}
|
||||
if _, kept := r.m.grantWait.Load("node-b\x00vb"); !kept {
|
||||
if kept := r.m.grantWaitKept("node-b\x00vb"); !kept {
|
||||
t.Fatal("vb's wait timer was dropped by another node's reconcile")
|
||||
}
|
||||
}
|
||||
|
||||
// grantWaitKept reports whether the master holds a first-seen time for key.
|
||||
func (h *Host) grantWaitKept(key string) bool {
|
||||
h.grantWaitMu.Lock()
|
||||
defer h.grantWaitMu.Unlock()
|
||||
_, ok := h.grantWait[key]
|
||||
return ok
|
||||
}
|
||||
@@ -152,10 +152,11 @@ type Host struct {
|
||||
statusLn net.Listener␍
|
||||
statusHTTP *http.Server␍
|
||||
journal *journalIsolation␍
|
||||
reads *readsLevels // each server's reported format read level (format_gate.go)␍
|
||||
grantWait sync.Map // "server\x00volume" -> time.Time: first seen waiting for its grant without its process's report (format_gate.go grantWaits)␍
|
||||
format formatLevelState // the cluster's format level (format_gate.go)␍
|
||||
finalizeMu sync.Mutex // serializes the format finalize and host retires (format_gate.go)␍
|
||||
reads *readsLevels // each server's reported format read level (format_gate.go)␍
|
||||
grantWaitMu sync.Mutex // one status snapshot reconciles grantWait at a time
|
||||
grantWait map[string]time.Time // "server\x00volume" -> first seen waiting for its grant without its process's report (format_gate.go grantWaits)␍
|
||||
format formatLevelState // the cluster's format level (format_gate.go)␍
|
||||
finalizeMu sync.Mutex // serializes the format finalize and host retires (format_gate.go)␍
|
||||
// testPublicationAdmission, when a test sets it before Start, wraps each␍
|
||||
// publication admission: next runs the admission itself.␍
|
||||
testPublicationAdmission func(ask authority.AssignmentAsk, next func() error) error␍
|
||||
|
||||
Reference in new issue
Block a user