mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
storage: expose configurable hydration limits and wait/fetch counters
This commit is contained in:
1 parent
13281568ef
commit
39aca2daee
8 files changed
+82
-19
No files matched your search
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user