test(storage): bound cut slots by configured payload budget

This commit is contained in:
pingqiu committed 2026-11-19 20:16:35 -08:00
1 parent ce7d290d4a
commit 46505243db
2 files changed
+46

No files matched your search

@@ -0,0 +1,40 @@
package storage
import (
"strings"
"testing"
)
func TestCutPayloadBudgetBoundsSlots(t *testing.T) {
const chunkBytes = int64(4 << 20)
for _, candidates := range []int{256, 4096} {
l := &chunkLayerImpl{blockSize: 4096, chunkBlocks: 1024, cfg: chunkLayerConfig{UploadConcurrency: 64, PayloadMemoryBudget: 6 * chunkBytes}}
pending := make(map[uint64]bool, candidates)
for i := 0; i < candidates; i++ {
pending[uint64(i)] = true
}
w, err := l.installCOWWindow(pending, nil, nil)
if err != nil {
t.Fatal(err)
}
workers, _, limit := l.cutPayloadWorkers()
if workers != 1 || cap(w.saverSlots) != 1 || limit != 6*chunkBytes || w.memoryLimit != limit || w.memory > limit {
t.Errorf("candidates=%d workers=%d savers=%d memory=%d limit=%d windowLimit=%d; want one uploader+saver within configured %d", candidates, workers, cap(w.saverSlots), w.memory, limit, w.memoryLimit, 6*chunkBytes)
}
w.abort(errCutCOWAborted)
if err := w.join(); err != nil {
t.Fatal(err)
}
}
}
func TestChunkLayerPayloadBudgetRejectsUndersized(t *testing.T) {
s, _ := newChunkTestStore(t)
cfg := ctConfig(1)
for _, budget := range []int64{-1, 1} {
cfg.PayloadMemoryBudget = budget
if _, err := attachChunkLayer(s, newFakeChunkRemote(), cfg); err == nil || !strings.Contains(err.Error(), "payload memory budget") {
t.Fatalf("payload memory budget %d: got %v, want refusal", budget, err)
}
}
}
+6
View File
@@ -364,6 +364,12 @@ type chunkLayerConfig struct {
// UploadConcurrency bounds capture/pre-copy Put calls (0 defaults to 8).
UploadConcurrency int
// PayloadMemoryBudget bounds this layer's uploader, saver and cached payload
// bytes (0 uses 64 MiB, or six chunks for larger geometry). Host-wide
// admission belongs behind a single Budget interface in the host limiter;
// this per-process budget does not coordinate other blockvolume processes.
PayloadMemoryBudget int64
// COWSpillLimit caps saved-before-write
// side bytes. Native pre-copy is triggered when remaining candidate
// bytes exceed half this cap; it streams directly to remote, without a