From eb177aed834702966601a5b64caeb9578f481b95 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 11:13:35 -0800 Subject: [PATCH] storage: preserve internal read waits and replace stale hydration --- seaweed-block/core/storage/chunk_hydration.go | 15 +++++++++++---- seaweed-block/core/storage/chunk_layer.go | 8 ++------ seaweed-block/core/storage/walstore.go | 2 -- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/seaweed-block/core/storage/chunk_hydration.go b/seaweed-block/core/storage/chunk_hydration.go index 01e5d97821..2291ea22cc 100644 --- a/seaweed-block/core/storage/chunk_hydration.go +++ b/seaweed-block/core/storage/chunk_hydration.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "time" ) // ErrChunkHydrationPending means no guest bytes were admitted: hydration @@ -13,7 +12,6 @@ var ErrChunkHydrationPending = errors.New("storage: chunk hydration pending") const defaultHydrationWorkers = 2 const defaultHydrationQueueDepth = 64 -const defaultHydrationWait = 4 * time.Second // ChunkHydrationStats separates wait refusals from owned fetch outcomes. // A wait refusal is not necessarily a wire completion (a caller may cancel). @@ -83,6 +81,11 @@ func (l *chunkLayerImpl) OnReadMissContext(ctx context.Context, lba uint64) ([]b stale := f != nil && (f.gen != gen || f.ref != ref) if stale { f.cancel() + // The old worker remains owned and joined, but cannot delay a + // new generation or remove its replacement when it finishes. + delete(l.hydration, idx) + close(f.done) + f = nil } if f != nil && !stale { l.stats.Hydration.Joined++ @@ -185,6 +188,7 @@ func (l *chunkLayerImpl) hydrationWorker() { } } next.running = true + l.stats.Hydration.Active++ l.stats.Hydration.Fetches++ l.wakeHydrationLocked() l.stMu.Unlock() @@ -201,9 +205,12 @@ func (l *chunkLayerImpl) hydrationWorker() { } else if resolved { l.stats.Hydration.Completed++ } + l.stats.Hydration.Active-- next.err = err - delete(l.hydration, next.idx) - close(next.done) + if l.hydration[next.idx] == next { + delete(l.hydration, next.idx) + close(next.done) + } l.wakeHydrationLocked() l.stMu.Unlock() } diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 38fd56c042..a2e6c10709 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -547,9 +547,7 @@ func sortedKeys(m map[uint64]bool) []uint64 { // block that has no newer local version, then lets the store read its // extent. It runs with no walstore lock held. func (l *chunkLayerImpl) OnReadMiss(lba uint64) ([]byte, error) { - ctx, cancel := context.WithTimeout(context.Background(), defaultHydrationWait) - defer cancel() - return l.OnReadMissContext(ctx, lba) + return l.OnReadMissContext(context.Background(), lba) } // fillOnce fetches one chunk version and installs every block that has no @@ -1382,9 +1380,7 @@ func (l *chunkLayerImpl) Stats() chunkLayerStats { out.Hydration.WorkerLimit = l.cfg.HydrationWorkers out.Hydration.QueueDepth = l.cfg.HydrationQueueDepth for _, f := range l.hydration { - if f.running { - out.Hydration.Active++ - } else { + if !f.running { out.Hydration.Queued++ } } diff --git a/seaweed-block/core/storage/walstore.go b/seaweed-block/core/storage/walstore.go index 9b96bcbc6d..12b694b12a 100644 --- a/seaweed-block/core/storage/walstore.go +++ b/seaweed-block/core/storage/walstore.go @@ -1049,8 +1049,6 @@ func (s *WALStore) WriteInstrumentation() WriteInstrumentationStatus { func (s *WALStore) Read(lba uint32) ([]byte, error) { return s.ReadContext(context.Background(), lba) } func (s *WALStore) ReadContext(ctx context.Context, lba uint32) (data []byte, err error) { - ctx, cancel := context.WithTimeout(ctx, defaultHydrationWait) - defer cancel() defer func() { if err == nil && ctx.Err() != nil { data = nil