Skip to content

fix(fileservice): stream full-object disk cache without read wait amplification - #24759

Merged
mergify[bot] merged 9 commits into
matrixorigin:mainfrom
LeftHandCold:fix-disk-cache-update-wait
Jun 2, 2026
Merged

mergify[bot] merged 9 commits into
matrixorigin:mainfrom
LeftHandCold:fix-disk-cache-update-wait

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Jun 1, 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:

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 SetFile without 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 671306459a8835c1a247074a0db9227657b956b0 no 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-file SetFile update to complete. During TPCC 1000/1000 this produced repeated slow disk cache wait update complete spans 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 nil file variable 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 full go test ./pkg/fileservice -count=1 run did not complete locally after several minutes and was stopped; the targeted tests above completed successfully.

Copilot AI review requested due to automatic review settings June 1, 2026 11:02
@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 →

…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.
@LeftHandCold
LeftHandCold force-pushed the fix-disk-cache-update-wait branch from ca9d1da to ecdbfb5 Compare June 1, 2026 11:04
@LeftHandCold LeftHandCold changed the title fix(fileservice): avoid waiting on updating full-file disk cache fix(fileservice): stream full-object disk cache without read wait amplification Jun 1, 2026

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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-object io.ReadAll buffer 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 complete amplification seen in Loki;
  • reused disk cache file handles now seek on the reused handle instead of the nil local file variable;
  • 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.

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

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 IOVector entries (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.Read to 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.

Comment thread pkg/fileservice/s3_fs.go Resolved
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jun 1, 2026
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]>
@mergify

mergify Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-06-02 07:43 UTC · Rule: main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-06-02 07:44 UTC · at 200fd35119ab30d6c8a14330e45539d5cdec016e · squash

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

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 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 CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT 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

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed from correctness, concurrency/cache behavior, and regression/test coverage angles. The change looks good to me.

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/enhancement kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance]: Avoid full-file disk cache update wait amplification in TPCC

5 participants