Skip to content

fix: keep disk cache file state consistent - #24495

Merged
mergify[bot] merged 18 commits into
matrixorigin:4.0-devfrom
LeftHandCold:fix/disk-cache-stale-index-4.0
May 21, 2026
Merged

mergify[bot] merged 18 commits into
matrixorigin:4.0-devfrom
LeftHandCold:fix/disk-cache-stale-index-4.0

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented May 20, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #24493

What this PR does / why we need it:

This PR ports the safe disk-cache consistency fix to 4.0-dev.

4.0-dev did not yet contain the FIFO async postEvict change from #24117, but this PR brings the same performance intent in with the disk-cache safety guards included. This keeps the 3.0-dev and 4.0-dev fixes consistent while avoiding the stale-index race that caused repeated S3 full-object reads in 3.0-dev.

Changes:

  • Move FIFO cache postEvict callbacks outside queueLock to avoid slow callback lock convoy.
  • Drain pending FIFO enqueue jobs before eviction/accounting decisions, including Replace, Evict, and EvictWithWait.
  • Read pending enqueue item state under the shard lock so Delete cannot race with enqueue draining.
  • Make disk cache eviction skip deleting a path that has already been reinserted.
  • Verify the physical file with os.Stat before trusting a disk cache index hit; stale entries are repaired and rewritten.
  • Clean up physical files whose cache index is evicted while writeFile still holds the per-path update guard.
  • Order same-key mem-cache remote callbacks by generation so stale evict callbacks cannot delete a newer set.
  • Finish the fifocache.New callback signature migration for object metadata cache.
  • Add regression tests for post-evict behavior, pending enqueue accounting, stale disk cache index repair, update cleanup, and mem-cache callback ordering.

Validation:

source /Users/shenjiangwei/Work/code/matrixone/setup_env.sh && go test -race -mod=mod ./pkg/fileservice/fifocache -run 'TestEvictSkipsDeletedPendingEnqueueJob|TestReplaceAccountsPendingEnqueueJob|TestEvictAccountsPendingEnqueueJob' -count=1 -timeout=90s
source /Users/shenjiangwei/Work/code/matrixone/setup_env.sh && go test -mod=mod ./pkg/fileservice -run 'TestDiskCacheSetFileRepairsStaleIndex|TestDiskCacheEvictSkipsPathBeingUpdated|TestDiskCacheUpdateCleanupRemovesUnindexedFile|TestDiskCacheStaleRepairReplacesCacheEntrySize|TestDiskCacheRemovesFileEvictedDuringWrite|TestDiskCacheFileCache|TestMemCacheSkipsStalePostEvictAfterReinsert|TestMemCacheSerializesSameKeyCallbacks' -count=1 -timeout=90s
source /Users/shenjiangwei/Work/code/matrixone/setup_env.sh && go test -mod=mod ./pkg/objectio ./pkg/fileservice ./pkg/fileservice/fifocache -count=1 -timeout=180s

Copilot AI review requested due to automatic review settings May 20, 2026 07:21
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label May 20, 2026
@mergify mergify Bot added kind/bug Something isn't working kind/test-ci labels May 20, 2026
@LeftHandCold
LeftHandCold force-pushed the fix/disk-cache-stale-index-4.0 branch from 8bb4096 to 23d5cb5 Compare May 20, 2026 07:27
@LeftHandCold LeftHandCold changed the title fix: repair stale disk cache index fix: keep disk cache file state consistent May 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Hardens the fileservice disk cache against stale in-memory index entries by verifying the on-disk cache file exists before treating an index hit as authoritative, and adds a regression test to ensure the cache self-repairs when the physical file is missing.

Changes:

  • In DiskCache.writeFile, validate cache index hits with os.Stat; if the file is missing, drop the stale index entry and proceed to rewrite the cache file.
  • Add TestDiskCacheSetFileRepairsStaleIndex to reproduce the stale-index/missing-file scenario and assert SetFile repairs the cache.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

File Description
pkg/fileservice/disk_cache.go Adds existence check on cache index hits and deletes stale index entries to force a rewrite when the physical file is missing.
pkg/fileservice/disk_cache_test.go Adds a regression test covering “index hit but physical file removed” and verifies subsequent reads observe repaired content.

Comment thread pkg/fileservice/disk_cache.go Resolved
Comment thread pkg/fileservice/disk_cache_test.go Resolved
LeftHandCold and others added 11 commits May 20, 2026 18:57
Retain memory cache values before publishing them in FIFO cache so delete/evict paths cannot release cache ownership before it is acquired. Keep slow post-set callbacks outside FIFO locks while preserving the existing public constructor.

Co-authored-by: Copilot <[email protected]>
Use the same shard-locked validation for immediate enqueue as pending enqueue so a slow post-set callback cannot enqueue an item deleted before enqueue. Add coverage for enqueue-after-delete accounting.

Co-authored-by: Copilot <[email protected]>
@mergify

mergify Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-21 14:47 UTC · Rule: release-4.0
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-05-21 14:48 UTC · at 514235fdd1f1b8171d544ad1e484c1be70d38918 · squash

This pull request spent 35 seconds in the queue, including 6 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants