From 1f36db305f173bc9cca00f096f07b7bdb8ea5564 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 18 Nov 2026 21:06:23 -0800 Subject: [PATCH] fix(chunkstore): partition base manifest chunks once per preparation --- .../core/frontend/chunkstore/manifest.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/seaweed-block/core/frontend/chunkstore/manifest.go b/seaweed-block/core/frontend/chunkstore/manifest.go index 01781b4b06..9a4708655d 100644 --- a/seaweed-block/core/frontend/chunkstore/manifest.go +++ b/seaweed-block/core/frontend/chunkstore/manifest.go @@ -90,14 +90,19 @@ func (r *ChunkRemote) PrepareManifest(ctx context.Context, base, next storage.Ch data []byte } var uploads []upload - for group, chunks := range groups { - old := map[uint64]storage.ChunkRef{} - for idx, ref := range base.Chunks { - if idx/per == group { - ref.Key = qualifyManifestKey(owner, ref.Key) - old[idx] = ref - } + // Partition the base once, rather than scanning every base chunk for each + // segment group. Keep the same qualified-key comparison for segment reuse. + baseGroups := map[uint64]map[uint64]storage.ChunkRef{} + for idx, ref := range base.Chunks { + group := idx / per + if baseGroups[group] == nil { + baseGroups[group] = map[uint64]storage.ChunkRef{} } + ref.Key = qualifyManifestKey(owner, ref.Key) + baseGroups[group][idx] = ref + } + for group, chunks := range groups { + old := baseGroups[group] if previous, ok := base.Segments[group]; ok && base.ChunkBytes == chunkBytes && reflect.DeepEqual(chunks, old) { next.Segments[group] = previous continue