Repository navigation
fix(fileservice): stream full-object disk cache without read wait amplification - #24759
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? |
…lification Stream full-object disk cache fills through SetFile so S3 reads no longer retain the whole object buffer while populating the disk cache. Treat an in-progress full-file disk cache update as a miss for range-read fallback, while preserving wait semantics for entry-specific cache files. This avoids TPCC latency amplification from waiting behind full-object disk cache updates. Also fix reused disk cache file handles to seek on the reused file instead of a nil local variable.
ca9d1da to
ecdbfb5
Compare
LeftHandCold
left a comment
There was a problem hiding this comment.
Reviewed the PR after squashing the branch. I did not find blocking code issues in the current diff.
Key points checked:
- full-object disk cache fill now streams through
SetFile, so the read path no longer retains a whole-objectio.ReadAllbuffer before updating disk cache; - entry-specific disk cache reads still wait for update completion, preserving protection against partially-written entry files;
- full-file fallback reads skip an in-progress full-file update and continue as a cache miss, which addresses the TPCC
disk cache wait update completeamplification seen in Loki; - reused disk cache file handles now seek on the reused handle instead of the nil local
filevariable; - regression coverage includes the non-blocking full-file update path and the streaming fill behavior.
Local targeted tests passed. Full go test ./pkg/fileservice -count=1 did not complete locally after several minutes, so final confidence should include the PR CI result.
There was a problem hiding this comment.
Pull request overview
This PR improves FileService disk-cache behavior for S3 full-object caching by streaming full-object cache population (avoiding full-object buffering in memory) and by preventing range reads from blocking behind an in-progress full-file disk cache update. It also fixes a bug in DiskCache.Read where the code attempted to seek on the wrong file handle in the opened-file reuse path, and adds targeted regression tests.
Changes:
- Stream full-object disk cache population while capturing only requested ranges to fill
IOVectorentries (reducing RSS pressure vs full-object buffering). - Treat “full-file fallback” disk-cache reads as cache misses when a full-file update is in progress (avoids latency amplification from waiting).
- Fix
DiskCache.Readto seek on the reused opened file handle; add focused tests covering both the streaming fill and the “skip while updating” behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/fileservice/s3_fs.go | Adds streaming full-object disk cache fill path that captures requested ranges during streaming. |
| pkg/fileservice/s3_fs_test.go | Adds a test ensuring streaming fill does not retain a full-object-sized buffer and verifies cache hit behavior. |
| pkg/fileservice/disk_cache.go | Fixes seek-on-nil bug for reused files; skips full-file fallback reads while a full-file update is in progress via isUpdating. |
| pkg/fileservice/disk_cache_test.go | Adds regression test ensuring reads do not block behind an in-progress full-file update. |
Align the regression test with DiskCache.SetFile returning only an error so static-check can compile pkg/fileservice again. Co-authored-by: Copilot <[email protected]>
Merge Queue Status
This pull request spent 55 seconds in the queue, including 6 seconds running CI. Required conditions to merge
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed from correctness, concurrency/cache behavior, and regression/test coverage angles. The change looks good to me.
What type of PR is this?
Which issue(s) this PR fixes:
Closes #24758
What this PR does / why we need it:
This PR replaces the bounded full-file preload admission approach with streaming full-object disk cache population. Full-object reads can populate the disk cache through
SetFilewithout retaining the whole object buffer in memory. The requested entry ranges are captured while the object stream is copied to disk, then used to fill the caller vector.The nightly TPCC run for commit
671306459a8835c1a247074a0db9227657b956b0no longer showed the previous RSS pressure, but Loki logs showed a remaining latency amplification path: range reads that miss their entry-specific disk cache file can fall back to the full-file disk cache path, and they previously waited for an in-progress full-fileSetFileupdate to complete. During TPCC 1000/1000 this produced repeated slowdisk cache wait update completespans while large full-file cache objects were being streamed to disk.The fix keeps the existing wait for entry-specific cache files, where waiting avoids reading a partially-written entry cache file. For the full-file fallback path, an in-progress update is now treated as a cache miss so the caller can continue through the normal backing read path instead of blocking behind the whole full-object cache fill.
It also fixes the opened-file reuse path in
DiskCache.Read, which was seeking on the nilfilevariable instead of the reused file handle.Test plan:
go test ./pkg/fileservice -run 'TestDiskCacheReadSkipsFullFileWhileUpdating|TestS3FSFullObjectDiskCacheFillDoesNotRetainWholeObjectBuffer' -count=1\n-go test ./pkg/fileservice -run 'TestDiskCacheReadSkipsFullFileWhileUpdating|TestDiskCacheUpdateCleanupRemovesUnindexedFile|TestDiskCacheStaleRepairReplacesCacheEntrySize|TestS3FSFullObjectDiskCacheFillDoesNotRetainWholeObjectBuffer' -count=1\n\nNote: a fullgo test ./pkg/fileservice -count=1run did not complete locally after several minutes and was stopped; the targeted tests above completed successfully.