From 20c95ad73f3a8bcb72887fea91ff31ab24fa1011 Mon Sep 17 00:00:00 2001 From: Darren Yu Date: Sun, 2 Aug 2026 09:59:50 +0800 Subject: [PATCH] fix(upload): set concurrent chunk upload to 1 when disk pre-allocation is disabled (#3501) * fix(upload): set concurrent chunk upload to 1 when disk pre-allocation is disabled * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- pkg/filemanager/driver/local/local.go | 6 ++++++ pkg/filemanager/driver/remote/remote.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/pkg/filemanager/driver/local/local.go b/pkg/filemanager/driver/local/local.go index 172effb8..33f6ea93 100644 --- a/pkg/filemanager/driver/local/local.go +++ b/pkg/filemanager/driver/local/local.go @@ -226,6 +226,12 @@ func (handler *Driver) Token(ctx context.Context, uploadSession *fs.UploadSessio if err := Fallocate(f, 0, uploadSession.Props.Size); err != nil { handler.l.Warning("Failed to preallocate file: %s", err) } + } else { + // When disk pre-allocation is disabled, concurrent chunk uploads must be 1 + // to avoid disk fragmentation and write contention on local storage. + settings := *handler.Policy.Settings + settings.ChunkConcurrency = 1 + handler.Policy.Settings = &settings } return &fs.UploadCredential{ diff --git a/pkg/filemanager/driver/remote/remote.go b/pkg/filemanager/driver/remote/remote.go index 42b2b1af..cc0b89fa 100644 --- a/pkg/filemanager/driver/remote/remote.go +++ b/pkg/filemanager/driver/remote/remote.go @@ -150,6 +150,14 @@ func (handler *Driver) Token(ctx context.Context, uploadSession *fs.UploadSessio return nil, fmt.Errorf("failed to sign upload url: %w", err) } + // When disk pre-allocation is disabled, concurrent chunk uploads must be 1 + // to avoid disk fragmentation and write contention on slave storage. + if !handler.Policy.Settings.PreAllocate { + settings := *handler.Policy.Settings + settings.ChunkConcurrency = 1 + handler.Policy.Settings = &settings + } + return &fs.UploadCredential{ SessionID: uploadSession.Props.UploadSessionID, ChunkSize: handler.Policy.Settings.ChunkSize,