Repository navigation
perf(fileservice): prefetch aligned, BDP-sized ranges for range reads and stream them to readers - #32382
perf(fileservice): prefetch aligned, BDP-sized ranges for range reads and stream them to readers#32382cpegeric wants to merge 67 commits into
Conversation
… read share honest - A background download keeps its reader's deadline and ends when the disk cache closes. - A read that captured its bytes does not fail when its download fails later, also when no background slot was free. - The download rate is fed only by downloads from object storage; content already in memory is cached without tracking it as a download. - Range-read cost is timed only for reads the file service drains to the end. - Bytes read from a downloading object count toward its cached file's read share. - The LRU disk cache inserts an item larger than its capacity as oldest, and does not evict an item before its insert notification returns. - Design v3 records these contracts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s at publication - A whole-object fill from memory is tracked as a download again, so readers share it, Update skips its ranges and the room check records its size; only downloads from object storage feed the download rate. - Bytes read from a download are counted before the read and credited to the file when it is published, so a file evicted at once, or a read still running at publication, keeps them. - The LRU disk cache neither evicts an item nor counts it toward eviction until its insert notification returns, so an oversized item no longer empties the cache while it is inserted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…zed items oldest - The read that starts a whole-object download counts the bytes it captures toward the file's read share, as other readers of the download do, so an object read only by its starter is not taken as unread. - A use of an item larger than the LRU capacity does not make it newer, so a read while it is inserted no longer evicts warm items before it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ns it A disk-cache read that misses its exact range file, the object's whole file and its download now reads from the smallest cached range file of the object that contains it. Range files are indexed by object as they enter the LRU, including files found at startup, and forgotten as they leave; a read passes over and forgets an indexed file the cache no longer holds. The size in a range file's name runs into the object name, so it is the prefix that equals the file's length, and only files in their object's shard directory are indexed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s cached ranges A range read with disk-prefetch-range-min or disk-prefetch-range-auto set fetches the aligned units its entries touch, at least the bandwidth-delay product of range reads with auto, and caches them as ranges that serve later reads. Units are split into blocks; a read takes each block it needs from a cached range, from the read under way that ends first, or from a new read of each run of missing blocks, so no block is read twice. The bytes between entries in other units are not read. DiskCache.Read serves an entry from cached ranges that hold it together when no single range contains it. The whole-object preload switch compares the cost of range reads with the cost of whole objects, with tunable margins, charge window and half life. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… cost model Prefetch flights read the body in 64KiB chunks and wake readers as their bytes arrive, drain the body to EOF so the connection is reused, and run on a context that outlives the reader that started them. Prefetch skips paths with a separator, samples request latency, fetches only the units entries touch, and counts its S3 reads. The preload cost model and its disk-preload-* knobs are removed; it changed no preload decision. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…inserts and deletes An insert charges its bytes as pending before used, and settles under the evictor lock. A removal subtracts its bytes before the item leaves its shard. Eviction checks the budget again before removing each item. Without these, a concurrent eviction could count a pending or deleted item and remove a warm one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h by default A run of missing blocks that holds a needed block is read from the first needed block, and the blocks before it in a range of their own, so a read does not wait for the bytes before its own. disk-prefetch-range-auto defaults to true; false turns prefetch ranges off. Co-Authored-By: Claude Opus 5.5 <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 9e65806ff5649916b7f7268b2af46cde5fd01b7d
Assessment: request_changes
Bounded scheduling and shared downloads sensibly extend existing cache owners. Earlier entry-publication, size, admission and connection-pool fixes are effective. Two defects remain: startup indexing can expose deleted range data, and failed range flights are reported as successful prefetches.
Model: gpt-6.1-sol / max
Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0
-
P1
pkg/fileservice/disk_cache.go:1715: Delete runs during warm-cache startup after loadCache discovers a range file but before SetOldest indexes it.
Impact: Deletion enumerates only already-indexed ranges, so it returns without removing this file. The loader subsequently exposes old bytes to reads after deletion or recreation. Include startup indexing in the deletion/publication protocol and add a warm-start deletion regression.
Evidence: loadCache's SetOldest reaches postSet/ranges.add without the generation guard used by entry writers. The retained public Delete/Write/Read probe returned cached 0x11 bytes versus backing 0x22; completing loading before deletion passed. loader-probe.stdout.log; receipt checks/1794568791520103242-2.json. The production overlay adds only a startup phase barrier. -
P2
pkg/fileservice/prefetcher.go:454: An admitted column-range flight fails its object-storage Read.
Impact: readRanges reports admission as success, so this branch increments downloaded and skips failure reporting despite caching nothing. Operators receive false prefetch-success statistics. Propagate the completed flight outcome and count/report failures separately from successful downloads.
Evidence: readRanges discards waitFlights' result, and flight read errors are not returned to this caller. The probe observed downloaded_delta=1, failed_delta=0, cached=false; the ordinary-read control recorded downloaded_delta=0, failed_delta=1. counter-probe.stdout.log; receipt checks/1794569280291341132-2.json. This probe changes no production code.
Validation:
-
Reviewed all 68 changed paths, affected consumers, 20 discussion entries and linked issue context; discussion-assessment.json covers every key exactly once.
-
Source audit passed: clean frozen head, diff check, gofmt, and protobuf descriptor verification showing only optional uint64 Node.read_policy field 98 added. Receipt: checks/1794568690130606633-2.json.
-
Isolation preflight passed. Native prerequisites were reused after verifying 198 current inputs and retained output hashes. Both focused diagnostic probes completed with the reported failures and passing controls, using assigned caches and test-exec.
-
Frozen CI reports 13 successful, 14 skipped and 2 neutral checks. validation-audit.json reconciles all five receipts, commands, source fingerprints and retained logs.
Limitations:
-
Probes used the disk backend; startup testing adds a phase barrier. No remote-S3 or production incident reproduction is claimed.
-
No local full-package, race or workload benchmark runs. Author validation retains its reported revisions and scope.
-
The initial counter-probe compilation timed out before executing tests; its completed retry reused the same caches. That setup timeout is not a product-test result.
…le; failed range prefetches count as failed Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Both findings of the 2026-11-13 review are fixed in 8aab88e. P1 — startup indexing vs. delete ( P2 — failed range flights reported as downloaded ( Validation: both regressions passed 100 runs under |
…prefetches past the flight bytes wait for room A read that reached an object whose prefetch had not started took the download over in its own goroutine and waited for all of it, or, for a whole object, dropped it. Past the 256 MiB of flights under way, a column prefetch read its ranges one by one with no flight to join and an asynchronous cache write, so reads of those bytes in between fetched them again. The prefetcher now has two queues of one type, prefetch and live. A read moves its object's waiting download to the live queue, whose workers run first, and waits only until reads can join the download, then streams its own bytes from it. A column prefetch past the flight bytes waits for flights to end instead of reading serially. Cold TPC-H SF10, interleaved, 2 runs each: cycle 1 12.45 / 12.40 s vs 14.44 / 13.85 s, q1 1.46 / 1.49 s vs 1.74 / 1.77 s, small GETs of bytes a column download fetched 92 / 83 vs 486 / 440; results identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…loads under the same flight bound Live downloads no longer skip the bytes of the flights under way, and both queues have the same workers and merge requests alike; queued bytes are bounded across both. The live queue keeps downloads whose reads all ended, as a read waits for each of them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e the flight bytes from memory A column prefetch of more than disk-prefetch-column-max bytes (default 32 MiB) downloads its whole object instead, to a file, and column reads join that download. Flight buffers are Go byte slices kept for reuse in pools by power-of-two size up to 32 MiB; a flight holds its buffer, as does each read copying from it, until the last release. The flights under way may hold 10% of the memory available on the node, measured at most once a second and at least one column bound, instead of a fixed 256 MiB, and count their buffers' sizes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ch-memory-max A prefetch is a MemoryPrefetchObject when its bytes are at most disk-prefetch-memory-max (default 32 MiB), and a FilePrefetchObject otherwise: each range downloads to its cache file through the file download path, which reads join while it downloads, without a memory buffer. A whole object is a FilePrefetchObject. A delete cancels the object's prefetch objects of both kinds before it removes its files, and a range is cached only if no delete was counted since it began. The flight-bytes measurement is taken by one caller at a time. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… prefetcher design Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…it for memory and connections A read's range fetch is a MemoryPrefetchObject it runs itself, or a FilePrefetchObject past disk-prefetch-memory-max, which other reads join; a parameter keeps a read that must not cache out of the disk cache, and a failed prefetch object fails the read. The read-miss path chooses the kind of each run by size, and a whole-object read is a FilePrefetchObject. Past the memory of the prefetch objects under way, a read waits for it; without a connection, a download waits for one. Downloads split while at most disk-prefetch-object-split-downloads (default 8) are in flight. Flush waits for the prefetch objects under way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
mo-bot review · Commit: "interrupted" |
…are one interface prefetchObject (span, joinable, eta, hold/release, use, stop, ended, err) is implemented by memoryPrefetchObject and filePrefetchObject, kept in one registry. Reads join either kind through use; a FilePrefetchObject is joined only when its bytes arrive within downloadMaxExtraWait of a range read. An object that ends without the bytes, or was stopped, leaves the read to the caller (errPrefetchMissed); a failed read's error fails the read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…jects Reads that miss the cache take their bytes from a prefetch object; downloads wait for connections and buffer memory; the split limit is the disk-prefetch-object-split-downloads setting. Fix the doc comments of waitDownloadConns and reserveDownloadConns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ncurrent reads Concurrent reads of different prefetch ranges against held object storage run only the MemoryPrefetchObjects the buffer bound admits; the rest wait without reading storage, a waiting read whose context ends returns, and afterwards every read has its bytes and no buffer stays counted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…est pins its estimates errPrefetchMissed uses moerr, as make err-check requires. The far-behind read test stops the download before it measures its own rate and sets the download rate and range-read cost, so the read is far behind in every run, including when the test runs alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t caches its entries A read that caches whole objects, not its entries, takes its bytes from a prefetch object that does not cache them, as its direct range read did not. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ead caches its entries A MemoryPrefetchObject a range read starts caches nothing: the read caches its entries as its policy says, as its direct range read did, unless the prefetch object it joined caches its bytes. Past disk-prefetch-memory-max a read that joins none reads directly. Caching the read's whole span made 8 concurrent TPC-H SF10 sessions on a 4 GB disk cache take about 80 s against about 68 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A FilePrefetchObject a read starts is registered before its download, so concurrent reads of its range share one download; it is stopped when no read waits for it before its download starts. - Reads that leave caching to a prefetch object join only objects that cache. - fetchRange allocates only once it has a prefetch object; FilePrefetchObjects read into the caller's buffer; eta counts the parts holding the read's bytes. - A download waits for a connection before it holds its path or an async slot. - A delete or close that stops a whole-object read's own download makes the read read its ranges, not fail with context.Canceled. - Flush no longer waits on the prefetch reads' WaitGroup. Co-Authored-By: Claude Opus 5.5 <[email protected]>
prefetcher.join counts the reads waiting on a download and returns leave, which joinQueued calls when it stops waiting, by start or by cancellation. A queued download whose last read left and whose scans ended is dropped, and the prefetch queue goes on. The live queue's keepEnded exception is removed: both queues drop a download no scan or read needs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A MemoryPrefetchObject's buffer was uncharged from the memory bound when its read ended, while reads still copying from it kept it alive, so the buffers held could exceed the bound. endPrefetch now only forgets the object; the last release uncharges the buffer and wakes the reads waiting for room. The release made under the prefetch-object lock moves after the unlock. Design doc v5 records the column-subset scan rule (2026-11-12) with its measurement, the buffer lifetime and the live-queue drop rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: fed865b79f8eed7afef20940931b5ed7a8d00ee2
Assessment: request_changes
The scheduler and memory/file prefetch objects coherently reuse existing cache owners. Earlier fixes are effective, but deletion still exposes unindexed prefetch files during warm-cache startup.
Model: gpt-6.1-sol / max
Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0
- P1
pkg/fileservice/disk_cache.go:1770: During asynchronous warm-cache loading, Delete returns before an old aligned range file is indexed; a subsequent read requests that range's exact offset and size.
Impact: The read can return deleted bytes, including after same-path recreation, and reindex the stale file for later containing reads.
Evidence: removeRangeFiles enumerates only d.ranges. DiskCache.Read opens the exact entry path at lines 604-606 and can reindex it at 736-748 without checking object deletion. loadFile checks deletion only when loading resumes (328-338). The startup regression checks after loading finishes, missing this interval. Invalidate unindexed ranges before Delete returns or guard raw-file reads/reindexing against deletion; add a read-before-loader-resumes regression. Source ordering and controls are retained in startup-delete-proof.md.
Validation:
-
Reviewed all 75 changed paths, affected consumers, 24 discussion entries and linked issue #32381. Saved the complete discussion ledger.
-
Source audit passed: clean frozen head, diff check, gofmt and descriptor verification showing only optional uint64 Node.read_policy field 98 added. Receipt: checks/1794650873534596837-2.json.
-
Isolation preflight passed. Go 1.27.1 bootstrap timed out before compilation; receipt checks/1794650958985921395-2.json records this environment diagnostic.
-
Frozen-head CI reports 13 successful, 14 skipped and 2 neutral checks, including build, UT, SCA and active PROXY/PESSIMISTIC BVT. Final receipt/log audit passed.
Limitations:
-
No local product, race or benchmark tests ran. The finding is source-established; the retained diagnostic regression was not executed.
-
Author validation and performance reports retain their stated revisions and scope; raw per-test logs were not supplied.
A read that opens a cache file the cache does not index reads and indexes it only if its object has no delete counted since the cache was created, as the startup load does. A delete during an asynchronous load misses range files the load has not indexed yet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Reply to the mo-bot review of fed865b:
Also in this update: main is merged. |
What type of PR is this?
Which issue(s) this PR fixes:
issue #32381
What this PR does / why we need it:
On S3, each read costs a request's latency on top of its bytes. Before this PR the file service had several problems:
This PR changes how the file service fetches object bytes and which bytes it fetches. Query results do not change.
Range reads
disk-prefetch-memory-max: it reads directly.disk-preload-*) is removed, because it never changed a decision.Prefetch objects
Every download is one of two kinds of prefetch object, behind one interface. The kind is chosen from the request's size, before any byte is downloaded.
disk-prefetch-memory-maxbytes in all (default 32 MiB, at least 8 MiB).disk-prefetch-memory-max.Both kinds behave the same way:
disk-download-max-extra-waitof what a range read would take. A read never waits behind a stalled download.Bounds. When an object would pass a bound, it waits until there is room; it does not fall back to serial reads.
disk-prefetch-memory-max. An object that does not fit waits until enough buffers are freed. It runs at once when no other object is under way.The prefetcher
The file service owns a prefetcher that is independent of the scans. The IO pipeline no longer carries object prefetches for table scans.
What scans send:
Queue order and bounds:
Live queue:
Ending:
Design: docs/design/20261110-object-prefetcher.md.
Column-range reads
read_policy(afileservice.Policy), on scans that should read column ranges.narrow_scanis no longer set or read.ADD COLUMN.count(*),select id, payload from …select *, a query naming every visible column, or a single-column tableExact reads:
ExactRead). A prefetch range around them used to hold the object's last columns, often the vector column.ExactColumnsRead) instead of downloading the whole object on a miss. These probes are:Reads that do not come from a planner scan node keep their own policy. These are the IVF-Flat search's scan of its entries table, TN merge and compaction, checkpoint and GC. A scan that reads a vector or blob column still downloads the whole object.
Whole-object downloads
disk-prefetch-object-split-min(16 MiB) readsdisk-prefetch-object-splitaligned parts at once (default 2, at most 4) into one cache file.disk-prefetch-object-split-downloadsdownloads are in flight (default 8).Thrash detector
The thrash detector switches a table's reads to range reads when its whole objects are evicted before use. A table may now switch only after the tables that are read less than it and are also evicting have switched. When one table switches, the others' eviction counts start again.
Before, the IVF-Flat entries table (about 33% read before eviction) often switched along with the base table (about 0.1%). With the disk cache full, it never switched back. The rule is in docs/design/20261102-thrash-aware-prefetch.md.
Disk cache correctness
SetOldestitems.Configuration and metrics
[fileservice.cache]settings:disk-prefetch-object-split(default 2; 1 turns splitting off);disk-prefetch-object-split-min(default 16 MiB);disk-prefetch-object-split-downloads(default 8);disk-prefetch-memory-max(default 32 MiB, at least 8 MiB).mo_fs_prefetch_object_total{result}counts prefetches by result: queued, merged, cached, downloaded, failed, missed, ended and dropped.Validation
Setup:
Results were identical in every run.
Against the parent build (a090268, interleaved pairs; the PR at 33a8a65, before column-range scans). Times are in seconds.
Column-range reads (MinIO, cold, against 4c4b60d, before column-range scans):
Index join-back (partial cache, 2 rounds, against dc3598b, where only IVF-Flat's join-back was marked):
select id, name … match … limit 10, 20 queriesselect id, cat … order by l2_distance … limit 10, 100 queriesLive queue and prefetch objects (MinIO, cold, interleaved, 2 runs each):
Concurrent reads (MinIO, cold, against 349a450, the parent of reads through prefetch objects; wall time in seconds):
The first version wrote each read's entries to the cache synchronously, which cost about 8 s with 8 sessions. Head writes them asynchronously (66.2–67.8 s across builds); head with only the entry writes made synchronous again took 75.6 / 76.3 s.
The filter queries' p95 was lower than the parent's.
The live queue cut small GETs for bytes that a column download had already fetched from 486 / 440 to 92 / 83.
Before prefetch objects, one 150 MB vector-column range was a single 150 MB buffer, and the fixed 256 MiB bound let only one run at a time.
Tests
pkg/fileserviceandpkg/objectiopass in a normal run and under-race.disttaeandmetric/v2pass under-race, andpkg/sql/compilepasses.-race.Limits
🤖 Generated with Claude Code