mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
test read command arrival and shared hydration lifetime
This commit is contained in:
1 parent
39aca2daee
commit
5aea1eaf8b
3 files changed
+115
-1
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package durable_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
@@ -12,6 +13,68 @@ import (
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
type pacedHydrationRemote struct {
|
||||
storage.ChunkRemote
|
||||
gets atomic.Int64
|
||||
second chan struct{}
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
func (r *pacedHydrationRemote) release() { r.once.Do(func() { close(r.second) }) }
|
||||
func (r *pacedHydrationRemote) Get(ctx context.Context, key string) ([]byte, error) {
|
||||
if r.gets.Add(1) == 1 {
|
||||
timer := time.NewTimer(120 * time.Millisecond)
|
||||
defer timer.Stop()
|
||||
select {
|
||||
case <-timer.C:
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
} else {
|
||||
select {
|
||||
case <-r.second:
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
}
|
||||
return r.ChunkRemote.Get(ctx, key)
|
||||
}
|
||||
|
||||
func TestDurableHydration_MultipleChunksShareOneDeadline(t *testing.T) {
|
||||
r := &pacedHydrationRemote{ChunkRemote: seededRemote(t), second: make(chan struct{})}
|
||||
p := chunkProvider(t, t.TempDir(), r, v1View(), 0)
|
||||
t.Cleanup(r.release)
|
||||
openRecovered(t, p)
|
||||
b, err := p.Open(context.Background(), "v1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 220*time.Millisecond)
|
||||
defer cancel()
|
||||
start := time.Now()
|
||||
buf := make([]byte, (101-33)*4096)
|
||||
n, err := b.Read(ctx, 33*4096, buf)
|
||||
if !errors.Is(err, frontend.ErrBackendBusy) || !errors.Is(err, context.DeadlineExceeded) || n != (96-33)*4096 {
|
||||
t.Fatalf("shared deadline n=%d err=%v gets=%d", n, err, r.gets.Load())
|
||||
}
|
||||
if elapsed := time.Since(start); elapsed >= 450*time.Millisecond {
|
||||
t.Fatalf("read budget renewed: %s", elapsed)
|
||||
}
|
||||
if !bytes.Equal(buf[:4096], block(0x33)) {
|
||||
t.Fatal("first chunk prefix changed")
|
||||
}
|
||||
r.release()
|
||||
ctx2, cancel2 := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel2()
|
||||
last := make([]byte, 4096)
|
||||
if n, err := b.Read(ctx2, 100*4096, last); n != 4096 || err != nil || !bytes.Equal(last, block(0x64)) {
|
||||
t.Fatalf("shared work after timeout: n=%d err=%v", n, err)
|
||||
}
|
||||
if r.gets.Load() != 2 {
|
||||
t.Fatalf("retry restarted shared fetch: %d", r.gets.Load())
|
||||
}
|
||||
}
|
||||
|
||||
type heldHydrationRemote struct {
|
||||
storage.ChunkRemote
|
||||
gate chan struct{}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package nvme
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/testback"
|
||||
)
|
||||
|
||||
type budgetReadBackend struct {
|
||||
frontend.Backend
|
||||
deadline time.Time
|
||||
physical bool
|
||||
}
|
||||
|
||||
func (b *budgetReadBackend) Read(ctx context.Context, _ int64, p []byte) (int, error) {
|
||||
b.deadline, _ = ctx.Deadline()
|
||||
<-ctx.Done()
|
||||
if b.physical {
|
||||
return 0, errors.Join(ctx.Err(), errors.New("physical read failure"))
|
||||
}
|
||||
return 0, frontend.ErrBackendBusy
|
||||
}
|
||||
|
||||
func TestSessionReadBudgetIncludesQueueResidence(t *testing.T) {
|
||||
for _, physical := range []bool{false, true} {
|
||||
b := &budgetReadBackend{Backend: testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1"}), physical: physical}
|
||||
s := &Session{handler: NewIOHandler(HandlerConfig{Backend: b}), respCh: make(chan *response, 1), done: make(chan struct{})}
|
||||
arrival := time.Now().Add(-5 * time.Second)
|
||||
req := &Request{receivedAt: arrival, dispatchReadyAt: time.Now()}
|
||||
req.capsule.OpCode, req.capsule.NSID = ioRead, 1
|
||||
s.handleRead(context.Background(), req)
|
||||
resp := <-s.respCh
|
||||
want := MakeStatusField(SCTGeneric, SCNamespaceNotReady, false)
|
||||
if physical {
|
||||
want = MakeStatusField(SCTGeneric, SCInternalError, true)
|
||||
}
|
||||
if !b.deadline.Equal(arrival.Add(frontend.ReadCommandBudget)) || resp.resp.Status != want || len(resp.c2hData) != 0 {
|
||||
t.Fatalf("physical=%t deadline=%v status=%#x data=%d", physical, b.deadline, resp.resp.Status, len(resp.c2hData))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,6 +129,12 @@ func TestChunkLayer_StaleFillCannotInstallAfterReEviction(t *testing.T) {
|
||||
}
|
||||
|
||||
held, releaseA := holdNextGet(t, f)
|
||||
// Schedule an old-generation physical fill directly. Guest readers now
|
||||
// share one flight, so two guest reads cannot create this overlap.
|
||||
impl := layer.(*chunkLayerImpl)
|
||||
impl.stMu.Lock()
|
||||
oldGen, oldRef := impl.absentGen[2], impl.head.Chunks[2]
|
||||
impl.stMu.Unlock()
|
||||
readA := make(chan error, 1)
|
||||
joinedA := make(chan struct{})
|
||||
t.Cleanup(func() {
|
||||
@@ -141,7 +147,7 @@ func TestChunkLayer_StaleFillCannotInstallAfterReEviction(t *testing.T) {
|
||||
})
|
||||
go func() {
|
||||
defer close(joinedA)
|
||||
_, err := s.Read(8)
|
||||
_, err := impl.fillOnce(ctTimeout(t), 2, oldGen, oldRef)
|
||||
readA <- err
|
||||
}()
|
||||
waitKey(t, held, "fetch A")
|
||||
|
||||
Reference in new issue
Block a user