Skip to content

perf(fileservice): decide whole-object prefetch of narrow reads per table - #32040

Merged
mergify[bot] merged 7 commits into
matrixorigin:mainfrom
cpegeric:issue_32033_remain
Nov 3, 2026
Merged

mergify[bot] merged 7 commits into
matrixorigin:mainfrom
cpegeric:issue_32033_remain

Conversation

@cpegeric

@cpegeric cpegeric commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #32033

What this PR does / why we need it:

Follow-up to #32034. #32034 keeps one thrash signal per disk cache: when one table thrashes, every narrow read switches to range reads, including tables that would fit. This PR keeps one signal per table.

Design (docs/design/20261102-thrash-aware-prefetch.md, updated):

  • Each narrow read tells the disk cache which table it reads for; the cache maps the objects narrow reads touch to their table and tracks the read share of each table's evicted whole-object files.
  • A table switches to range reads when that share averages below 0.1 over 4 evictions, or below 0.4 over 16. Of two tables evicting each other, the one using its whole objects least switches first, and the other usually fits after that.
  • A table switches back after 30 s with no eviction of its own whole-object files. The period doubles, up to 10 min, when it thrashes again soon after.
  • The IVFFLAT pre-filter join back (JOIN(base, SEMI(search, filter scan))) is now marked narrow like the plain join back; the filter scan copied from the base scan is not.
  • The decision is made in S3FS.Read for every narrow read, from the table in the read context; reads of no table are never skipped.
  • Scans read with their table id: taken from the table definition, or from the plan node's object reference when the rewritten table definition has none.

Measurements (wiki_all 1M, IVFFLAT lists=1000, probe_limit=8, filtered query, MinIO, empty disk cache; 50 cold, 50 warm, 35 s pause, 50 more; avg ms, p95 in brackets):

Memory / disk #32034: cold / warm / after pause this PR: cold / warm / after pause
1 / 4 GB (4 runs) 162 (401) / 46 (223) / 68 122–194 (364–604) / 22–31 (60–127) / 45–64
0.5 / 1.5 GB (3 runs) 515 / 149 / 136 485 / 138 / 197
1 / 8 GB 102 / 16 82 / 16

Not in this PR: marking reads narrow by the share of an object's blocks they select (point and primary-key lookups without a plan mark). Tried and rejected: the TPC-H joins with selective runtime filters became narrow, and TPC-H round one took 64 s with 9,678 S3 requests.

Tests: per-table signal unit tests (separation, tiered trip, own quiet period, doubling, deletes, bounds), a real disk cache reporting a group, S3FS per-group decision, the prefetch gate and both data sources, table id reaching the read context from the scan operator, the scope fallback to the object reference, the IVFFLAT entries search, and the pre-filter join back plan mark.

🤖 Generated with Claude Code

…able (matrixorigin#32033)

The disk cache keeps one thrash signal per table instead of one per cache, so a
table that fits keeps its whole-object prefetch while another table thrashes.
A table switches first when its whole objects are used least, and turns off
after its own quiet period, which doubles when it thrashes again. The IVFFLAT
pre-filter join back is marked narrow like the plain join back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cpegeric
cpegeric requested a review from fengttt as a code owner November 2, 2026 21:11
@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 →

…d objects (matrixorigin#32033)

S3FS.Read applies the per-table decision to every narrow read, using the
table from the read context. Reads of no table are never skipped, an evicted
file's table mapping is dropped, and only scans with a read policy carry a
table in their context.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@XuPeng-SH

XuPeng-SH commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: a4f42da34042bc3d4000e2cb3cef9c3389686fe7

Review completed. Read the assessment.

@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.

mo-bot review · mo-bot-local · review

Commit: a4f42da34042bc3d4000e2cb3cef9c3389686fe7

Assessment: request_changes

The per-table policy is coherent, but its history map needs bounded retention before approval.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

  • P2 pkg/fileservice/disk_cache_preload.go:162: A long-lived CN observes whole-object evictions for successive table IDs, including tables subsequently dropped or no longer read.
    Impact: Each table permanently adds a groupUsage entry. Memory grows with historical table count, independently of disk capacity and preloadObjectsMax. Bound or expire these histories while preserving active cooldown behavior, and add a table-churn regression test.
    Evidence: removed creates p.groups entries; deleted only clears object records, and quiet-period recovery only resets flags/samples. No group deletion or capacity limit exists. A probe using the unchanged controller retained all 128 table histories after their objects were removed, explicit deletion, 24 hours of simulated idle time and another read. See controller-probe-distinct-objects.log.

Validation:

  • Read all 19 changed files and reconciled both discussion items; reviewed the linked issue and design.

  • Isolation preflight passed. Controller diagnostics confirmed retention while table-separation, zero-group and quiet-recovery controls passed.

  • Frozen CI reports 13 successful, 14 skipped and two neutral checks.

  • Source identity, probe provenance and terminal receipts were reconciled in validation-manifest.json; source remains unchanged.

Limitations:

  • The probe tests the controller directly, not live SQL or full-package behavior. Broader package/race/performance validation stopped after the lifecycle blocker.

  • Performance measurements are author-reported; their raw logs were unavailable. No production OOM is claimed.

@gouhongshen gouhongshen 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.

Codex automated review

The per-table thrash-signal rework is correct; I found no new blocking or non-blocking issues. Prior behavior (#32034) kept one thrash signal per disk cache; this PR maps each whole-object cache file to a table via a context-carried group (table ID) and keeps an independent EWMA, tiered-threshold, and quiet-period signal per table, deciding per narrow read in S3FS.Read and per object in the prefetch gates. I verified from code: group propagation (table_scan attaches TableID when ReadPolicy != 0; scope.go falls back to ObjRef.Obj, which carries the table ID; remote-run deserialization restores TableDef and node; the IVFFLAT entries scanner attaches the hidden table's TblId; group 0 never skips); the preloadUsage state machine (tiered trip 0.1 over 4 evictions and 0.4 over 16, average/sample reset on turn-off, quiet-period doubling capped at 10 min, explicit deletes excluded, objects map bounded at 1<<16) against its new unit tests; path consistency between the read/prefetch fill and the skip decision (both normalize via parseFilePathAtService and pathForFile on the object Name().String()); the prefetch gates (local per-block skip with consistent cursor bookkeeping; remote retains tombstone prefetch); and the IVFFLAT pre-filter rewrite (the filter scan is copied before scanNode.NarrowScan is set, so only the join-back scan is marked, with a test proving the copy stays unmarked). All callers of the renamed FullFilePreloadSkipped API are migrated and no stale implementers of the removed interface remain. An earlier mo-bot review raised a P2 that preloadUsage.groups retains one entry per table ID forever under table churn; the author has not addressed it, so it is not duplicated here, and it remains the one open, non-blocking concern. Limitation: tests could not be executed in this checkout because the touched packages require native third-party libraries (jemalloc, CRoaring, xxHash, usearch under thirdparties/install) that are absent, CGO_ENABLED=0 is unsupported (pkg/common/mpool requires the C allocator), and building them is environment setup outside review scope; validation was static, including compile-level checks of every changed call site and test helper.

@XuPeng-SH

XuPeng-SH commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: a4f42da34042bc3d4000e2cb3cef9c3389686fe7

New discussion was assessed; the previous review remains unchanged.

@mergify mergify Bot added the queued label Nov 3, 2026
@mergify

mergify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request branch update failed

51 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 3 Nov, 11:05 · rule main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue 11:56 · a9e37e5

Reason

The pull request can't be updated

GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/ci-cancellation.yml without workflows permission
GitHub only lets Mergify write to .github/workflows/ with the workflows permission. An organization owner can accept Mergify's pending permissions at https://dashboard.mergify.com/orgs/matrixorigin/repositories.

To get back in the queue

  • Update or rebase the branch yourself: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, tick the box below to queue it again as it is.

Requeued — the merge queue status continues in this comment ↓.

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added dequeued and removed queued labels Nov 3, 2026
@mergify

mergify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🛑 Queue command cancelled

@mergify mergify Bot added queued and removed dequeued labels Nov 3, 2026
@mergify

mergify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as 8522123 at 19:47 UTC

2 h 43 min in the queue, 1 h 6 min of it CI.

So far

  • ✅ Entered the queue Tue 3 Nov, 17:05 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 19:47 · 8522123 · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
ci — 6989a202 Deployed Nov 3, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants