Skip to content

[Bug]: DiskCache cleanup holds the global update mutex during filesystem I/O #27360

Closed

Description

@XuPeng-SH

Branch Name

main

Commit ID

6f42b19

Other Environment Information

  • MatrixOne source build / matrixorigin/matrixone:local
  • Linux amd64, Docker multi-CN test deployment

Actual Behavior

DiskCache.startUpdateWithCleanup keeps updatingPaths.L locked while invoking its cleanup callback. The production callback from DiskCache.writeFile calls removeUnindexedFile, which can execute filesystem removal (os.Remove). Because the mutex protects the update map for every cache path, a slow cleanup for one path blocks startUpdate, startUpdateWithCleanup, and waitUpdateComplete for unrelated paths as well.

A white-box reproduction ran 3 times: a cleanup callback for path first was held for 150 ms; an update for independent path second remained blocked for the entire interval and proceeded only after cleanup released the global mutex.

Expected Behavior

The per-path update marker should remain held until cleanup completes, but cleanup filesystem I/O should not hold the global mutex for unrelated paths. The implementation should release the global map lock before invoking cleanup, while preserving same-path exclusion and exactly-once marker removal.

Steps to Reproduce

  1. In package pkg/fileservice, create a DiskCache.
  2. Call startUpdateWithCleanup for an IOEntry path with a callback that blocks on a channel.
  3. While the callback is blocked, call startUpdate for a different IOEntry path in another goroutine.
  4. Observe that the independent path cannot start until the first callback returns.
  5. Diagnostic command:
    GOWORK=off go test -mod=readonly -v -count=3 ./pkg/fileservice -run TestCodexDiskCacheCleanupSerializesIndependentPaths

Additional information

  • pkg/fileservice/disk_cache.go locks updatingPaths.L in startUpdateWithCleanup, defers its unlock, then runs cleanup() before deleting the path marker and broadcasting.
  • The production cleanup path is writeFile -> startUpdateWithCleanup -> removeUnindexedFile -> os.Remove.
  • Under high disk latency, this global critical section can amplify one slow cache cleanup into cluster-wide disk-cache tail latency and waiter buildup across otherwise independent objects.

Activity

  1. added
    kind/bug
    on Aug 19, 2026
  2. XuPeng-SH commented on Aug 19, 2026

    @XuPeng-SH
    ContributorAuthor

    High-depth cause analysis:\n\nstartUpdateWithCleanup protects a global map of all updating paths with one condition mutex. Its completion function keeps that mutex held while invoking cleanup, and the production cleanup can call os.Remove. Thus the wait-for graph is path A cleanup I/O -> global updatingPaths mutex -> every path B start/wait operation.\n\nThe intended ownership invariant only requires the path A marker to remain true until cleanup completes. It does not require unrelated paths to wait for the cleanup callback. Releasing the global map lock during cleanup, while retaining the marker and performing an exactly-once delete and broadcast afterward, would preserve same-path exclusion and remove this cross-path serialization. With disk p99 in the tens of seconds, this lock scope amplifies one slow cleanup into broad DiskCache tail latency.

  3. added a commit that references this issue on Aug 21, 2026
    70cd802
  4. added 3 commits that reference this issue on Sep 17, 2026
    2f7ae34
    61f94b0
    1c17af6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions