diff --git a/seaweed-block/cmd/blockvolume/chunk_remote.go b/seaweed-block/cmd/blockvolume/chunk_remote.go index 48015840f1..c8b7ce0c1c 100644 --- a/seaweed-block/cmd/blockvolume/chunk_remote.go +++ b/seaweed-block/cmd/blockvolume/chunk_remote.go @@ -29,13 +29,15 @@ const ( ) type chunkFlags struct { - filer string - path string - collection string - replication string - captureInterval time.Duration - dirtyThreshold int - uploadConcurrency int + filer string + path string + collection string + replication string + captureInterval time.Duration + dirtyThreshold int + uploadConcurrency int + hydrationWorkers int + hydrationQueueDepth int // controlEndpoint mounts the /chunk/* routes on the status listener. controlEndpoint bool } @@ -45,7 +47,7 @@ func validateChunkFlags(f flags) error { if f.durableImpl != "walstore-chunk" { if c.filer != "" || c.collection != "" || c.replication != "" || c.path != defaultChunkPath || c.captureInterval != defaultChunkCaptureInterval || c.dirtyThreshold != defaultChunkDirtyThreshold || - c.uploadConcurrency != 8 || c.controlEndpoint { + c.uploadConcurrency != 8 || c.hydrationWorkers != 2 || c.hydrationQueueDepth != 64 || c.controlEndpoint { return errors.New("--chunk-* flags require --durable-impl=walstore-chunk") } return nil @@ -71,6 +73,12 @@ func validateChunkFlags(f flags) error { if c.uploadConcurrency < 1 || c.uploadConcurrency > 64 { return errors.New("--chunk-upload-concurrency must be between 1 and 64") } + if c.hydrationWorkers < 1 || c.hydrationWorkers > 64 { + return errors.New("--chunk-hydration-workers must be between 1 and 64") + } + if c.hydrationQueueDepth < 1 || c.hydrationQueueDepth > 65536 { + return errors.New("--chunk-hydration-queue-depth must be between 1 and 65536") + } if c.dirtyThreshold < 0 { return fmt.Errorf("--chunk-dirty-threshold=%d must not be negative", c.dirtyThreshold) } diff --git a/seaweed-block/cmd/blockvolume/hydration_flags_test.go b/seaweed-block/cmd/blockvolume/hydration_flags_test.go index a7cd51d2fd..6d37a85eb7 100644 --- a/seaweed-block/cmd/blockvolume/hydration_flags_test.go +++ b/seaweed-block/cmd/blockvolume/hydration_flags_test.go @@ -4,8 +4,9 @@ import "testing" func TestChunkHydrationFlagsAreConfigurable(t *testing.T) { base := append(phase150RequiredBlockvolumeArgs(), "--durable-root=hydration-test", "--durable-impl=walstore-chunk", "--chunk-filer=x:1") - if _, err := parseFlags(append(base, "--chunk-hydration-workers=3", "--chunk-hydration-queue-depth=17")); err != nil { - t.Fatalf("valid hydration limits refused: %v", err) + f, err := parseFlags(append(base, "--chunk-hydration-workers=3", "--chunk-hydration-queue-depth=17")) + if err != nil || f.chunk.hydrationWorkers != 3 || f.chunk.hydrationQueueDepth != 17 { + t.Fatalf("hydration limits: %+v err=%v", f.chunk, err) } for _, flag := range []string{"--chunk-hydration-workers=0", "--chunk-hydration-workers=65", "--chunk-hydration-queue-depth=0", "--chunk-hydration-queue-depth=65537"} { if _, err := parseFlags(append(base, flag)); err == nil { diff --git a/seaweed-block/cmd/blockvolume/main.go b/seaweed-block/cmd/blockvolume/main.go index 62a2f09d92..2516140cb2 100644 --- a/seaweed-block/cmd/blockvolume/main.go +++ b/seaweed-block/cmd/blockvolume/main.go @@ -194,6 +194,8 @@ func parseFlags(args []string) (flags, error) { fs.StringVar(&f.chunk.replication, "chunk-replication", "", "walstore-chunk: replication for chunk needles (empty = filer default / storage rule)") fs.DurationVar(&f.chunk.captureInterval, "chunk-capture-interval", defaultChunkCaptureInterval, "walstore-chunk: automatic cut once this long has passed since the last successful cut; 0 (default) disables the timer, e.g. 15m as a host-loss safety net") fs.IntVar(&f.chunk.uploadConcurrency, "chunk-upload-concurrency", 8, "walstore-chunk: maximum concurrent dirty-chunk uploads (1..64)") + fs.IntVar(&f.chunk.hydrationWorkers, "chunk-hydration-workers", 2, "walstore-chunk: concurrent lazy chunk fetches per volume (1..64)") + fs.IntVar(&f.chunk.hydrationQueueDepth, "chunk-hydration-queue-depth", 64, "walstore-chunk: distinct queued/in-flight hydration chunks per volume (1..65536)") fs.IntVar(&f.chunk.dirtyThreshold, "chunk-dirty-threshold", defaultChunkDirtyThreshold, "walstore-chunk: number of candidate chunks above which a cut pre-copies (stages) chunks before its barrier, in rounds of this size; copy-before-write copies the rest outside the barrier; never triggers a cut; 0 = no pre-copy") fs.BoolVar(&f.chunk.controlEndpoint, "chunk-control-endpoint", false, "walstore-chunk: expose the /chunk/* control routes (cut, snapshot, snapshots, snapshot/delete, detach) on the status HTTP listener; off by default; loopback-only like the listener") fs.UintVar(&f.durableBlocks, "durable-blocks", 2048, "number of blocks per volume on first create (ignored when opening existing)") @@ -618,6 +620,8 @@ func run(f flags) int { cfg.ChunkCaptureInterval = f.chunk.captureInterval cfg.ChunkDirtyThreshold = f.chunk.dirtyThreshold cfg.ChunkUploadConcurrency = f.chunk.uploadConcurrency + cfg.ChunkHydrationWorkers = f.chunk.hydrationWorkers + cfg.ChunkHydrationQueueDepth = f.chunk.hydrationQueueDepth cfg.ChunkHolder = chunkHolder(f) if chunkErr == nil { cfg.ChunkRemoteFor = chunk.remoteFor diff --git a/seaweed-block/core/frontend/durable/provider.go b/seaweed-block/core/frontend/durable/provider.go index 72ba48299c..6174905117 100644 --- a/seaweed-block/core/frontend/durable/provider.go +++ b/seaweed-block/core/frontend/durable/provider.go @@ -162,6 +162,9 @@ type ProviderConfig struct { // ChunkReadMissTimeout bounds one remote fetch of an absent block. // Zero: the storage default. ChunkReadMissTimeout time.Duration + // Per-volume hydration bounds; zero selects 2 workers and 64 distinct chunks. + ChunkHydrationWorkers int + ChunkHydrationQueueDepth int // ChunkCaptureInterval: an automatic cut is due once this long has // passed since the volume's last successful cut (of any kind). Zero // disables the timer. diff --git a/seaweed-block/core/frontend/durable/provider_chunk.go b/seaweed-block/core/frontend/durable/provider_chunk.go index dc5a1cca97..4af44da113 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk.go +++ b/seaweed-block/core/frontend/durable/provider_chunk.go @@ -364,14 +364,16 @@ func (p *DurableProvider) newChunkLayer(ctx context.Context, volumeID string, h remote = &manifestBoundRemote{closeBoundRemote: bound, builder: builder} } cfg := storage.ChunkLayerConfig{ - ChunkBlocks: p.cfg.ChunkBlocks, - RestoreChunkBytes: uint64(ws.BlockSize()) * uint64(p.cfg.ChunkBlocks), - Epoch: lin.epoch, - Holder: holder, - FreshFromHead: h.fresh, - ReadMissTimeout: p.cfg.ChunkReadMissTimeout, - BarrierBound: p.cfg.ChunkDirtyThreshold, - UploadConcurrency: p.cfg.ChunkUploadConcurrency, + ChunkBlocks: p.cfg.ChunkBlocks, + RestoreChunkBytes: uint64(ws.BlockSize()) * uint64(p.cfg.ChunkBlocks), + Epoch: lin.epoch, + Holder: holder, + FreshFromHead: h.fresh, + ReadMissTimeout: p.cfg.ChunkReadMissTimeout, + HydrationWorkers: p.cfg.ChunkHydrationWorkers, + HydrationQueueDepth: p.cfg.ChunkHydrationQueueDepth, + BarrierBound: p.cfg.ChunkDirtyThreshold, + UploadConcurrency: p.cfg.ChunkUploadConcurrency, CaptureAllowed: func() error { cur := p.view.Projection() if !cur.Healthy || cur.VolumeID != volumeID || lin.volumeID != volumeID { diff --git a/seaweed-block/core/storage/chunk_hydration.go b/seaweed-block/core/storage/chunk_hydration.go index f8261fa58e..01e5d97821 100644 --- a/seaweed-block/core/storage/chunk_hydration.go +++ b/seaweed-block/core/storage/chunk_hydration.go @@ -15,6 +15,21 @@ 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). +type ChunkHydrationStats struct { + WorkerLimit int + QueueDepth int + Active int + Queued int + WaitCalls uint64 + Joined uint64 + WaitRefusals uint64 + Fetches uint64 + Completed uint64 + FetchErrors uint64 +} + type chunkHydrationFlight struct { idx, gen uint64 ref chunkRef @@ -38,6 +53,7 @@ func hydrationPending(cause error) error { // it (or a store/capture/lifecycle lock) while awaiting or fetching bytes. func (l *chunkLayerImpl) OnReadMissContext(ctx context.Context, lba uint64) ([]byte, error) { idx := l.chunkOf(lba) + counted := false for { l.stMu.Lock() if l.closed { @@ -53,7 +69,12 @@ func (l *chunkLayerImpl) OnReadMissContext(ctx context.Context, lba uint64) ([]b l.stMu.Unlock() return make([]byte, l.blockSize), nil } + if !counted { + l.stats.Hydration.WaitCalls++ + counted = true + } if err := ctx.Err(); err != nil { + l.stats.Hydration.WaitRefusals++ l.stMu.Unlock() return nil, hydrationPending(err) } @@ -63,8 +84,12 @@ func (l *chunkLayerImpl) OnReadMissContext(ctx context.Context, lba uint64) ([]b if stale { f.cancel() } + if f != nil && !stale { + l.stats.Hydration.Joined++ + } if f == nil { if len(l.hydration) >= l.cfg.HydrationQueueDepth { + l.stats.Hydration.WaitRefusals++ l.stMu.Unlock() return nil, hydrationPending(nil) } @@ -101,6 +126,7 @@ func (l *chunkLayerImpl) OnReadMissContext(ctx context.Context, lba uint64) ([]b default: l.stMu.Lock() f.waiters-- + l.stats.Hydration.WaitRefusals++ l.stMu.Unlock() return nil, hydrationPending(ctx.Err()) } @@ -110,6 +136,9 @@ func (l *chunkLayerImpl) OnReadMissContext(ctx context.Context, lba uint64) ([]b closed := l.closed changed := l.absentGen[idx] != f.gen || l.head.Chunks[idx] != f.ref err := f.err + if !closed && !changed && errors.Is(err, ErrChunkHydrationPending) { + l.stats.Hydration.WaitRefusals++ + } l.stMu.Unlock() if closed { return nil, errChunkLayerClosed @@ -156,16 +185,22 @@ func (l *chunkLayerImpl) hydrationWorker() { } } next.running = true + l.stats.Hydration.Fetches++ l.wakeHydrationLocked() l.stMu.Unlock() fetch, cancel := context.WithTimeout(next.ctx, l.cfg.ReadMissTimeout) - _, err := l.fillOnce(fetch, next.idx, next.gen, next.ref) + resolved, err := l.fillOnce(fetch, next.idx, next.gen, next.ref) cancel() next.cancel() l.stMu.Lock() if hydrationContextCauseOnly(err) { err = hydrationPending(err) } + if err != nil { + l.stats.Hydration.FetchErrors++ + } else if resolved { + l.stats.Hydration.Completed++ + } next.err = err delete(l.hydration, next.idx) close(next.done) diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index e039e1cbc3..38fd56c042 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -1379,6 +1379,15 @@ func (l *chunkLayerImpl) recordCut(r chunkCutResult, st chunkCutStats, err error func (l *chunkLayerImpl) Stats() chunkLayerStats { l.stMu.Lock() out := l.stats + out.Hydration.WorkerLimit = l.cfg.HydrationWorkers + out.Hydration.QueueDepth = l.cfg.HydrationQueueDepth + for _, f := range l.hydration { + if f.running { + out.Hydration.Active++ + } else { + out.Hydration.Queued++ + } + } out.CutsRefused = make(map[string]uint64, len(l.stats.CutsRefused)) for k, v := range l.stats.CutsRefused { out.CutsRefused[k] = v diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index 9985dcf8fb..c1cc2888f2 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -435,6 +435,7 @@ type chunkCutStats struct { // - LastCut, LastCutH and LastCutNs (wall clock, Unix ns) describe the // last successful cut, whatever triggered it. type chunkLayerStats struct { + Hydration ChunkHydrationStats CutsOK uint64 CutsNoop uint64 CutsFailed uint64