Skip to content

Spill excess inline files before publishing a CAS manifest - #2969

Open
k-morozov wants to merge 7 commits into
antalya-26.8from
cas-manifest-inline-budget
Open

k-morozov wants to merge 7 commits into
antalya-26.8from
cas-manifest-inline-budget

Conversation

@k-morozov

@k-morozov k-morozov commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

A text-index rebuild can write hundreds of files that are individually small enough for inline placement. When their combined contents exceeded 16 MiB, CAS rejected the manifest after the merge had already built the index. A retry could repeat the entire merge and hit the same limit.

At commit, CAS counts the inline bytes from unchanged base-manifest entries and from the paths being added or replaced. If the total exceeds 16 MiB, it switches the largest eligible entries supplied by the transaction to blob placement until the manifest fits. During writes, an inline candidate such as skp_idx_idx_s.dct.idx spills to a local temporary file as soon as it exceeds 1 MiB, including on disks configured for S3 staging. Smaller files stay in memory. On finalize, CAS trims spare string capacity before transferring their bytes to the transaction. The combined contents of these files can still exceed 16 MiB in RAM before commit. Manifest budget · Spill after 1 MiB · Trim retained capacity

Why the PR keeps partial streaming

We also tested streaming every file to the configured staging backend from the first byte. This reduced the writer's retained memory to 25,232 bytes for 64 small files, but on RustFS with S3 staging it increased both the memory peak and the time needed to rebuild a text index. The PR reverts that experiment. Full streaming · Revert

Peak tracked memory for a one-million-row text-index rebuild on RustFS 1.0.6, from one profiled run per cell in system.part_log. The three columns compare the historical commits before the final string-capacity change.

Operation Staging Budget fix only · C1 Spill after 1 MiB · C2 Full streaming · C3 (reverted)
Merge two 500k-row parts local 350.01 MiB 256.42 MiB 258.30 MiB
Merge two 500k-row parts s3 368.01 MiB 274.40 MiB 324.18 MiB
MATERIALIZE INDEX idx_s, one 1M-row part local 339.53 MiB 245.78 MiB 246.71 MiB
MATERIALIZE INDEX idx_s, one 1M-row part s3 342.52 MiB 248.77 MiB 309.67 MiB

In the separate timing series with S3 staging, median merge duration rose from 149.7 s on C2 to 293.3 s on C3, and median mutation duration rose from 146.6 s to 288.9 s (three runs per cell). Staging small files in S3 added writes and reads during index construction. For example, a proxy trace of the merge counted 818 GETs on C2 and 3,095 on C3. The median paired change was +99% for merge duration and +97% for mutation duration. Peak tracked memory increased by 18% and 26%, respectively, in that timing series. Local-staging timings varied across paired runs. These results rule out streaming every file from the first byte as the default for this PR. CAS streaming benchmark results for Antalya 26.8

Follow-up in a separate PR

The remaining case is one disk transaction that finalizes many files smaller than 1 MiB. For example, 64 index files of 600 KiB each still retain 37.76 MiB before commit after trimming excess capacity. The proposed follow-up gives the transaction a shared 16 MiB memory budget for inline candidates across both open writers and finalized files. Small writes can stay in RAM while space is available. A writer that needs more space spills its current file to local staging. The existing commit-time policy continues to choose inline or blob placement for each manifest. The transaction budget will be developed and benchmarked in a separate PR. The available data contain no paired measurements for that implementation.

Verification

  • All 20 focused tests in CASInlineCapGaps and CASInlineCandidateMemory passed with the final callback, including the exact 16 MiB boundary, one byte over budget, and payload preservation on either side of the 1 MiB spill threshold.
  • The 100-row 05815 test pins LZ4 at the table level. With server defaults of LZ4, ZSTD(1) and ZSTD(3), the merge and mutation each wrote 20 temporary index segments and selected three entries for blob placement. Indexed lookup and CHECK TABLE passed in all three runs. The fixed memory-test translation unit compiled under ASan+UBSan with unreachable-code warnings treated as errors.
  • In the million-row workload, the merge produced 978 temporary text-index segments and the mutation produced 977. Each operation selected 727 entries for blob placement, preserved all rows, and passed the indexed lookup and CHECK TABLE.
  • The final callback was measured in 36 paired blocks of 64 sequential writes to 0.idx through 63.idx (600 KiB each). With the same callback signature, shrink_to_fit() reduced tracked memory before commit from 64.26 to 37.76 MiB in every block. The median paired cost was 1.44 ms (+9.58%) for writing and finalizing all 64 files. This follow-up measured only the writer.

Related: #2441

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

CAS disks can commit merges and mutations whose small files together exceed the 16 MiB manifest inline limit by storing the excess contents as blobs.

Documentation entry for user-facing changes

CAS enforces the existing 16 MiB per-manifest inline limit automatically.

CI/CD Options

Exclude tests:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • Aarch64 tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All Regression
  • Disable CI Cache

Regression jobs to run:

  • Fast suites (mostly <1h)
  • Aggregate Functions (2h)
  • Alter (1.5h)
  • Benchmark (30m)
  • CAS (content-addressed storage; Antalya only)
  • ClickHouse Keeper (1h)
  • Iceberg (2h)
  • LDAP (1h)
  • OAuth (5m)
  • Parquet (1.5h)
  • RBAC (1.5h)
  • SSL Server (1h)
  • S3 (2h)
  • S3 Export (2h)
  • Swarms (30m)
  • Tiered Storage (2h)

Text index rebuilds can produce hundreds of small files whose combined
inline data exceeds the 16 MiB manifest limit. Count inline bytes from
the final paths and store the largest added or replaced files as blobs
until the manifest fits. Include unchanged base entries in the budget
when updating a published part.

Use the existing precommit and blob upload path for spilled files.
Share their payload across upload requests and independent readers.

Co-authored-by: Codex (GPT-6) <noreply@openai.com>
Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [bf97da2]

k-morozov and others added 2 commits November 27, 2026 17:29
Text index files can outgrow the 1 MiB per-file inline limit while a
merge is still writing them. Keeping the entire file in memory until
finalize makes the peak allocation grow with the file size.

Once a write crosses the limit, pass the buffered prefix and subsequent
blocks to the local staging writer. Release the prefix allocation after
the transfer. At finalize, register the staged file for publication
through the existing precommit and blob upload path.

Co-authored-by: Codex (GPT-6) <noreply@openai.com>
Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
Stream new part files to the configured local or S3 staging backend.
Keep the size, content hash and staging handle when a writer closes.
At commit, read the files selected for inline placement and publish the
remaining blobs from staging. Hardlinks, moves and open readers retain
the source until their last reference is released.

Exercise the manifest budget with 100 rows and 20 temporary text index
segments in both a merge and a mutation. Cover multipart staging and
cleanup on RustFS after a successful insert or an injected failure.

Co-authored-by: Codex (GPT-6) <noreply@openai.com>
Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
@k-morozov
k-morozov marked this pull request as draft November 28, 2026 17:10
k-morozov and others added 3 commits November 28, 2026 23:08
This reverts commit 6430520.

Co-authored-by: Codex (GPT-6) <noreply@openai.com>
Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
An inline candidate written in chunks can retain substantially more memory than its payload when the transaction takes ownership. Request a smaller allocation before moving the finalized string into the manifest entry.

Co-authored-by: Codex (GPT-6) <noreply@openai.com>
Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
Pin LZ4 for the text index rebuild so randomized server codecs cannot
make the segment dictionaries fit below the manifest limit. Generate
100 rows across 20 segments and check that both the merge and mutation
still select entries for blob placement.

Exclude the memory measurement at compile time under sanitizers, where
the allocation tracker cannot support the assertion. This avoids Clang's
unreachable-code diagnostic after `GTEST_SKIP`.

Co-authored-by: Codex (GPT-6) <noreply@openai.com>
Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
@k-morozov
k-morozov marked this pull request as ready for review November 28, 2026 23:28
@k-morozov
k-morozov requested a review from filimonov November 28, 2026 23:34
…limit

Randomized dictionary settings can make the 100-row fixture fit within
the manifest budget. Keep the dictionary settings stable and report the
segment and blob-placement checks separately for the merge and mutation.

Use the same per-file inline limit in the writer and the manifest
validator. Include the namespace and ref in the retained-entry limit
error and document staging, the placement counter and failed commits.

CI: https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2969&sha=a2b90dc739fc9e8169a4784148258164f8b191de&name_0=PR
PR: #2969

Co-authored-by: Codex (GPT-6) <noreply@openai.com>
Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant