Repository navigation
fix: keep disk cache file state consistent - #24494
mergify[bot] merged 13 commits into
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
There was a problem hiding this comment.
Pull request overview
This PR fixes a disk cache index/file inconsistency race introduced by running FIFO cache eviction callbacks asynchronously (outside queueLock). The fix prevents stale eviction callbacks from deleting newly reinserted cache files and makes DiskCache.SetFile self-heal when the on-disk file is missing despite an in-memory index hit.
Changes:
- Add
Cache.Containsand adjust FIFO cache deletion paths sopostEvictcallbacks run outside shard locks. - In disk cache eviction callback, skip
os.Removeif the path has been reinserted into the cache. - In
DiskCache.writeFile, verify the physical file exists before trusting an index hit; delete stale index entries and rewrite. - Add a regression test covering stale index repair.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/fileservice/fifocache/fifo.go | Adds Contains, refactors value purging + runs postEvict outside locks for Delete/Evict paths. |
| pkg/fileservice/fifocache/data_cache.go | Ensures DeletePaths executes postEvict callbacks after unlocking shard. |
| pkg/fileservice/disk_cache.go | Prevents stale evict callback from deleting reinserted files; repairs stale index on SetFile. |
| pkg/fileservice/disk_cache_test.go | Adds regression test for stale index repair behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I think this PR fixes the stale-index repair path, but there is still one race window in the core fix.
So A conservative fix would be to make eviction-time file removal coordinate with the same per-path update marker, e.g. a |
4e6e32f to
71f9bc3
Compare
|
Addressed review comments in the latest force-push:
|
|
Reviewed the latest update. I did not find additional blocking issues after the final cleanup change. The pushed fix now also handles the edge case where the just-written disk cache file is synchronously evicted while the same path is still in the write/update critical section: if the cache index no longer contains the path after Set/Replace, the physical file is removed immediately, avoiding an untracked .mofscache file. Local validation passed:
Tried to approve, but GitHub rejected it because this is my own PR: |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Retain memory cache values before publishing them in FIFO cache so delete/evict paths cannot release cache ownership before it is acquired. Also drain pending FIFO enqueue jobs before accounting-sensitive 3.0 replace/evict paths and skip deleted pending items. 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]>
Merge Queue Status
This pull request spent 1 hour 3 minutes 19 seconds in the queue, including 1 hour 2 minutes 52 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #24493
What this PR does / why we need it:
This PR fixes a disk cache stale-index race exposed after FIFO cache eviction callbacks were moved outside
queueLock.For disk cache, the eviction callback removes the physical cache file. After an item is moved to ghost state, the same key can be inserted again before the old callback runs. The old callback can then delete the physical file for the newly inserted cache entry, leaving the in-memory index present while the file is gone. Later
SetFilecalls trusted the index and returned without rewriting the file, so repeated reads missed disk cache and fetched the full object from S3 again.Changes:
DiskCache.writeFileverify the physical file exists before trusting an index hit; stale index entries are repaired and rewritten.writeFilestill holds the per-path update guard.postEvictexecution out ofDelete/DataCache.DeletePathsshard locks so callbacks can safely inspect cache state.fifocache.Newcallback signature migration for object metadata cache.Validation: