Skip to content

perf(fileservice): prefetch aligned, BDP-sized ranges for range reads and stream them to readers - #32382

Closed
cpegeric wants to merge 67 commits into
matrixorigin:mainfrom
cpegeric:fileservice_range_cost
Closed

cpegeric wants to merge 67 commits into
matrixorigin:mainfrom
cpegeric:fileservice_range_cost

Conversation

@cpegeric

@cpegeric cpegeric commented Nov 8, 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 #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:

  • Scans prefetched whole objects through the IO pipeline with no order and no bound. Objects were evicted before the scan reached them.
  • A read that reached an object before its prefetch could download the whole object itself.
  • Any scan downloaded the columns it never read, chiefly the vector column. This included a scan that read only a few columns, a vector or fulltext index's join back to its base table, and a dedup probe.

This PR changes how the file service fetches object bytes and which bytes it fetches. Query results do not change.

Range reads

  • A range read fetches aligned ranges of the object, in 64 KiB blocks.
    • Ranges are sized by the bandwidth-delay product of range reads: a power of two from 64 KiB to 8 MiB.
    • Only the blocks an entry touches are fetched.
    • Overlapping reads fetch and cache each block once.
  • A read is served from the cached range files that cover it.
  • Every range read that misses the cache takes its bytes from a prefetch object (below), which other reads of those bytes join. Bytes stream to readers as they arrive. The one exception is a read that must not write the disk cache and is larger than disk-prefetch-memory-max: it reads directly.
  • A read caches its own entries. A prefetch object that a read starts caches nothing; the read joins it only for its bytes. Entries are written to the cache asynchronously, and a write is dropped when the async slots are full.
  • The preload cost model (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.

  • A MemoryPrefetchObject holds ranges of at most disk-prefetch-memory-max bytes in all (default 32 MiB, at least 8 MiB).
    • It reads them into buffers and then caches them as range files.
    • Buffers are Go byte slices, reused by power-of-two size up to 32 MiB. A buffer is reused only once its object has ended and no read is still copying from it.
  • A FilePrefetchObject downloads to the temporary file that becomes its cache file, and holds no buffer. It is used for an object read whole, and for each run of ranges larger than disk-prefetch-memory-max.

Both kinds behave the same way:

  • Joining. Readers join both kinds and wait only for their own bytes.
    • A FilePrefetchObject is joined only when its bytes will arrive within disk-download-max-extra-wait of what a range read would take. A read never waits behind a stalled download.
    • A prefetch object that ends without a read's bytes leaves that read to fetch them itself. This covers an object stopped by another query, by a delete or by close.
    • A storage error while reading the bytes fails the read.
  • Delete. A delete cancels both kinds before it removes the object's files. Neither is cached after a delete counted since it began.

Bounds. When an object would pass a bound, it waits until there is room; it does not fall back to serial reads.

  • Memory. The buffers of MemoryPrefetchObjects, counted from the start of each until the last read copying from it releases it, hold at most 10% of the node's available memory. This is measured at most once a second and is never below 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.
  • Connections. Downloads hold at most half of the object-storage host's connections, so range reads always keep connections of their own. A download waits for a connection; it is not skipped.

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:

  • A table scan passes each object in its window to the prefetcher. It sends:
    • the object's size, from the catalog (no Stat request);
    • when the scan will reach it, from the scan's measured pace;
    • the share of the object's blocks the scan reads;
    • for a column-range scan, the ranges of its columns.
  • The call returns at once.

Queue order and bounds:

  • The queue downloads objects in this order:
    1. the largest share read, in tenths;
    2. the soonest due;
    3. the first asked for.
  • Two scans asking for the same object merge into one queue entry.
  • An object is never queued while it is queued, downloading or cached.
    • A request for a cached object marks it used in the disk cache LRU.
    • A request for ranges of a cached object does not.
  • Queued bytes stay below min(cache / 2, download rate × workers × 30 s).
    • When the queue is full, entries whose scans have all ended are dropped first.
    • After that, the entry last in download order is dropped.

Live queue:

  • The prefetcher has two queues of one type: prefetch and live. Both run on the same workers with the same code.
  • A read that reaches an object whose download is still queued does three things:
    1. It moves the download to the live queue. The prefetch queue starts nothing while the live queue has work.
    2. It waits only until reads can join the download.
    3. It takes its own bytes as they arrive.
  • No download runs in a reader's goroutine.

Ending:

  • When a scan closes, its queued downloads are dropped, unless a read waits for them in the live queue.
  • A queued download that no read waits for any more, because each read started or was cancelled, and whose scans have ended, is dropped at once.
  • Closing the file service or the disk cache cancels the downloads under way and waits for them.

Design: docs/design/20261110-object-prefetcher.md.

Column-range reads

  • Plan field. The planner sets a new plan field, read_policy (a fileservice.Policy), on scans that should read column ranges. narrow_scan is no longer set or read.
  • What such a scan does, per object. It prefetches each read column's object-wide extent as one range, whatever share of the object those columns are.
    • MO objects are column-major across blocks, so each column is one contiguous range for every type, including varchar. Consecutive columns are adjacent.
    • The download skips the columns already cached and reads adjacent columns in one read.
    • It prefetches nothing when the object records no column ranges, or stores none of the columns, as after ADD COLUMN.
  • It never downloads a whole object. Its reads fetch exactly their entries; a miss with gaps between entries reads each entry on its own. Its block pruning reads with the same policy.
Scan Read path
A scan of some of a table's visible columns, e.g. TPC-H (q1 reads 7 of lineitem's 16 columns), count(*), select id, payload from … column ranges
select *, a query naming every visible column, or a single-column table whole object
The base-table join-back of a vector (IVF-Flat, HNSW, IVF-PQ, CAGRA) or fulltext (fulltext, fulltext2) index search column ranges, set explicitly; the full-table scan a pre-filter plan copies from it is not marked this way
The target scan of each DEDUP join (INSERT, REPLACE, UPDATE and their IGNORE forms) its key columns only

Exact reads:

  • Object metadata and bloom filters are read as exactly their extents (ExactRead). A prefetch range around them used to hold the object's last columns, often the vector column.
  • Probes that read one to three columns of a data object read exactly those columns (ExactColumnsRead) instead of downloading the whole object on a miss. These probes are:
    • the CN's insert/upsert dedup, optimistic-RC write validation and visible-commit-ts walk;
    • the TN's precommit dedup, dedup of persisted objects, object add and MVCC load.

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

  • Split downloads. A download of an object of at least disk-prefetch-object-split-min (16 MiB) reads disk-prefetch-object-split aligned parts at once (default 2, at most 4) into one cache file.
    • It splits only while fewer than disk-prefetch-object-split-downloads downloads are in flight (default 8).
    • A read waits only for the part that holds its bytes.
    • Any failed part fails the whole download and nothing is published. This includes an object whose size differs from the size given.
  • Stalls. A download whose source makes no progress for 20 s fails, and the readers waiting on it then read their own ranges.

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

  • Delete vs. publication. A delete and the publication of an entry read before it exclude each other through a per-object lock. Either the delete is counted first and the entry is not published, or the entry is published first and the delete removes it. No read after a delete returns the deleted bytes.
  • Range files. Deleting an object deletes its cached range files. The warm-start loader indexes each range file under the object's delete lock, so a delete during startup removes it. Until then, a read neither returns nor indexes a not yet loaded file of an object deleted since startup.
  • LRU. The eviction budget stays consistent with pending inserts and deletes. An oversized item stays older than later SetOldest items.
  • Policy. A read that skips disk-cache reads is not served from cached ranges.

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).
  • The HTTP pool allows 128 connections per host, up from 100.
  • mo_fs_prefetch_object_total{result} counts prefetches by result: queued, merged, cached, downloaded, failed, missed, ended and dropped.
  • No persisted format changes.

Validation

Setup:

  • Hardware. One CN with MinIO. "Emulated S3" means MinIO behind a proxy that adds 25 ms per request and caps each response at 100 MB/s.
  • Workload. Each run is a cold start, then TPC-H SF10 (all 22 queries), then wiki_all 1M IVF-Flat queries (filter, nofilter, proj).
  • Caches. Partial cache is 1 GB memory and 4 GB disk; full cache is 14 GB memory and 20 GB disk.
  • TPC-C. 10 warehouses, 50 terminals, 5 minutes.

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.

MinIO, parent MinIO, PR Emulated S3, parent Emulated S3, PR
Partial cache, TPC-H (3 pairs) 35.3 32.1 37.4 37.4
Partial cache, wiki filter (3 pairs) 17.3 6.8 35.0 12.9
Full cache, TPC-H 16.1 14.2 17.1 15.1
Full cache, wiki filter 7.5 4.2 12.6 11.8
Full cache, S3 requests 1,820 1,017 1,227 770
TPC-C tpmC 15,904 15,662 15,291 15,502

Column-range reads (MinIO, cold, against 4c4b60d, before column-range scans):

before after
TPC-H SF10 41.8 / 42.0 s, 21 GB fetched 14.1 / 14.3 s, 6.7 GB fetched
Two-cycle TPC-H + wiki, cycle 1 27.0 / 29.5 s 13.9 / 13.5 s
Two-cycle TPC-H + wiki, cycle 2 26.2 / 17.1 s 9.5 / 9.5 s
Two-cycle TPC-H + wiki, wiki filter query 87 / 89 ms 44 / 48 ms
INSERT of duplicate keys into a table with a vector column 29.9 MB fetched 0.15 MB
INSERT of new keys into that table 29.9 MB fetched 0.07 MB
TPC-C tpmC (0 errors) 15,719 / 16,887 15,754 / 15,793

Index join-back (partial cache, 2 rounds, against dc3598b, where only IVF-Flat's join-back was marked):

MinIO, before MinIO, after Emulated S3, before Emulated S3, after
fulltext2 select id, name … match … limit 10, 20 queries 3.42 / 3.23 s 1.32 / 1.33 s 4.17 / 4.31 s 2.14 / 2.48 s
HNSW select id, cat … order by l2_distance … limit 10, 100 queries 1.75 / 1.80 s 1.35 / 1.56 s 2.19 / 2.32 s 1.67 / 1.70 s

Live queue and prefetch objects (MinIO, cold, interleaved, 2 runs each):

before the live queue live queue prefetch objects head (e19f7ab)
TPC-H SF10, cycle 1 14.44 / 13.85 s 12.45 / 12.40 s 12.25 / 13.02 s 13.67 / 12.76 s
TPC-H query 1 1.74 / 1.77 s 1.46 / 1.49 s 1.41 / 1.52 s 1.60 / 1.47 s
Scan of wiki_all reading the vector column (3.1 GB in 150 MB ranges) 4.27 / 4.31 s 2.35 / 2.34 s 2.39 / 2.24 s

Concurrent reads (MinIO, cold, against 349a450, the parent of reads through prefetch objects; wall time in seconds):

parent reads through prefetch objects, first version (d85efb1) head (6db0945)
TPC-H SF10, 8 sessions × 22 queries 66.4 / 68.7 about 80 67.3 / 67.3
4 concurrent scans of the vector column, with 100 IVF-Flat filter queries 4.8–5.5 3.4–4.0
Peak RSS, TPC-H, 8 sessions 7.6–8.1 GB 8.5–9.2 GB
  • 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

  • Each regression test fails without its fix.
  • pkg/fileservice and pkg/objectio pass in a normal run and under -race. disttae and metric/v2 pass under -race, and pkg/sql/compile passes.
  • The new and changed tests pass repeated runs under -race.
  • Planner tests check that each index kind's join-back scan is marked and that the copied full-table scan is not.
  • An end-to-end check filtered and projected varchar columns through the column-prefetched join-back. It returned the same rows as primary-key lookups (32 queries, 0 mismatches).
  • gofmt, vet and golangci-lint are clean.

Limits

  • Few pairs per cell, and the variance between cold runs is large, most of all for TPC-H on emulated S3.
  • Cache swapping. With partial cache, the second cycle swaps each workload's working set back in. Its time depends on which objects the cache happens to keep.
  • Under 8 concurrent TPC-H sessions, peak RSS is about 1–1.5 GB higher than the parent's, within the 10% memory bound of MemoryPrefetchObjects.
  • The prefetcher has no runtime switch. Splitting can be turned off by configuration.

🤖 Generated with Claude Code

cpegeric and others added 6 commits November 7, 2026 07:36
… 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]>
cpegeric and others added 2 commits November 8, 2026 19:53
…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]>
…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 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: 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]>
@cpegeric

Copy link
Copy Markdown
Contributor Author

Both findings of the 2026-11-13 review are fixed in 8aab88e.

P1 — startup indexing vs. delete (pkg/fileservice/disk_cache.go, loadFile)
The loader now indexes each file it finds under the same per-object delete stripe that entry publication holds. If the object was deleted at any time since the cache was created, the file is removed instead of indexed. A delete takes the stripe exclusively before it is counted, so either it finds the file indexed and removes it, or the loader sees the delete and drops the file. Regression: TestDiskCacheLoadDropsRangeFileOfObjectDeletedMeanwhile pauses the loader at a range file, deletes the object meanwhile, and checks the file is neither indexed nor left on disk; it fails without the fix.

P2 — failed range flights reported as downloaded (pkg/fileservice/disk_cache_prefetch_range.go, pkg/fileservice/prefetcher.go)
A flight records why its range was not cached (its read's error or its cache write's), and readRanges returns it once its flights end. prefetchRanges counts that as failed, not downloaded, and logs it. A delete's cancellation of flights still waits for them without turning their cancellation into the delete's error. Regression: TestS3FSColumnPrefetchFailureCountsFailed fails the range read and checks failed +1, downloaded unchanged and nothing cached; it fails without the fix.

Validation: both regressions passed 100 runs under -race, as did the existing delete, flight and close tests; pkg/fileservice passes under -race and normally. TestMinioSDK was skipped locally because it starts its own MinIO, which clashes with a MinIO already running on this machine; it passes when run alone. vet, gofmt and make err-check are clean.

cpegeric and others added 7 commits November 13, 2026 13:27
…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]>
…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]>
@XuPeng-SH

XuPeng-SH commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 9c6b6069590bd64c18ba8f5b0d62e6e3d68e5836

"interrupted"

cpegeric and others added 9 commits November 13, 2026 17:52
…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]>
@XuPeng-SH

XuPeng-SH commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: fed865b79f8eed7afef20940931b5ed7a8d00ee2

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

cpegeric and others added 2 commits November 14, 2026 10:50
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]>
@cpegeric

Copy link
Copy Markdown
Contributor Author

Reply to the mo-bot review of fed865b:

  • P1 disk_cache.go:1770, a delete during the asynchronous warm-cache load misses range files not yet indexed — fixed in e63318a. A read that opens a cache file the cache does not index now reads and indexes it only if its object has no delete counted since the cache was created, the rule loadFile already applies. The check runs under the object's delete lock, so either the delete is counted first and the read treats the file as a miss (the object is read from storage, and the loader later removes the file), or the file is indexed first and the delete removes it. New test: TestDiskCacheReadSkipsUnloadedRangeFileOfDeletedObject, which pauses the loader on a range file, deletes the object, reads that range, and checks that the bytes are not returned, the file is not indexed, and the file is gone once the load resumes. Without the fix the read returns the deleted bytes.

Also in this update: main is merged.

This branch was previously deployed

1 inactive deployment
ci — ead35fb8 Deployed Nov 14, 2026 by cpegeric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants