-
Notifications
You must be signed in to change notification settings - Fork 622
Open
Description
Expected behavior
When running mc mirror, each log line should show an incrementing or correct totalSize field, representing the cumulative bytes mirrored so far.
Actual behavior
On consecutive log lines, the totalSize field remains the same even as new files are mirrored and the size field changes. This results in log output like:
{"status":"success","source":"...part.155.parquet","target":"...part.155.parquet","size":151084394,"totalCount":773,"totalSize":117613662156,...}
{"status":"success","source":"...part.156.parquet","target":"...part.156.parquet","size":149891402,"totalCount":774,"totalSize":117613662156,...}
Here, totalSize should increase by the size of the file, but it does not.
Steps to reproduce the behavior
- Run
mc mirroron a large set of files (with parallelism enabled, e.g., default or--max-workers > 1). - Examine the log output (
mc --json mirror ... > mirror.log). - Observe that in some consecutive lines,
totalSizedoes not increment, even though the filesizedoes.
Root cause analysis
- The code in
cmd/mirror-main.goupdates and logs progress (totalSize,totalCount) per file. - Due to parallel processing (see the use of
mj.parallel.queueTask), log messages can be written out of order with respect to the accumulator. - This causes a race condition where consecutive log lines may have identical
totalSizevalues, even though files are being mirrored sequentially in the log.
Code reference
Example code relevant to logging and parallel execution (from cmd/mirror-main.go):
// Each mirror task is queued in parallel
mj.parallel.queueTask(func() URLs {
return mj.doMirror(ctx, sURLs, EventInfo{})
}, sURLs.SourceContent.Size)
// Logging of totalSize happens here, but can be out of sync due to race conditions
mj.status.PrintMsg(mirrorMessage{
Source: sourcePath,
Target: targetPath,
Size: length,
TotalCount: sURLs.TotalCount,
TotalSize: sURLs.TotalSize,
...
})mc --version
mc version RELEASE.2025-08-13T08-35-41Z (commit-id=7394ce0dd2a80935aded936b09fa12cbb3cb8096)
Runtime: go1.24.6 linux/amd64
Copyright (c) 2015-2025 MinIO, Inc.
License GNU AGPLv3 <https://www.gnu.org/licenses/agpl-3.0.html>
System information
- Affects all platforms, especially with parallel mirroring (
--max-workers > 1).
Recommendation
Synchronize accumulator update and log writing so each log entry reflects the true cumulative totals at that moment, avoiding race conditions. Consider using mutex or atomic operations to ensure consistency.