mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
test: F1 watches heartbeat health: slot expiries, their effects, superseded lines
V1-SPEC r2.53. The rung polls the master's view of every source volume's replica each second (GetVolumeStatus) and records each span the master does not observe it, epoch changes and frontend-not-ready polls; it counts the master's per-slot "heartbeat superseded" lines per volume. Pass rule: zero slot expiries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
57432c20da
commit
1f757bb78b
2 files changed
+159
-3
No files matched your search
@@ -0,0 +1,148 @@
|
||||
//go:build subprocess && chunkstore_integration
|
||||
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"github.com/seaweedfs/seaweed-block/core/rpc/link"
|
||||
)
|
||||
|
||||
// Rung F1's heartbeat-ordering watch (V1-SPEC r2.53): with N processes under
|
||||
// one server id, a volume's slot at the master can expire when its
|
||||
// heartbeats are dropped. The watch polls the master's view of every source
|
||||
// volume's replica each second and records each span where the master does
|
||||
// not observe it (a slot expiry), and what the volume shows meanwhile: an
|
||||
// epoch change or its frontend leaving ready. At the end it counts the
|
||||
// master's per-slot superseded lines for the volume ('blockmaster:
|
||||
// heartbeat superseded ... volume=<v> ...'; 0 where the master does not log
|
||||
// them).
|
||||
|
||||
// f1Health is one source volume's record over the whole run.
|
||||
type f1Health struct {
|
||||
Volume string `json:"volume"`
|
||||
Replica string `json:"replica"`
|
||||
Polls int `json:"polls"`
|
||||
PollErrors int `json:"poll_errors"`
|
||||
SlotExpiries int `json:"slot_expiries"`
|
||||
SlotUnobservedMs float64 `json:"slot_unobserved_ms"`
|
||||
EpochChanges int `json:"epoch_changes"`
|
||||
FrontendNotReady int `json:"frontend_not_ready_polls"`
|
||||
DuringExpiry []string `json:"during_expiry,omitempty"`
|
||||
SupersededLogLines int `json:"master_superseded_lines"`
|
||||
}
|
||||
|
||||
type f1Watch struct {
|
||||
stop chan struct{}
|
||||
done chan struct{}
|
||||
mu sync.Mutex
|
||||
vols map[string]*f1Health
|
||||
}
|
||||
|
||||
// f1StartWatch starts polling the master for every source volume.
|
||||
func f1StartWatch(env *handoffEnv, vols []f1Volume) *f1Watch {
|
||||
w := &f1Watch{stop: make(chan struct{}), done: make(chan struct{}), vols: map[string]*f1Health{}}
|
||||
for _, v := range vols {
|
||||
w.vols[v.id] = &f1Health{Volume: v.id, Replica: env.hosts[v.node].replica}
|
||||
}
|
||||
go func() {
|
||||
defer close(w.done)
|
||||
conn, err := link.Dial(env.h.masterAddr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
cl := control.NewClusterEvidenceServiceClient(conn)
|
||||
type state struct {
|
||||
unobservedSince time.Time
|
||||
epoch uint64
|
||||
}
|
||||
st := map[string]*state{}
|
||||
t := time.NewTicker(time.Second)
|
||||
defer t.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-w.stop:
|
||||
return
|
||||
case <-t.C:
|
||||
}
|
||||
for _, v := range vols {
|
||||
h, s := w.vols[v.id], st[v.id]
|
||||
if s == nil {
|
||||
s = &state{}
|
||||
st[v.id] = s
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
ev, err := cl.GetVolumeStatus(ctx, &control.GetVolumeStatusRequest{VolumeId: v.id})
|
||||
cancel()
|
||||
w.mu.Lock()
|
||||
h.Polls++
|
||||
if err != nil {
|
||||
h.PollErrors++
|
||||
w.mu.Unlock()
|
||||
continue
|
||||
}
|
||||
observed := false
|
||||
for _, r := range ev.GetReplicas() {
|
||||
if r.GetReplicaId() == h.Replica && r.GetObserved() {
|
||||
observed = true
|
||||
}
|
||||
}
|
||||
now := time.Now()
|
||||
switch {
|
||||
case !observed && s.unobservedSince.IsZero():
|
||||
s.unobservedSince = now
|
||||
h.SlotExpiries++
|
||||
case observed && !s.unobservedSince.IsZero():
|
||||
h.SlotUnobservedMs += ms(now.Sub(s.unobservedSince))
|
||||
s.unobservedSince = time.Time{}
|
||||
}
|
||||
if e := ev.GetEpoch(); s.epoch != 0 && e != s.epoch {
|
||||
h.EpochChanges++
|
||||
if !s.unobservedSince.IsZero() {
|
||||
h.DuringExpiry = append(h.DuringExpiry, fmt.Sprintf("epoch %d -> %d", s.epoch, e))
|
||||
}
|
||||
}
|
||||
s.epoch = ev.GetEpoch()
|
||||
w.mu.Unlock()
|
||||
ready := volumeFrontendReady(env.hosts[v.node].status, v.id)
|
||||
w.mu.Lock()
|
||||
if !ready {
|
||||
h.FrontendNotReady++
|
||||
if !s.unobservedSince.IsZero() {
|
||||
h.DuringExpiry = append(h.DuringExpiry, "frontend not ready at "+now.UTC().Format(time.RFC3339))
|
||||
}
|
||||
}
|
||||
w.mu.Unlock()
|
||||
}
|
||||
}
|
||||
}()
|
||||
return w
|
||||
}
|
||||
|
||||
// finish stops the watch and counts the master's superseded lines per
|
||||
// volume from its log.
|
||||
func (w *f1Watch) finish(masterLog string) []f1Health {
|
||||
close(w.stop)
|
||||
<-w.done
|
||||
b, _ := os.ReadFile(masterLog)
|
||||
lines := strings.Split(string(b), "\n")
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
var out []f1Health
|
||||
for _, h := range w.vols {
|
||||
for _, l := range lines {
|
||||
if strings.Contains(l, "heartbeat superseded") && strings.Contains(l, " volume="+h.Volume+" ") {
|
||||
h.SupersededLogLines++
|
||||
}
|
||||
}
|
||||
out = append(out, *h)
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -124,6 +124,7 @@ type f1Report struct {
|
||||
Limiter string `json:"limiter"`
|
||||
StartedAt time.Time `json:"started_at"`
|
||||
Rounds []f1Round `json:"rounds"`
|
||||
Health []f1Health `json:"heartbeat_health"`
|
||||
CommitBound float64 `json:"commit_bound_ms"`
|
||||
WriteErrors int `json:"write_errors"`
|
||||
Verdict string `json:"verdict"`
|
||||
@@ -133,7 +134,7 @@ type f1Report struct {
|
||||
func TestSnapshotLadderF1VolumesOneHost(t *testing.T) {
|
||||
cfg := f1ConfigFromEnv(t)
|
||||
rep := &f1Report{Config: cfg, StartedAt: time.Now().UTC(), Limiter: "off"}
|
||||
env := f1StartEnv(t, cfg)
|
||||
env, master := f1StartEnv(t, cfg)
|
||||
env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"}
|
||||
if cfg.HostLimitDir != "" {
|
||||
env.volExtra = append(env.volExtra, "--host-limit-dir", cfg.HostLimitDir, "--host-limit-normal-slots", strconv.Itoa(cfg.Slots))
|
||||
@@ -141,6 +142,7 @@ func TestSnapshotLadderF1VolumesOneHost(t *testing.T) {
|
||||
}
|
||||
vols := f1StartSources(t, env, cfg.Volumes)
|
||||
defer f1WriteReport(t, cfg, rep)
|
||||
watch := f1StartWatch(env, vols)
|
||||
|
||||
for round := 1; round <= cfg.Rounds; round++ {
|
||||
before := f1FilerEntries(t, env)
|
||||
@@ -152,6 +154,7 @@ func TestSnapshotLadderF1VolumesOneHost(t *testing.T) {
|
||||
}
|
||||
rep.Rounds = append(rep.Rounds, rounds...)
|
||||
}
|
||||
rep.Health = watch.finish(master.log)
|
||||
f1Judge(t, cfg, rep)
|
||||
}
|
||||
|
||||
@@ -163,7 +166,7 @@ func f1RestoreTarget(vol, round int) string { return fmt.Sprintf("v%dr%d", vol,
|
||||
// ports. Source v<i> is replica r<i>; the restore target of v<i> in round k
|
||||
// is replica r<i+N*k> on the same server. The node record carries the first
|
||||
// source's pair, as the deployment page writes one node.
|
||||
func f1StartEnv(t *testing.T, cfg f1Config) *handoffEnv {
|
||||
func f1StartEnv(t *testing.T, cfg f1Config) (*handoffEnv, *daemon) {
|
||||
t.Helper()
|
||||
h := newPlannedHandoffHarness(t)
|
||||
env := &handoffEnv{h: h, cluster: startWorkspaceWeed(t), chunkPath: fmt.Sprintf("/f1-%d", time.Now().UnixNano()), hosts: map[string]bvHost{}}
|
||||
@@ -202,7 +205,7 @@ func f1StartEnv(t *testing.T, cfg f1Config) *handoffEnv {
|
||||
"--cluster-spec", spec, "--expected-slots-per-volume", "1", "--listen", h.masterAddr,
|
||||
"--workspace-rpc", "--workspace-head-base-url", "http://"+env.cluster.filerHTTP+env.chunkPath)
|
||||
master.waitLog(t, 30*time.Second, "blockmaster: lock acquired, reloaded=")
|
||||
return env
|
||||
return env, master
|
||||
}
|
||||
|
||||
// f1Up starts the blockvolume of key and waits for its volume to be primary
|
||||
@@ -567,6 +570,11 @@ func f1Judge(t *testing.T, cfg f1Config, rep *f1Report) {
|
||||
waves = math.Ceil(float64(cfg.Volumes)/float64(cfg.Slots)) + 1
|
||||
}
|
||||
rep.CommitBound = waves * worst
|
||||
for _, h := range rep.Health {
|
||||
if h.SlotExpiries > 0 {
|
||||
rep.Failures = append(rep.Failures, fmt.Sprintf("%s: the master lost its slot %d time(s) for %.0f ms in total (during: %v)", h.Volume, h.SlotExpiries, h.SlotUnobservedMs, h.DuringExpiry))
|
||||
}
|
||||
}
|
||||
if longest > rep.CommitBound {
|
||||
rep.Failures = append(rep.Failures, fmt.Sprintf("a snapshot took %.0f ms, above the bound %.0f ms (%.0f waves x the slowest cut %.0f ms): a volume starved", longest, rep.CommitBound, waves, worst))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user