Skip to content

[P3] Stale multipart cleanup delays removal of empty hash directories #246

Closed

Description

@Vonng

Fix status (2026-10-19)

Released in SILO 20261018000000.

  • Fix: 0f9199e0c.
  • Merge: 4189869e4.
  • Released source: 0cd388c666f8211f552604ae73448a066e9c25ce; the fix is present on GitHub main and in the published binaries and images.

The fix replaces parent age checking and renaming with nonrecursive removal. The existing child traversal skips parents containing recent or unreadable uploads, avoiding unnecessary removal attempts. A concurrently created upload prevents removal of its nonempty parent. Upload expiry rules, deadlines, and throttling are preserved. Production code decreases by six lines, with no new locks, scans, dependencies, or configuration.

Validation passed on the local merge: cleanup regression tests, a controlled real-upload concurrency probe under the race detector, make verifiers, and make build with the executable reporting merge commit 4189869e4. The optional typos check was skipped because the tool was not installed. The concurrency probe confirms that an upload created and written while parent cleanup is paused remains usable and completes after cleanup resumes.

Cost review on local macOS arm64, using real filesystem operations, the real disk wrapper, default throttling, and medians of three samples:

Per cleanup pass Before Final fix
Scan 10,000 live hash directories 0.82 s 0.81 s
Allocated memory for that live-directory scan 43.4 MB 15.8 MB
Clean 1,000 expired uploads 3.10 s 4.16 s

The expired-upload pass now also removes the empty parents; the old pass leaves that work for later. This additional background cleanup cost was accepted. Unreadable legacy uploads remain in place instead of being removed indirectly through an old parent. These are local measurements, not a production throughput guarantee.


Expected Behavior

When cleanupStaleUploadsOnDisk removes the last expired upload from a multipart hash directory (.minio.sys/multipart/<shaDir>/), it should also remove that now-empty directory in the same pass. A hash directory containing another upload must remain intact.

Current Behavior

The expired upload is moved to .minio.sys/tmp/.trash/<uuid>, but the empty hash directory remains for another expiry period. With the defaults, that is at least another 24 hours, followed by the next cleanup scan (normally scheduled every 6 hours). Scan duration, restarts, and further directory changes can extend that delay.

The cause is the order of operations:

  1. renameAll moves an expired uploadIDDir out of shaDir, updating the parent directory's filesystem mtime.
  2. The cleanup then calls StatVol on shaDir; xlStorage.StatVol puts the directory's mtime in VolInfo.Created.
  3. time.Since(vi.Created) < staleUploadsExpiry is now true, so cleanup skips the empty parent.

Relevant code at published baseline 86fb2b833fb77146549f9170d9c460bfae2550bf (the cleanup code is identical to the initially reproduced local revision bb60871f57c0a590539fb0eef058e66dcaec49e4):

Steps to Reproduce

Use a temporary directory and the real cleanupStaleUploadsOnDisk function in a package-level Go test:

  1. Create .minio.sys/multipart/<shaDir>/<UUID>x<UnixNano>/, with the timestamp in the upload ID older than staleUploadsExpiry.
  2. Set the parent shaDir mtime to an old value as well.
  3. Supply a local disk whose Endpoint().Path is the temporary root and whose StatVol reports the actual filesystem mtime, then call cleanupStaleUploadsOnDisk once.
  4. Verify that the expired upload is gone, but its parent still exists, is empty, and has a fresh mtime.
  5. Run cleanup again immediately: the empty parent remains. Advance the parent's mtime past the expiry threshold and run cleanup again: the parent is finally moved away.

A fresh reproduction at the baseline above produced:

expired child removed; empty parent retained; actual parent mtime age=1.442046ms
aging the empty parent past expiry lets a later pass remove it

This exercised the actual cleanup function and real filesystem operations through a temporary Go test overlay. No production data or production timestamps were changed.

The existing cleanup test does not catch the problem: its StatVol stub always returns time.Now(), and the assertions only check the upload directory rather than the empty parent. See the current test.

Context

The verified impact is unnecessary retention of empty directories and their inode/metadata and directory-scan overhead, especially when many distinct object keys have expired multipart uploads. This finding does not show retained upload payloads in the empty hash directories, permanent leakage, or user data loss.

Reported by the maintainer from a Gemini review and independently reproduced against current SILO source.

Possible Solution

After scanning and expiring child uploads, replace the parent StatVol / age-check / Rename block with a best-effort, nonrecursive Remove(shaDir), keeping the existing deadline worker and cleanup throttling. Reuse the existing child scan to skip parents with recent or unreadable uploads, avoiding unnecessary removal attempts. The filesystem rejects removal of a nonempty directory, so another upload keeps its parent in place. A fresh empty directory does not need another expiry period.

Regression coverage should check same-pass removal after the last expired child, already-empty directories regardless of age, and preservation of a recent upload sharing a directory with an expired upload. Use real filesystem timestamps rather than a constant time.Now() stub.

Regression

Inherited behavior, present in the current baseline. The parent-age check and parent rename already appear in the upstream history preceding the SILO fork.

Your Environment

  • Source: pgsty/silo at bb60871f57c0a590539fb0eef058e66dcaec49e4
  • Reproduction: package-level test calling the actual cleanup function; local temporary filesystem
  • OS: macOS 27.0.1, arm64
  • Go: go1.27.2 darwin/arm64
  • This reproduction is local filesystem evidence, not a deployed Linux cluster acceptance result.

Activity

  1. added
    bug
    on Oct 18, 2026
  2. added this to the 20261018 milestone on Oct 19, 2026
  3. Vonng commented on Oct 19, 2026

    @Vonng
    MemberAuthor

    Fixed in 0f9199e0c, merged to main, and included in 20261018000000.

    Cleanup removes empty parents in the same pass while preserving live, unreadable, and concurrently created uploads. Cleanup regressions and the real-upload race probe passed. This closes the empty-directory issue; multipart enumeration and cancellation limitations remain tracked in #79.

  4. moved this from Backlog to Done in Siloon Oct 19, 2026
  5. added theissue type on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

    • Status
      Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions