Skip to content

fileservice: cache v2, one range-fill model for the disk and index-file caches - #33544

Open
cpegeric wants to merge 390 commits into
matrixorigin:mainfrom
cpegeric:disk_cache_range_fill_review
Open

cpegeric wants to merge 390 commits into
matrixorigin:mainfrom
cpegeric:disk_cache_range_fill_review

Conversation

@cpegeric

@cpegeric cpegeric commented Nov 30, 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 #33543

What this PR does / why we need it:

Implements file-service cache v2 (docs/design/20261126-fileservice-cache-v2.md): the disk cache and the index-file cache hold immutable range files, filled through one fill registry and one read planner. Two governors own the object-storage connections: the object storage server admits every cache-path request, and a stream governor admits streams.

Behavior

  • A read takes each piece from a cached range of its cache, a running fill holding it, or a new fill; read policy only decides piece boundaries and the kind of fill.
  • Whole-object fills are ranges [0, size); the size comes from the caller, a recorded size, or the first part's response header.
  • A stream (ReadCloserForRead / WriterForRead) is one request of its range whose body the caller reads, as on main: no parts, no read-ahead, no buffers. Streams read through an HTTP transport of their own, sharing the client and credentials of the file service, so they never take the server's connections (max-conns-per-host / concurrency do not count them). At most max(256, GOMAXPROCS × 16) streams are open per process; an open waits for a slot in arrival order, holding nothing. A response body closed before its end is drained for at most 64 KiB within 100 ms, then its request is canceled and its connection dropped (main read the rest), so a stalled body never holds a close or a slot. Stream entries look up the caches as on main and never fill them; a read with several stream entries takes their slots at once, so it never waits on itself.
  • Delete stops the object's fills, makes its cached bytes unreadable before it returns, and has the publisher remove the files; while 512 removals are queued it waits for room to queue its own, until its context ends.
  • A prefetch trusts the cache index and checks no file on disk; a file removed behind the cache is found and refilled by the read that opens it, as on main.
  • Memory charges are freed in the class they were taken in.

Compatibility

  • Cache files with pre-v2 names are removed at startup, so the disk cache starts cold after upgrading.
  • Fix-missing is removed (see decisions); a fix-missing key in the config is ignored.
  • Cached objects are immutable, as on main; a read racing a delete may return "not found" or the deleted bytes, as on main.
  • IsWholeObjectCached = the cached ranges cover the whole object.

Decisions (2026-12-01)

  • A max-conns-per-host / concurrency in a SQL path's s3-opts caps each file service made for that path (as on main, not the whole query), from 1 up to the configured max-conns-per-host; a larger value is rejected.

  • A server's background share is half its room, rounded down; with no share (a room of 1) a background request runs as a foreground one.

  • IndexFileObject never comes with SkipAllCache; a read with both is outside the contract.

  • The object storage server's memory budget has a floor of 128 MiB: a configured object-storage-memory below it is an invalid-input error; a measured budget is raised to it.

  • A range file is named r<offset hex>-<size hex>_<object path>.mofscache: the tag (5 to 35 bytes) lengthens the object path's first component and .mofscache (10 bytes) its last. A component pushed past the file system's 255-byte limit is not cached; the read itself works. A one-component name of up to 210 bytes is always cached (255 - 10 - 35, with the largest tag r7fffffffffffffff-7fffffffffffffff_); for objects under 4 GiB the tag is at most 19 bytes (rffffffff-ffffffff_), so up to 226 bytes. A data object is named <segment UUID>_<5 digits> (42 bytes), for example:

    • a column at offset 128,000, 16 KiB: r1f400-4000_0193c3c6-6b1e-7a2f-9c4d-1a2b3c4d5e6f_00000.mofscache (64 bytes);
    • the largest possible tag: r7fffffffffffffff-7fffffffffffffff_0193c3c6-6b1e-7a2f-9c4d-1a2b3c4d5e6f_00000.mofscache (87 bytes).

Decisions (2026-12-02)

  • The configured room has a floor of 8 (replaces the floor of 64 of 2026-12-01). A max-conns-per-host / concurrency of 1 to 7 is a misconfiguration: a database's scans, index reads, prefetches, fills and writes share the room of its file service, and fewer than 8 requests in flight do not serve them. Startup fails with an invalid-input error naming the setting. A value is never raised: 8 or more is a ceiling honored exactly, as on main; 0 is the default. Upgrade: a configuration with a value from 1 to 7 must be changed first; every other value starts as before.
  • Write part buffers are bounded per process, as on main (NumCPU × 64 MiB), beside each server's own budget; a part that does not fit is read into a temporary file (nobody waits for memory), so file services made per path (ETL) never hold more together than main allowed.
  • A write's copy for the disk cache fits the cache. The copies of all writes of a cache stay within its capacity; a larger one is dropped and the write uploads without caching (main kept the copy in memory, unbounded).
  • Two governors. Streams have connections of their own (reaffirmed 2026-12-03), outside the object storage server, so LOAD, external tables and backups cannot take the connections of scans, and scans cannot stall streams.
  • Fix-missing removed as a buggy feature. It uploaded disk-cache files to object storage as objects with no catalog check and no checksum: it could bring back objects GC deleted (deletes by other processes are invisible to it), upload corrupt cache bytes as objects, and v2's cache rarely holds whole objects, so it restored almost nothing. The setting, -fs-fix-missing and MO_FS_FIX_MISSING are gone; recover lost objects from backup.

Decisions (2026-12-03)

  • The floor of 8 and streams' own connections are reaffirmed. The upgrade side is a step of the stopped-upgrade guide (docs/guides/upgrade-4.2-to-main.md, "File-service configuration"): change a concurrency / max-conns-per-host set from 1 to 7 to 0 or 8+, drop fix-missing, copy the disk cache directory first if its 4.2 files are needed (startup removes them), and make room on each CN for the index-file cache, new since 4.2 (by default 8 GiB in <disk-path>-index-file, apart from disk-capacity).
  • Streams stay outside the object storage server, which makes every other request of its file service (reads and fills, writes, deletes, listings, stats). A write of the caller's reader, of any size, to object storage without multipart upload (HDFS) is a stream: written through the stream storage under a slot of the open stream limit and staged in an HDFS temporary file, as on main, holding no room. A read with a stream entry joins no merged read and no prefetch object, so under every policy a stream makes no request of the server and waits for none.
  • A read takes the slots of its streams at once, after its other entries. Entries that do not stream are read first, so caller code they run may open streams of its own; then one grant covers every stream entry the caches did not serve, passed down explicitly (no longer through the context). An entry with both a WriterForRead and a ReadCloserForRead holds one slot: the writer's stream ends before the other opens and takes it. A stream served from cached bytes holds them until it closes; a stream write takes its slot before anything else, so a waiting write holds no file.
  • A canceled delete past the removal queue bound queues one shared sweep of stale files, or its own removal only while a publication of the object is in flight; the queue stays within its bound plus the sweep.
  • A scan reads the metadata of objects ahead of it off its own path, on one goroutine per scan with a queue of at most one window; the scan's end stops it and waits for it.

Measured (2 CNs, 25 ms / 110 MiB/s link, base = previous head b51e39a):

  • LOAD DATA of a 4.86 GB CSV: parallel 43.9 s vs 44.3 s (main 531–566 s: closing the boundary probes drained the rest of the file, ~51 GB read; now 4.86 GB), serial 74.9 s vs 78.8 s, 16 files 43.5–104 s vs 43 s (one request per stream, as on main's 48–104 s).
  • TPC-H SF100 Q1–Q22: cold 348.7 s vs 349.8 s; warm 215.2 s vs 205.0 s (+5%, being investigated).
  • 8 concurrent LOADs: 80 open streams per process, none waiting.

Validation

  • pkg/fileservice under -race -cpu 1,2,8; new and changed tests -race -count=20 -cpu 1,2,8.
  • Regression tests that fail before their fix: stream slot release on every path, cache reads while all streams are held, streams on their own transports with shared credentials (aws, minio, aliyun, qcloud), Aliyun stream endpoint scheme, early close reads no more than the drain limit, a stalled body closes in bounded time, several stream entries in one read, process-wide write part memory, the disk-cache write copy bound, panicking WriterForRead, a failed download part outside the read's bytes.
  • Dependent packages: external, arrowio, objectio, backup, cmd/mo-service, toolfs, iceberg, datalink.
  • make static-check-changed.

🤖 Generated with Claude Code

cpegeric and others added 30 commits November 24, 2026 18:36
…d ends with its context

A read whose context ends while it waits for a download's bytes returns
its context's error instead of reading on as if the wait timed out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A prefetch, of a whole object or of ranges, that ends with an error after
a delete of its object counted since it was asked for counts as ended,
not failed. A MemoryPrefetchObject classifies a stop when it is failed,
so its tests that fail it directly keep their meaning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ects serve every entry

BC6: DiskCache.Read fails an entry of no bytes with EmptyRange, as the
read of object storage, the index-file cache and the streamed read do,
instead of serving it.
BC7: readIndexObject serves every entry the index-file cache holds,
also those after an entry read to the end of the object, which it leaves
to storage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…across ranges and whole files

A read whose joined prefetch object ended without its bytes, in
prefetchRead and fetchRange, reads them through readCachedBytes from the
smallest cached range holding them, the cached ranges holding them
together, as across the parts of a split run, or the cached whole
object. A read past the end of a cached whole object does not drop it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ads it again

TestS3FSSparseDiskFallbackErrors/short expected the read whose prefetch
object's source ended one byte short to fail with UnexpectedEOF. Under
the approved BC3 that object leaves the read to read the range itself,
and the read's own read of object storage decides: here it reads the
whole range and succeeds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…have published to

S3FS.recheckPublished reads the index-file cache, for an index object,
then the disk cache, after a read joined a queued download or read the
flights. readFromFlights no longer reads the disk cache itself when a
flight ended, which the recheck after it does. No behavior change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he caches again

A read whose own whole-object fill stopped or was skipped, as for an
object another read cached meanwhile, reads the index-file cache and the
disk cache again, through recheckPublished, before it reads its ranges
from object storage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
S3FS.sourcesFor decides, from a read's policy, its context and its
entries, whether it reads the index-file cache, joins the prefetcher's
queued downloads, reads the flights and takes its range read from a
prefetch object. S3FS.Read, joinQueued, read and recheckPublished use it
instead of their own conditions. TestSourcesForTable checks it against
the table of those conditions over every policy. No behavior change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h limit

The test reads 1 MiB past the limit instead of 32 MiB and allows a minute, so it does
not depend on the executor's copy throughput.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…read does

An ExactRead read, like a ColumnPrefetch read, joins a queued prefetch
of ranges holding its bytes, also under SkipFullFilePreloads, as it
already joins the flights reading them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A read under a prefetcher download's context joins neither the flights,
the prefetch ranges of prefetchRead, a prefetch object through
fetchRange, nor a download in the disk cache, as it already joined no
queued download (OP: the reads a prefetch object makes for itself join
no prefetch object).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, fills by SkipCacheWrites

Every site that reads the index-file cache, the read, the recheck, the
prefetch of a cached object and the shared decode's fill, asks
indexObjectReadable; every site that fills it, the fill target, the
whole-object prefetch, the preload decision and the narrow-read
downgrade, asks indexObjectFillable. A fill of an index object never
fills the disk cache: one that skips every cache write fills neither,
and a read of an index object downloads no prefetch range into the disk
cache, also when the index-file cache cannot be written. Red/green:
TestUnwritableIndexCacheKeepsTableCacheSeparate,
TestIndexObjectFillSkippingCacheWrites.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…x-file download

A read of an index object the index-file cache does not hold yet joins
the download of the object into it under way, through readIndexDownload,
also when it skips disk-cache reads, which do not apply to the
index-file cache.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… joins any object

readFromFlights joins, as fetchRange and prefetchRead do, by whether the
read caches its bytes (readSources.caches): one that caches them joins
only prefetch objects that cache theirs, one that caches nothing, such
as a column read that skips disk-cache writes, joins any.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… context ends

A read that joins the download of a FilePrefetchObject, through the disk
cache or a prefetch object, and a read that started one, wait for its
bytes as long as their context allows instead of giving up after the
I/O wait bound and reading them again. A read that joins a whole-object
download keeps the bound. Red/green: TestJoinedFileRangeWaitsForCaller.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e file download

fileDownload returns, of the FilePrefetchObjects holding the read's
bytes, the download of the one whose bytes arrive first, skipping one
that was stopped, instead of the first one registered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s what it published

A read of an index object that joined its download into the index-file
cache, and found the download retired once it published, reads its
entries from the published entry instead of reading object storage.
Found by TestIndexObjectReadSkippingDiskReadsJoinsIndexDownload at -cpu 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…planned it

A block prefetchRead chose to join is joined, when the read copies it,
by the same predicate that chose it, the fastest prefetch object that
caches it within the max extra wait, instead of any covering one however
long its bytes take; a block of a run of the read's own that released
its object on admission is copied from that object while it is
registered, and otherwise from the range it cached. coveringLocked is
removed; its test of a part not begun now checks joinableLocked, under
the approved BC18.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es to split

The check of the downloads in flight against
disk-prefetch-object-split-downloads and the count of the download that
splits are one atomic step (diskCacheDownloads.take), so two downloads
admitted before either registered no longer both split past the limit.
Red/green: TestConcurrentSplitAdmissionAtLimitOne.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… waiting for it

The FilePrefetchObject of a read that declined the download of its range
no longer waits for that download's path owner, which held it until the
declined, slower download ended: when the path is held by a registered
download it downloads the range without publishing it, and the readers
of its own download read it as it arrives. A read whose path owner has
not started a download still waits for it and finds its publication.
Red/green: TestLargeReadPastDeclinedFilePrefetch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…wn reader

An entry a read streams to its caller, through WriterForRead or
ReadCloserForRead, takes its bytes from a shared source that hands them
over once all arrived, a download in the disk cache, an index-file
download, the flights, a queued download, the prefetch ranges of
prefetchRead or fetchRange, only when it is at most
disk-prefetch-memory-max bytes (IOEntry.materializes, part of the
sourcesFor table). A larger or read-to-end streamed entry opens its own
reader, so its caller gets its bytes as they arrive; one within the bound
may now also use fetchRange. Red/green:
TestStreamedEntryPastPrefetchBufferReadsItself (controls: the same reads
skipping disk-cache reads, and an entry within the bound that joins).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TestLargeReadPastDeclinedFilePrefetch, TestSplitCacheReadReturnsWriterError,
TestJoinedFileRangeWaitsForCaller, TestConcurrentSplitAdmissionAtLimitOne
and TestUnwritableIndexCacheKeepsTableCacheSeparate, each of which failed
its target subtest before the fix of its finding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… before its body

TestReadCloserReturnsBeforeReadingBody/eligible_for_range_sharing read a
64-byte ReadCloserForRead entry, which under the approved streaming rule
(at most disk-prefetch-memory-max bytes may take them from a prefetch
object) now shares a range read. The test keeps its meaning with a
prefetch buffer bound below the entry, where the entry opens its own
reader.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s path owner

The FilePrefetchObject of a read downloads without publishing only when,
at its start, a download of its range was under way that the read did
not join; one whose path owner had not started a download waits for it
and reads its publication, as before. The earlier check of a download
registered when the write took the path raced with that owner's
registration (TestFileRangeReadUsesCachePublishedWhileAdmitted at -cpu
1 and 2); 30 runs at -cpu 1,2,8 pass with it and with
TestLargeReadPastDeclinedFilePrefetch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…kCache method

The shared callback runner stays DiskCache.runAsyncUpdateCallback, the recover()
boundary molint's checkrecover allows, now taking the path, entry and callback index.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A read joined to a prefetch flight releases its hold on the flight once its
  bytes are copied into the entry, before the entry's decoder runs.
- The four-block cutoff of the local data source only disables whole-object
  prefetch; a column-prefetch scan of fewer blocks prefetches its column
  ranges ahead and on entering each object, as the remote data source does.

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

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: b51e39a2c5dc73af995e42e5454b2ec9ed35da80

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

Assessment: request_changes

The cache and admission redesign consolidates existing file-service responsibilities, but it leaves complete v2 cache files unavailable to restart recovery and permits stream buffers to grow outside the storage server's limits. The earlier concerns about legacy-file restoration and unbounded disk-spooled read streams were addressed.

Model: gpt-6.1-terra / max

Session: 01a22aff-bb68-7e31-ae71-ee4ab48ad9d0 · slot 0 · generation 45

  • P1 pkg/fileservice/s3_fs_restore.go:329: A complete v2 whole-object cache file survives a restart after its object has gone missing from object storage, with fix-missing enabled.
    Impact: The startup restore does not recover the object, even when the cache holds its complete contents. The object remains unavailable, and its last cached copy can subsequently be evicted.
    Evidence: The restore enumerates cache.prefetched, but object sizes are held only in memory and are not reconstructed when range files are loaded. The review-contract-tests.log probe prefetched a whole object, removed its backend copy, restarted the service and received 'file obj is not found'; its legacy-file control passed. The design acknowledges this limit, but it weakens the existing fix-missing recovery behavior. Persist and reload a reliable whole-object completeness or size marker and use it for startup restoration.

  • P1 pkg/fileservice/s3_fs.go:2563: Many callers open or slowly consume object streams, such as concurrent LOAD DATA readers.
    Impact: Each live stream can retain up to two 4 MiB buffers until close. Those buffers are neither charged to object-storage-memory nor bounded by request room after their part requests finish, so aggregate memory can grow with the number of open streams and exhaust CN memory.
    Evidence: In review-contract-tests.log, a one-slot test server with a one-byte memory budget retained 12 MiB across three open streams while holding no request room. The prior storage semaphore held a permit until the reader reached an error or closed; the new per-part lifecycle releases it while the stream retains its buffers. Bound aggregate stream-owned memory while preserving progress for slow readers, and cover multiple open streams under memory pressure.

Validation:

  • The supplied isolation preflight and retained native-input provenance check passed; receipts 1796162655801733815-3.json and 1796162656083772533-33.json.

  • Focused file-service tests passed under the race detector; receipt 1796163400270967779-3.json and focused-race.log.

  • Selected planner, scan, object I/O and vector-index tests passed; receipt 1796163554605690343-3.json and dependent-tests.log.

  • The recovery and stream-memory review probes ran against the frozen head. Their combined command exited 1 because the v2 restart-recovery assertion failed; the legacy recovery control passed and the stream-memory probe recorded the unbounded retention. Receipt 1796162966028521616-3.json and review-contract-tests.log.

Limitations:

  • A passing object I/O test logged 105094 outstanding mpool bytes at teardown, so that run is not evidence of leak-free operation.

  • Live cloud-provider, full BVT, multi-CN and performance runs were not independently performed; the supplied local validation evidence was empty.

cpegeric and others added 3 commits December 2, 2026 14:15
…issing

Streams (ReadCloserForRead / WriterForRead) no longer read through the
object storage server. Each stream is one request of its range, as on
main, over an HTTP transport of its own that shares the file service's
client and credentials, so streams never take the server's connections.
At most max(256, GOMAXPROCS*16) streams are open per process; an open
waits for a slot in arrival order, holding nothing. A read has at most
one stream entry. Stream entries look up the caches and never fill them.
This removes the 4 MiB part buffers that grew with the number of open
streams.

A response body closed before its end is drained for at most 64 KiB,
then its connection is dropped, instead of being read to its end.

Fix-missing is removed: it uploaded disk-cache files to object storage
as objects without a catalog check or checksum, so it could bring back
objects GC deleted and upload corrupt cache bytes, and the v2 cache
rarely holds whole objects. The range-file naming that existed only for
it is removed with it.

Also:
- the object storage server's memory budget has a floor of 128 MiB;
- Aliyun streams use the server's normalized endpoint (https);
- a WriterForRead that panics frees its stream;
- a read that starts a whole-object download and loses its bytes to a
  failed part outside them reads its own range instead of failing;
- pathForIOEntry builds the path without fmt.

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

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 447b53699c4bd49513687bc87bee75f6b134f312

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: 447b53699c4bd49513687bc87bee75f6b134f312

Assessment: request_changes

The cache consolidation reuses coherent fill and publication owners, but the new stream lifecycle, upload-memory accounting, and write staging leave material resource failures. The change also narrows the FileService read contract and needs to resolve compatibility for retained connection limits. Earlier findings about read-side disk spooling and per-stream part buffers were superseded by the direct-stream design.

Model: gpt-6.1-terra / max

Session: 01a23642-a5da-74a3-9479-4bd000540084 · slot 0 · generation 54

  • P1 pkg/fileservice/s3_fs.go:2569: A caller closes an S3 stream early after the provider has sent headers but stops delivering body bytes.
    Impact: Close can wait indefinitely for the provider before canceling the request or releasing its process-wide stream slot. Enough stalled closes prevent streams from opening through unrelated, healthy file services until the bodies resume or their contexts are independently canceled.
    Evidence: The AWS body close calls drainAndClose, which synchronously reads up to 64 KiB; the HTTP transport has a response-header timeout but no body deadline. endLocked calls body.Close before cancel and openStreams.release. The source-extracted stalled-body probe retained the slot, while its merge-base close-order control released the permit. Make cancellation and cleanup independent of further body progress, while preserving the open-stream bound.

  • P1 pkg/fileservice/s3_fs.go:759: A streaming write uses a shared S3 file service with disk caching enabled, for example an export to shared storage.
    Impact: The temporary cache copy grows with the entire input without reserving or checking disk-cache capacity. A large or slow write can fill the cache filesystem and cause unrelated operations sharing that volume to fail with ENOSPC.
    Evidence: The new cacheCopy receives every uploaded byte until the write returns; neither its creation nor Write consults disk capacity, and a failed copy is retained until cleanup. A source-extracted probe wrote 4 MiB against an illustrative 1 MiB cache limit. Bound or abandon the optional cache copy when it cannot be admitted, without failing the object upload.

  • P1 pkg/fileservice/object_storage_server.go:471: Many concurrent streaming exports use separate dynamically constructed S3 file services, including with MO_ETL_PARALLEL_MODE=auto.
    Impact: Each service independently admits upload buffers against a minimum 128 MiB budget, even when measured memory headroom is exhausted. Aggregate retained parts can exceed process memory and cause an OOM.
    Evidence: GetForETL constructs a new S3FS and server per argumented path, and writeParts takes 64 MiB parts from that server's private accounting. The merge base instead used a process-wide parallel-upload buffer budget of NumCPU times 64 MiB. In a source-extracted admission probe, eight independent servers each admitted a 64 MiB part with simulated zero headroom. Restore a process-wide bound or equivalent aggregate admission while retaining service-level isolation.

  • P2 pkg/fileservice/object_storage_arguments.go:231: A deployment retains a file-service configuration with a positive max-conns-per-host or concurrency below 64.
    Impact: The new binary rejects the configuration during S3FS construction, so an affected service cannot start after upgrade.
    Evidence: The local v4.2.8 tag accepts these fields and applies positive concurrency as a semaphore capacity; the pinned upgrade policy requires supported retained configuration files to remain readable or be migrated. The current v4.2.9 release and applicable hotfix artifacts were not available locally, so the exact supported source boundary remains unverified. Preserve the old values or provide a migration, and verify it against the applicable released source.

  • P2 pkg/fileservice/s3_fs.go:946: A FileService.Read vector contains two streaming entries, such as a ReadCloserForRead and a WriterForRead for different ranges.
    Impact: S3FS now rejects a vector that the common FileService contract and the merge-base cross-backend test accepted, even when all requested bytes are cached. Callers using the shared interface must change behavior specifically for this backend.
    Evidence: The prior common test issued the mixed vector in one Read and checked both results. The PR replaces that call with readStreamsApart for S3FS and adds a test expecting rejection, while the FileService interface still promises to fill its entries. Preserve the existing vector contract and its direct-read oracle while preventing a read from deadlocking on its own stream slots.

Validation:

  • The private /tmp and loopback preflight passed: checks/1796231437368711018-6.json.

  • Source-extracted Go probes completed for stalled stream close, per-service memory admission, and cache-copy staging: checks/1796231694812395328-3.json, checks/1796232391837196564-3.json, and checks/1796232497848834708-3.json. The close probe included a merge-base ordering control.

  • checks/1796232506922942679-4.json and probe-provenance.log verified the extracted methods against the clean frozen checkout and checked the merge-base close order.

  • review-plan.md and discussion-assessment.json were saved in the diagnostic directory; the assessment covers all 10 indexed discussion keys.

Limitations:

  • The selected pkg/fileservice test did not compile: the installed Go 1.26.6 is older than the required Go 1.27.1, and toolchain download timed out. This is an environment limitation, not a product-test pass or failure.

  • The probes use extracted owner code and stubs; they are not full public-entrypoint, live-provider, race, integration, or performance tests.

  • The current v4.2.9 release and applicable hotfix artifacts could not be independently verified for the configuration upgrade boundary.

…floor of 8

- A response body closed before its end is drained for at most 64 KiB within 100 ms,
  then its request is canceled, so a stalled body holds neither Close nor a stream slot.
- Write part buffers are bounded per process (NumCPU x 64 MiB, as on main) beside each
  server's budget; a part that does not fit is read into a temporary file.
- The disk-cache copies of writes stay within the cache's capacity; a larger copy is
  dropped and the write uploads without caching.
- A read with several stream entries takes their slots at once; main's mixed-vector
  file service test is restored.
- A streamed entry with ToCacheData gets its cached data, as on main.
- max-conns-per-host / concurrency have a floor of 8 (decision, replaces 64).

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

cpegeric commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 7ceb439. Each fix has a regression test that fails before it.

  • P1 s3_fs.go:2569, a stalled body blocks Close. Fixed. A response body closed before its end is drained for at most 64 KiB within 100 ms (maxDrainWait), then its request is canceled and the connection dropped. The bound is in drainAndClose, used by the AWS, MinIO and Aliyun read paths, so it covers streams and cache reads alike. Test: TestStreamClosedEarlyOnAStalledBody. Without the bound, Close of a stalled body is still blocked after 5 s. With it, Close returns, the slot is freed, and a body that keeps flowing is still drained so its connection is kept.
  • P1 s3_fs.go:759, the write's cache copy grows without bound. Fixed. The disk-cache copies of all writes of a cache stay within its capacity. A copy that would pass it is emptied and dropped, and the write uploads without filling the cache and does not fail. (Main kept this copy in memory, unbounded.) Test: TestWriteCacheCopyFitsTheCacheCapacity, where a 4 MiB write into a 1 MiB cache never copies more than 1 MiB, and a 512 KiB write is still cached.
  • P1 object_storage_server.go:471, per-service upload budgets. Fixed. Write part buffers are now also bounded per process at NumCPU × 64 MiB, main's bound, beside each server's own budget. A part that does not fit both is read into a temporary file, so nothing waits for memory, and file services made per path (ETL) never hold more part buffers together than main allowed. Test: TestUploadPartBuffersFitTheProcess.
  • P2 s3_fs.go:946, two stream entries in one read. Fixed: the vector contract is restored. A read with several stream entries takes a slot for each in one FIFO grant before it reads, so it never holds some slots while waiting for others and cannot wait on itself. Only a read with more stream entries than the whole limit (at least 256) is rejected. Main's cross-backend test calls fs.Read on the mixed vector again, unchanged. Tests: TestReadSeveralStreamEntries and TestReadSeveralStreamsTakeSlotsAtOnce, which cover waiting without holding a slot, FIFO order behind it, and freeing every slot when the second open fails.
  • P2 object_storage_arguments.go:231, configs below 64. Recorded decision (2026-12-02, design doc "The configured room has a floor of 8"; replaces the floor of 64):
    • 1 to 7 is a misconfiguration. A database's scans, index reads, prefetches, fills and writes share the room of its file service, and fewer than 8 requests in flight cannot serve them. Startup fails with an invalid-input error naming the setting.
    • A value is never raised to the floor. 8 or more is a ceiling honored exactly, as on main, so the "configured maximum is raised" concern from the earlier round does not apply either.
    • Upgrade: only a configuration with a value from 1 to 7 must be changed before upgrading; every other value starts as before.

Also fixed from our own review: a streamed entry with ToCacheData gets its cached data from its Data, as on main (TestStreamedEntrySetsCachedData).

Validation: pkg/fileservice/... passes under -race at -cpu 1,4,8, and make static-check-changed reports 0 issues.

cpegeric and others added 2 commits December 2, 2026 21:39
…ot serve

A read with several stream entries took a slot for each before its cache lookup, so a
read whose stream entries were all cache hits waited for slots it never used. The slots
are now taken at once when the read goes to object storage, for the stream entries still
undone.

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

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 595fb0d53e6f05e0ab53519814b0da3b13badee0

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: 595fb0d53e6f05e0ab53519814b0da3b13badee0

Assessment: request_changes

The unified range-fill and publication owners have a coherent purpose, and the latest stream-close, cache-copy, upload-memory and multi-stream fixes pass focused checks. Six issues remain: unbounded local staging for streamed HDFS writes, two retained-configuration compatibility regressions, a stream connection-limit bypass, unbounded canceled cleanup work, and synchronous metadata reads ahead of cold projected scans.

Model: gpt-6.1-terra / max

Session: 01a237df-a073-7910-ac2c-836d2d273b8a · slot 1 · generation 43

  • P1 pkg/fileservice/s3_fs.go:934: An unknown-length streamed write uses HDFS, such as an export through an argumented hdfs file service, or another non-multipart backend receives ReaderForWrite.
    Impact: The whole input must now fit in local temporary storage before it reaches the backend. A large or concurrent export can exhaust the node volume, and unavailable scratch space makes the export fail even when the backend is healthy.
    Evidence: writeObject copies the reader into an unlinked local file for every non-multipart, non-disk backend. HDFS.Write already streams to an HDFS temporary file before renaming it, and the merge base sent the reader directly to storage. A current-head FileService.Write probe with a non-multipart wrapper failed on an unavailable TMPDIR while the wrapped backend write succeeded (focused-and-probes-v2.log, receipt 1796254478063508873-3.json). Restore bounded streaming for this path, reusing backend staging where appropriate.

  • P2 pkg/fileservice/disk_cache.go:289: A stopped 4.2 deployment upgrades with fix-missing enabled while its old disk cache holds a complete legacy file for an object missing from the backend.
    Impact: The retained recovery setting is ignored and startup deletes the legacy file, removing a locally available recovery input before an operator can inspect it. Deployments relying on the former option no longer receive its best-effort recovery behavior.
    Evidence: The annotated v4.2.8-hotfix-20261114 tag defines fix-missing and invokes restoreFromDiskCache; its whole-object files use the full.mofscache layout. Current Config removes the setting and loadFile unlinks that layout; TestDiskCacheOldLayoutFilesAreRemovedAtStartup passes while asserting removal. The pinned 4.2-to-main guide and upgrade policy cover retained configurations. Recognize this upgrade case and preserve a safe recovery or explicit migration path before deleting the input; automatically uploading unverified stale cache bytes is not required.

  • P2 pkg/fileservice/object_storage_arguments.go:231: A supported 4.2 deployment retains a file-service configuration with concurrency or max-conns-per-host set to a positive value from 1 through 7.
    Impact: NewS3FS rejects the previously valid configuration, so the affected service cannot start after a stopped upgrade.
    Evidence: The v4.2.8-hotfix-20261114 source accepts positive values and applies them as limits; current TestRoomBelowMinimumIsRejected confirms the new rejection. The pinned upgrade policy requires retained supported configuration files to remain readable or be migrated. Honor the existing values or provide an applicable migration; the author’s floor decision alone does not change that contract.

  • P2 pkg/fileservice/s3_fs.go:160: A file service or SQL s3-opts path has an explicit per-host or request limit and concurrently opens streaming reads.
    Impact: Streaming responses use a separate transport sized to the process-wide stream limit, outside the configured per-service ceiling. A constrained object-storage endpoint can receive more connections than its operator configured.
    Evidence: openStream calls s.streams directly, while streamStorage uses openStreams.limit() rather than the configured room. A public FileService.Read probe against a local HTTP S3 endpoint configured for 8 observed 9 simultaneously open streams (stream-cap-probe.log, receipt 1796254659432141875-3.json). Honor the explicit aggregate ceiling across stream and ordinary traffic while arranging admission to retain forward progress.

  • P2 pkg/fileservice/disk_cache_async.go:495: A delete batch is canceled or times out while publisher workers are delayed and the 512-entry removal queue is full.
    Impact: The canceled-context branch enqueues every remaining distinct removal without a bound. Repeated timed-out batches can retain an unbounded number of paths and closures and prolong shutdown or exhaust memory.
    Evidence: DiskCache.DeletePaths calls removeLater for every path even after cancellation; the GC deleter uses timed batches of 1,000 paths. In a gated public Delete probe the live-context control stayed bounded, but cancellation left 2,560 removals queued against the 512 limit (focused-and-probes-v2.log, receipt 1796254478063508873-3.json). Bound canceled cleanup while preserving invalidation, ordering and eventual removal.

  • P2 pkg/vm/engine/readutil/datasource.go:228: A projected-column scan starts with cold metadata across many distinct objects; the planner assigns ColumnPrefetch to subset-column scans.
    Impact: Before returning its first block, the scan synchronously reads metadata for each object in a window of up to 1,000 blocks. Cold scans can experience a large time-to-first-row regression, including when little of the scan is consumed.
    Evidence: PrefetchColumns calls ColumnRanges, which calls FastLoadObjectMeta synchronously, inside the scan loop; the merge base did not perform those future metadata reads on this path. In three equal-work current-head cold controls with 40 one-block objects and an injected 3 ms read latency, the first-block control performed 1 read in 3.5–3.9 ms, while the projected path performed 40 reads in 134–136 ms (prefetch-repeat.log, receipt 1796255270311547850-3.json). Move future metadata resolution into bounded prefetch work, or otherwise let the current scan advance without waiting for unrelated future objects.

Validation:

  • Private /tmp and loopback preflight passed; the native-input ledger matched 196 checkout inputs and the usearch dependency (preflight.log, native-provenance.log; receipts 1796253876846256294-3.json and 1796253957587432108-4.json).

  • Selected current-head file-service tests passed without overlays, including the author’s stream-close, cache-copy, upload-budget and multi-stream regressions (focused-clean-v2.log; receipt 1796254875578807404-3.json).

  • Selected readutil, disttae, planner and external-reader tests passed (dependent-focused.log; receipt 1796255221048089275-3.json). Selected cache-fill, delete and stream lifecycle tests passed under -race -cpu=1,4 (focused-race.log; receipt 1796255537838097220-3.json).

  • The intentionally failing non-multipart-write, canceled-queue and stream-ceiling probes include controls and have retained logs and matching exit-1 receipts. The repeated cold-metadata control passed while recording the latency and read-count contrast.

  • All receipts report the assigned head and an empty source delta. The review plan and complete discussion assessment are saved in the diagnostic directory.

Limitations:

  • No live HDFS service, cloud provider, multi-CN integration suite or full workload benchmark was run. The HDFS write probe uses a non-multipart wrapper; source tracing establishes that HDFS reaches the same path.

  • The metadata timing uses injected per-read latency at the real scan entry point, not a production query benchmark. The supplied author validation has no retained command logs; its broader race and static-check claims were not independently reproduced.

  • The 4.2-to-main upgrade guide and an annotated v4.2.8 hotfix tag are available locally. The supplied v4.2.9 release and other applicable hotfix artifacts were unavailable for independent inspection; no claim is made that v4.2.8 is the latest release.

cpegeric and others added 3 commits December 3, 2026 08:43
…ch column metadata off the scan

- A write of unknown size to object storage without multipart upload (HDFS)
  streams the caller's reader in one request, as on main, instead of staging
  the whole write in a local temporary file.
- A delete whose context ended past the removal queue bound queues one sweep
  of stale files, or its own removal while a publication of the object is in
  flight, so canceled deletes no longer grow the queue without bound.
- Column-range prefetches of objects ahead of a scan read their metadata on a
  bounded per-scan goroutine that the scan's end stops and waits for, so the
  scan never waits for metadata of objects it has not entered.
- TestS3FSColdLockReadDoesNotFillDisk waits for fills to go idle between reads.
- Design doc and the 4.2 upgrade guide record the file-service upgrade steps
  and the reaffirmed floor and stream-pool decisions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ll_review

# Conflicts:
#	pkg/fileservice/qcloud_sdk_close_test.go
- A write of unknown size to object storage without multipart upload (HDFS)
  is a stream: it is written through the stream storage under a slot of the
  open stream limit and holds no room of the server, so a caller whose reader
  reads the same file service cannot hang it.
- A read with a stream entry joins no merged read, so a stream never waits for
  a request of the server under any policy.
- A canceled delete counts only publications, not waiting removals, when it
  decides between its own removal and the shared sweep, so the removal queue
  stays within its bound plus the sweep.
- Drop a duplicate import left by the merge of main.
- Design doc: streams include those writes and join no merged read; correct
  the upgrade step wording.

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

cpegeric commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 3b91048. Each code fix has a regression test that fails before it.

  • P1 s3_fs.go:934, an HDFS streamed write staged locally. Fixed. A write of unknown size to object storage without multipart upload (HDFS) is a stream, as on main: it is written through the stream storage under a slot of the open stream limit and staged in an HDFS temporary file. It never goes through the object storage server and holds no room, so a caller whose reader reads the same file service (an export to SHARED) cannot hang it. Tests:
    • TestWriteWithoutPartsStreams: an unavailable TMPDIR no longer fails the write.
    • TestWritesWithoutPartsHoldNoRoom: as many piped writes as rooms, each fed by a read of the same file service, finish; holding a room per write, they hung.
  • P2 disk_cache_async.go:495, canceled deletes queue past the bound. Fixed. A delete whose context ended while the removal queue is full queues one shared sweep of stale files, or its own removal only while a publication of the object is in flight. So the queue stays within its bound plus that sweep, and the bytes stay unreadable before the delete returns. Tests: TestCanceledDeleteRemovalsStayBounded (disk and index caches, 1,024 queued before the fix) and TestCanceledDeletesBehindWaitingDeletesShareTheSweep (earlier deletes waiting to submit are not publications).
  • P2 readutil/datasource.go:228, metadata ahead of a cold projected scan. Fixed. The metadata of objects ahead of the scan is read on one goroutine per scan, with a queue of at most one window; the scan's end stops it and waits for it. The scan reads only the metadata of the object it enters. The local data source had the same pattern and is fixed too. Test: TestRemoteDataSourceDoesNotWaitForMetadataAhead (first block and close, while the metadata of the objects ahead is held).
  • P2 s3_fs.go:160, stream connections outside the configured ceiling. Recorded decision, reaffirmed 2026-12-03 (design doc, "Streams have connections of their own"). The object storage server governs the cache path; streams are governed by the stream governor, with a connection pool of their own sized to the open stream limit, and do not count toward max-conns-per-host or concurrency. We also checked that streams reach object storage only through that pool. Under every policy, a stream makes no request of the server and waits for none: it joins no merged read and no prefetch object (TestStreamsStayOutsideTheServer; the merged-read wait was fixed in this push).
  • P2 object_storage_arguments.go:231, 4.2 configs with 1 to 7. Recorded decision, reaffirmed 2026-12-03 (design doc, "The configured room has a floor of 8"). The upgrade side is now a step of the pinned stopped-upgrade guide: docs/guides/upgrade-4.2-to-main.md, "File-service configuration", says to change a concurrency or max-conns-per-host set from 1 to 7 to 0 or to 8 or more before starting the new version. The upgrade policy allows a retained configuration to be read "directly or through an upgrade step".
  • P2 disk_cache.go:289, legacy whole-object cache files with fix-missing. Recorded decision ("Fix-missing removed", 2026-12-02): fix-missing wrote unverified cache bytes as objects and is removed; lost objects are recovered from backup. The same upgrade-guide section now tells operators that the new version removes the 4.2 cache files at startup, and to copy the cache directory first if they want them.

Also fixed: TestS3FSColdLockReadDoesNotFillDisk failed in CI once. A read can join the range fill the previous read is still publishing, as the #33615 decision allows, so the test now waits for fills to end between reads.

Validation: pkg/fileservice/... under -race at -cpu 1,4,8, pkg/vm/engine/readutil/... under -race, pkg/vm/engine/disttae/..., and make static-check-changed with 0 issues.

cpegeric and others added 5 commits December 3, 2026 09:39
- A read reads its entries that do not stream first, then takes one grant for
  its stream entries and passes it down, instead of carrying the reservation
  in the context; caller code of the other entries may open streams of its
  own.
- An entry with both a WriterForRead and a ReadCloserForRead holds one slot:
  the writer's stream ends before the ReadCloserForRead stream opens and
  takes it.
- A stream served from cached bytes holds them until it closes.
- A write that is a stream takes its slot before it creates its disk-cache
  copy, so a waiting write holds no file.
- A read rejected for too many stream entries empties its outputs first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ll_review

# Conflicts:
#	pkg/pb/plan/plan.pb.go
…s buffer

When a read fails after a stream took an entry's cached bytes, closing the
stream returns the buffer; the entry now drops its reference too, so a retry
allocates its own buffer instead of writing into the returned one.

Design doc: when several entries fail, a read returns the error of the first
entry it reads, the entries that do not stream first.

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

This branch had an error being deployed

1 failed deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants