From 7387866fd61c728c351395f306a970e00684945c Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 9 Aug 2026 23:56:21 -0700 Subject: [PATCH] filer: bound format chunk sizes when no maxMB is configured Extent chunks are buffered in memory, so an absent limit must not mean unlimited. Also close the repack chunk reader to release its private reader cache, and drop the arithmetic capacity hint on the extended-map allocation. --- weed/server/filer_server_format.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/weed/server/filer_server_format.go b/weed/server/filer_server_format.go index 5a1fbd02e2..442d603793 100644 --- a/weed/server/filer_server_format.go +++ b/weed/server/filer_server_format.go @@ -28,6 +28,9 @@ import ( const ( maxFormatSidecarBytes = 16 << 20 formatSniffBytes = 512 + // defaultFormatChunkSizeMB caps extent chunks when no maxMB is configured. + // Extent chunks are buffered in memory, so the limit must never be absent. + defaultFormatChunkSizeMB = 4 ) // formatChunkSizeLimit mirrors the autoChunk maxMB resolution. @@ -37,6 +40,9 @@ func (fs *FilerServer) formatChunkSizeLimit(r *http.Request) int64 { if maxMB <= 0 && fs.option.MaxMB > 0 { maxMB = int32(fs.option.MaxMB) } + if maxMB <= 0 { + maxMB = defaultFormatChunkSizeMB + } return int64(maxMB) * 1024 * 1024 } @@ -261,6 +267,8 @@ func (fs *FilerServer) formatRepack(ctx context.Context, w http.ResponseWriter, chunkViews := filer.ViewFromChunks(ctx, lookup, oldChunks, 0, size) readerCache := filer.NewReaderCache(8, chunk_cache.NewChunkCacheInMemory(16), lookup, nil) readerAt := filer.NewChunkReaderAtFromClient(ctx, readerCache, chunkViews, size, filer.DefaultPrefetchCount) + // Close releases the private reader cache and its in-flight prefetches. + defer readerAt.Close() hint := format.Hint{Name: entry.Name(), ContentType: entry.Attr.Mime, Size: size} sniffSize := int64(formatSniffBytes) @@ -321,7 +329,7 @@ func (fs *FilerServer) formatRepack(ctx context.Context, w http.ResponseWriter, newEntry := *entry newEntry.Chunks = newChunks - newEntry.Extended = make(map[string][]byte, len(entry.Extended)+1) + newEntry.Extended = make(map[string][]byte) for k, v := range entry.Extended { newEntry.Extended[k] = v }