From 46505243db7db4afd71d30e78fa9b71aaea84a7f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 18:37:19 -0800 Subject: [PATCH] test(storage): bound cut slots by configured payload budget --- .../storage/chunk_cut_payload_budget_test.go | 40 +++++++++++++++++++ seaweed-block/core/storage/chunk_seam.go | 6 +++ 2 files changed, 46 insertions(+) create mode 100644 seaweed-block/core/storage/chunk_cut_payload_budget_test.go diff --git a/seaweed-block/core/storage/chunk_cut_payload_budget_test.go b/seaweed-block/core/storage/chunk_cut_payload_budget_test.go new file mode 100644 index 0000000000..bf141d776b --- /dev/null +++ b/seaweed-block/core/storage/chunk_cut_payload_budget_test.go @@ -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) + } + } +} diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index dee18a76a7..d178f10f63 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -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