From be32061728822869526e9f05edf5b0cbf6e7389d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 04:18:08 -0800 Subject: [PATCH] test: lock countingRemote's counts; the chunk layer puts in parallel countingRemote.Put updated its counts and seen map with no lock while the chunk layer's upload workers call Put in parallel; a main run aborted with "concurrent map writes". The counts are now under a mutex, and the read of the upload count inside the cut is too. Co-Authored-By: Claude Opus 5.5 --- .../chunkstore/layout_remote_session_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/seaweed-block/core/frontend/chunkstore/layout_remote_session_test.go b/seaweed-block/core/frontend/chunkstore/layout_remote_session_test.go index b0fde09c8a..f8f637957b 100644 --- a/seaweed-block/core/frontend/chunkstore/layout_remote_session_test.go +++ b/seaweed-block/core/frontend/chunkstore/layout_remote_session_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "path/filepath" + "sync" "testing" "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout" @@ -114,12 +115,16 @@ func TestLayoutRemote_AbortedSessionEndsAtTheNextCleaningTick(t *testing.T) { // refuses as not prepared (uploads of an ended session). type countingRemote struct { *LayoutRemote + // mu guards the counts: the chunk layer calls Put from parallel upload + // workers. + mu sync.Mutex puts, notPrepared int again []string // keys uploaded more than once seen map[string]bool } func (c *countingRemote) Put(ctx context.Context, key string, data []byte) error { + c.mu.Lock() c.puts++ if c.seen == nil { c.seen = map[string]bool{} @@ -128,13 +133,23 @@ func (c *countingRemote) Put(ctx context.Context, key string, data []byte) error c.again = append(c.again, key) } c.seen[key] = true + c.mu.Unlock() return c.LayoutRemote.Put(ctx, key, data) } +// uploads is the number of Puts so far. +func (c *countingRemote) uploads() int { + c.mu.Lock() + defer c.mu.Unlock() + return c.puts +} + func (c *countingRemote) CASHead(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) (uint64, error) { gen, err := c.LayoutRemote.CASHead(ctx, expected, next) if errors.Is(err, layout.ErrNotPrepared) { + c.mu.Lock() c.notPrepared++ + c.mu.Unlock() } return gen, err } @@ -161,7 +176,7 @@ func TestLayoutRemote_AdmissionRefusalKeepsTheSessionSoTheRetryConverges(t *test refuse := true l, err := storage.AttachChunkLayer(s, r, storage.ChunkLayerConfig{ChunkBlocks: lrChunkBlocks, Epoch: lh.me.Epoch, Holder: lh.me.Holder, FreshFromHead: true, CaptureAllowed: func() error { - if refuse && r.puts > 0 { // refused after the uploads, before the commit + if refuse && r.uploads() > 0 { // refused after the uploads, before the commit return errors.New("demoted") } return nil