mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
test: reproduce default attach deadline on a dense manifest
This commit is contained in:
1 parent
30b5177b17
commit
83cdea1502
1 file changed
+133
@@ -0,0 +1,133 @@
|
||||
package durable_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable/testutil"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
// Only segment fetches are delayed: each finishes within its own 30s bound.
|
||||
// The real layout reader decodes every entry and reports completed segments.
|
||||
type pacedAttachFiler struct {
|
||||
chunkstore.Filer
|
||||
delay time.Duration
|
||||
fetched atomic.Int64
|
||||
}
|
||||
|
||||
func (f *pacedAttachFiler) LookupEntry(ctx context.Context, dir, name string) (*filerpb.Entry, error) {
|
||||
if strings.Contains(dir, "/seg/") || strings.HasSuffix(dir, "/seg") {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
case <-time.After(f.delay):
|
||||
}
|
||||
f.fetched.Add(1)
|
||||
}
|
||||
return f.Filer.LookupEntry(ctx, dir, name)
|
||||
}
|
||||
|
||||
// Default (no lease/master-wait callback) startup must read a dense manifest
|
||||
// after assignment even when its total read exceeds the assignment allowance.
|
||||
// Full mode uses the shipped 30s default; short mode compresses only the clock.
|
||||
func TestDefaultAttachAt262144EntriesOutlivesAssignmentWait(t *testing.T) {
|
||||
const entries = 262144
|
||||
ctx := context.Background()
|
||||
fixture := testutil.NewLayoutFixture(t, "v1", entries, 1)
|
||||
f := &pacedAttachFiler{Filer: fixture.Filer, delay: 1200 * time.Millisecond}
|
||||
allowance := 30 * time.Second
|
||||
configured := time.Duration(0)
|
||||
if testing.Short() {
|
||||
allowance, configured, f.delay = 100*time.Millisecond, 100*time.Millisecond, 10*time.Millisecond
|
||||
}
|
||||
cat, err := chunkstore.NewBCatalog(f, fixture.Blobs, "/provider-test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fixture.Catalog = cat
|
||||
st, err := cat.Store(fixture.Ref)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
refs := make(map[uint64]layout.Ref, entries)
|
||||
for i := uint64(0); i < entries; i++ {
|
||||
refs[i] = layout.Ref{Owner: fixture.Ref.Name, OwnerID: fixture.Ref.ID, Chunk: layout.NameChunk(i, []byte("payload"))}
|
||||
}
|
||||
root, segments, err := layout.Build(refs)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rn, raw, err := layout.NameRoot(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for name, b := range segments {
|
||||
if err := st.Create(ctx, name.Path(), b, "fixture"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := st.Create(ctx, rn.Path(), raw, "fixture"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
head, found, err := st.ReadHead(ctx)
|
||||
if err != nil || !found {
|
||||
t.Fatalf("fixture HEAD: found=%v err=%v", found, err)
|
||||
}
|
||||
head.Current = &rn
|
||||
if err := st.UpdateHead(ctx, head.Gen, head, layout.CauseCommit); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v := &arrivingAssignment{seen: make(chan struct{}), assigned: make(chan struct{})}
|
||||
var completed atomic.Uint64
|
||||
cfg := durable.ProviderConfig{Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), NumBlocks: entries, BlockSize: 4096, ChunkBlocks: 1, ChunkAssignmentTimeout: configured,
|
||||
RecoveryProgress: func(phase storage.RecoveryPhase, done uint64) {
|
||||
if phase == storage.RecoveryAttach {
|
||||
completed.Store(done)
|
||||
}
|
||||
},
|
||||
}
|
||||
fixture.Configure(&cfg)
|
||||
p, err := durable.NewDurableProvider(cfg, v)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer p.Close()
|
||||
if _, err := p.EnsureStorage("v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v.active.Store(true)
|
||||
if _, err := p.RecoverVolume(ctx, "v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
start := time.Now()
|
||||
close(v.assigned)
|
||||
deadline := start.Add(allowance + 30*time.Second)
|
||||
for {
|
||||
statuses := p.DurableStatuses()
|
||||
if len(statuses) == 1 && statuses[0].Operational {
|
||||
break
|
||||
}
|
||||
if _, failed := p.ChunkStartupOutcome("v1"); failed {
|
||||
t.Fatalf("default attach expired after %s: %+v; segments=%d progress=%d", time.Since(start), statuses, f.fetched.Load(), completed.Load())
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("attach never served: %+v", statuses)
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
if elapsed := time.Since(start); elapsed <= allowance {
|
||||
t.Fatalf("fixture did not cross assignment allowance: %s <= %s", elapsed, allowance)
|
||||
}
|
||||
if f.fetched.Load() != int64(len(segments)) || completed.Load() < entries {
|
||||
t.Fatalf("incomplete manifest: fetched=%d/%d progress=%d", f.fetched.Load(), len(segments), completed.Load())
|
||||
}
|
||||
t.Logf("default attach served after %s, allowance=%s segments=%d entries=%d progress=%d", time.Since(start), allowance, f.fetched.Load(), entries, completed.Load())
|
||||
}
|
||||
Reference in new issue
Block a user