mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
test(block): pin retirement recovery and complete slow-pass evidence
This commit is contained in:
1 parent
a865bdf4d0
commit
b098ac3a0e
2 files changed
+64
-13
No files matched your search
@@ -97,8 +97,11 @@ func TestRetirementWorkerServingWithOneHundredSlowHeads(t *testing.T) {
|
||||
cfg := original.cfg
|
||||
closeTestMaster(t, original)
|
||||
entered := make(chan struct{}, 1)
|
||||
completed := make(chan string, len(ids))
|
||||
logs := &syncBuffer{}
|
||||
cfg.Logger = log.New(logs, "", 0)
|
||||
var active, maximum atomic.Int32
|
||||
cfg.LayoutReadHead = func(ctx context.Context, _ lifecycle.VolumeSpec) (layout.Head, error) {
|
||||
cfg.LayoutReadHead = func(ctx context.Context, spec lifecycle.VolumeSpec) (layout.Head, error) {
|
||||
n := active.Add(1)
|
||||
defer active.Add(-1)
|
||||
for old := maximum.Load(); n > old && !maximum.CompareAndSwap(old, n); old = maximum.Load() {
|
||||
@@ -115,6 +118,7 @@ func TestRetirementWorkerServingWithOneHundredSlowHeads(t *testing.T) {
|
||||
defer timer.Stop()
|
||||
select {
|
||||
case <-timer.C:
|
||||
completed <- spec.VolumeID
|
||||
return layout.Head{State: layout.StateDeleted}, nil
|
||||
case <-ctx.Done():
|
||||
return layout.Head{}, ctx.Err()
|
||||
@@ -159,6 +163,32 @@ func TestRetirementWorkerServingWithOneHundredSlowHeads(t *testing.T) {
|
||||
case <-ctx.Done():
|
||||
t.Fatal("product tick waits for retirement read")
|
||||
}
|
||||
if !held {
|
||||
// Complete the entire ten-second pass: serving early alone would
|
||||
// miss a one-read budget or a five-second total cap on the scan.
|
||||
passDeadline := time.Now().Add(15 * time.Second)
|
||||
want := "eligible=100 reads=100 timeouts=0 retired=0"
|
||||
for !strings.Contains(logs.String(), want) && time.Now().Before(passDeadline) {
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
if !strings.Contains(logs.String(), want) || !strings.Contains(logs.String(), "kept_by_spec:100") || strings.Count(logs.String(), "deletion retirement pass") != 2 {
|
||||
t.Fatalf("one full pass did not finish with all counters: %s", logs.String())
|
||||
}
|
||||
if elapsed := time.Since(started); elapsed <= 5*time.Second {
|
||||
t.Fatalf("slow pass took %s, must cross the per-call five-second bound", elapsed)
|
||||
}
|
||||
for _, id := range ids {
|
||||
select {
|
||||
case got := <-completed:
|
||||
if got != id {
|
||||
t.Fatalf("completed visit=%s, want %s", got, id)
|
||||
}
|
||||
default:
|
||||
t.Fatalf("no completed visit for %s", id)
|
||||
}
|
||||
}
|
||||
t.Logf("completed one pass across all %d records through %s in %s; %s", len(ids), ids[len(ids)-1], time.Since(started), want)
|
||||
}
|
||||
closeTestMaster(t, h) // child bounds cancellation and all joins
|
||||
if active.Load() != 0 || maximum.Load() != 1 {
|
||||
t.Fatalf("background reads active=%d max=%d", active.Load(), maximum.Load())
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -163,6 +164,9 @@ func TestSpecRetirementDoesNotUseAbsentHeadWithoutReservation(t *testing.T) {
|
||||
// Stop precisely after durable authority retirement and before deleting the
|
||||
// lifecycle tail; a distinct Host must reconstruct the permanent exclusion.
|
||||
func TestSpecRetirementFreshHostFinishesHalfRetiredTail(t *testing.T) {
|
||||
if !retirementWorkerChild(t) {
|
||||
return
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("Linux lifecycle/authority directory fsync durability witness")
|
||||
}
|
||||
@@ -191,18 +195,12 @@ func TestSpecRetirementFreshHostFinishesHalfRetiredTail(t *testing.T) {
|
||||
WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) {
|
||||
return authority.WorkspaceHead{}, authority.ErrWorkspaceHeadUnclaimed
|
||||
},
|
||||
LayoutReadHead: func(_ context.Context, spec lifecycle.VolumeSpec) (layout.Head, error) {
|
||||
if spec.VolumeID != "gone" {
|
||||
t.Errorf("read unreserved live HEAD %s", spec.VolumeID)
|
||||
}
|
||||
return layout.Head{State: layout.StateDeleted}, nil
|
||||
},
|
||||
}
|
||||
first, err := New(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
first.Start()
|
||||
first.Start() // no retirement reader during fixture preparation
|
||||
firstClosed := false
|
||||
t.Cleanup(func() {
|
||||
if !firstClosed {
|
||||
@@ -243,13 +241,32 @@ func TestSpecRetirementFreshHostFinishesHalfRetiredTail(t *testing.T) {
|
||||
}
|
||||
closeTestMaster(t, first)
|
||||
firstClosed = true
|
||||
// Hold the first post-start read until recovery and RPC exclusions are checked.
|
||||
entered, release := make(chan struct{}, 1), make(chan struct{})
|
||||
releaseRead := sync.OnceFunc(func() { close(release) })
|
||||
cfg.LayoutReadHead = func(readCtx context.Context, spec lifecycle.VolumeSpec) (layout.Head, error) {
|
||||
if spec.VolumeID != "gone" {
|
||||
t.Errorf("read unreserved live HEAD %s", spec.VolumeID)
|
||||
}
|
||||
select {
|
||||
case entered <- struct{}{}:
|
||||
case <-readCtx.Done():
|
||||
return layout.Head{}, readCtx.Err()
|
||||
}
|
||||
select {
|
||||
case <-release:
|
||||
return layout.Head{State: layout.StateDeleted}, nil
|
||||
case <-readCtx.Done():
|
||||
return layout.Head{}, readCtx.Err()
|
||||
}
|
||||
}
|
||||
fresh, err := New(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fresh.specDesired = map[string]bool{"live": true}
|
||||
fresh.Start()
|
||||
t.Cleanup(func() { closeTestMaster(t, fresh) })
|
||||
t.Cleanup(releaseRead)
|
||||
// Tombstone recovery happens in New, before any serving/reconcile.
|
||||
if _, ok := fresh.Publisher().VolumeAuthorityLine("gone"); ok {
|
||||
t.Fatal("fresh Host restored removed authority")
|
||||
@@ -271,6 +288,12 @@ func TestSpecRetirementFreshHostFinishesHalfRetiredTail(t *testing.T) {
|
||||
t.Fatalf("binding %s missing before reconcile: %v", id, err)
|
||||
}
|
||||
}
|
||||
fresh.Start()
|
||||
select {
|
||||
case <-entered:
|
||||
case <-ctx.Done():
|
||||
t.Fatal("fresh worker did not enter the gated HEAD read")
|
||||
}
|
||||
conn, err := grpc.NewClient(fresh.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -288,6 +311,7 @@ func TestSpecRetirementFreshHostFinishesHalfRetiredTail(t *testing.T) {
|
||||
}
|
||||
}
|
||||
assertExcluded()
|
||||
releaseRead()
|
||||
for i := 0; i < 2; i++ {
|
||||
if err := fresh.ReconcileDeletedSpecVolumes(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -386,9 +410,7 @@ func TestSpecRetirementBackgroundBoundsReadsAndCachesTerminalProof(t *testing.T)
|
||||
t.Fatalf("one background pass made %d remote reads", after-before)
|
||||
}
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
tick(at)
|
||||
}
|
||||
tick(at) // one pass must visit every due record, not one record per pass
|
||||
if reads["a"] != 1 || reads["b"] != 1 || reads["c"] != 1 {
|
||||
t.Fatalf("scan starved a volume: %v", reads)
|
||||
}
|
||||
@@ -400,7 +422,6 @@ func TestSpecRetirementBackgroundBoundsReadsAndCachesTerminalProof(t *testing.T)
|
||||
}
|
||||
later := at.Add(h.cfg.Freshness.EffectiveFreshnessWindow())
|
||||
tick(later)
|
||||
tick(later)
|
||||
if reads["a"] != 1 || reads["b"] != 2 || reads["c"] != 2 {
|
||||
t.Fatalf("terminal proof repolled or due retry starved: %v", reads)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user