Skip to content

CAS GC: check the orphan sweep premise before reading refs - #3011

Draft
filimonov wants to merge 5 commits into
antalya-26.8from
work/antalya-26.8/cas-gc-orphan-sweep-premise
Draft

filimonov wants to merge 5 commits into
antalya-26.8from
work/antalya-26.8/cas-gc-orphan-sweep-premise

Conversation

@filimonov

@filimonov filimonov commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

The orphan manifest sweep of a CAS GC round read a table's whole ref log before it checked whether any listed manifest could be deleted at all. On a pool that was not remounted none can, and on S3 that read was 40 s of a 67 s phase. The sweep now checks the key first. A second commit closes a gap in the writer that the sweep's safety rule depends on.

Related: #3000 (this branch is built on its head 8a212b543b62; the two commits of this change are on top)

Changes

  • Sweep: premise before view. The sweep deletes a manifest of a build of epoch E only if (1) the namespace's fold cursor has consumed the seal that closes epoch E, and (2) no record above the cursor names the manifest as a removal target (Gc/CasOrphanManifestSweep.h). Condition (1), with the coverage and hold checks, needs only data the round already has; condition (2) and the ownership check need the namespace's view (ref table recovery and tail walk). The sweep now tests condition (1) first and builds the view only when a key passes, once per namespace per page; then it runs the same ownership check and full premise as before. A refusal is a retain.
  • Sweep: budget. gc_round_sweep_namespace_budget is charged when a view is built. A namespace whose keys are all refused before the view takes no slot.
  • Sweep: metric. retained_before_view in the orphan_sweep row of system.cas_gc_log: keys refused before the view. Their ownership is unknown, so they are not counted in a retained_* class nor as retained debris in the round's summary line.
  • Writer: a precommit does not cross a mount epoch. PartWriteTxn::precommitAdd checked the build's epoch only at entry. A thread that passed the check and stayed descheduled for a whole self-remount could then append a precommit for its old-epoch manifest in the new epoch, after the sweep had deleted that body. The epoch is checked again inside the closure that builds the record, in the namespace's flush. A superseded build gets the typed admission refusal (retry later), and its precommit intent is rolled back.

Risks / notes

  • Sweep verdicts: no key becomes deletable that was retained before, with one intended exception: in a round limited by the namespace budget, a namespace refused before the view no longer consumes a slot, so an orphan of the next namespace can go one round sooner.
  • retained_unconsumed_seal no longer counts unowned manifests of the chain's current epoch when they are refused before a view exists; they are in retained_before_view together with live parts.
  • The orphan sweep still runs inside the phase row fold_reduce; that is why the table below shows fold_reduce getting shorter.
  • Writer cost: per precommit record one atomic load, one compare and one empty test-hook check. No request, lock or I/O added. Allocation and latency were not measured separately.
  • Writer behaviour: a precommit whose closure runs after a newer epoch was published is refused with the same retry-later error the build's next step returns today. Not observed outside a remount; first mount and the epoch's representation were checked.
  • No format change, no new setting. Old and new binaries can alternate as GC leader: the sweep cursor carries no verdict.
  • Not changed: after a remount the sweep still recovers the ref table and walks the tail for namespaces with a key that passes. Sweep planning has no phase row of its own.

Testing

  • Unit gate CAS*, release: 5536 passed. ASan + UBSan: 5534 passed, no sanitizer report. The touched files compile in the Fast test configuration.
  • New sweep tests: a page over a namespace whose manifests are all of the chain's current epoch sends no ref-log GET and no _ckpt read and retains every key; a namespace budget of 1 with a first namespace refused before the view (fails before the change); an uncatalogued namespace before a catalogued one and after the budget is spent.
  • New writer tests: a build parked between the entry check and the append across a full self-remount is refused and leaves no precommit record, no cleanup duty and no pinned build sequence (five tests fail before the change); the path without a remount keeps its request journal.
  • Drain on S3 (eu-central-1), 795 parts, 10341 unique blobs, GC stopped during the load, then GC alone, cas_gc_io_concurrency 48. Seconds per phase from system.cas_gc_log, one run each:
Phase Base 8a212b543b62 This PR
fold_ref_intake 8.9 8.9
fold_reduce, round that condemns 67.0 21.6
manifest_deletes + ref_object_cleanup 6.1 5.9
fold_reduce, round that deletes 10.1 10.1
pending_deletes 13.4 13.3
both rounds 110.8 64.7

Blobs per second of round time: 93 before, 160 after. Wall stacks of the round thread at 20 Hz: 59 % of the base's condemning fold_reduce waits in walkRefChain called from the sweep page; none after. Sweep row after: listed 1000, retained_before_view 1000. Two base runs of this bench differ by 2 %.

Changelog category (leave one):

  • Performance Improvement

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

Content-addressed storage: a garbage collection round no longer re-reads a table's ref log to look for orphan manifests that it could not delete anyway. On S3 a round that condemns blobs is up to 3 times shorter. An insert whose mount was re-established under it is now refused before it writes its precommit record.

Documentation entry for user-facing changes

  • Documentation is written: docs/en/antalya/cas/architecture/garbage-collection.md (retained_before_view).

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)

filimonov and others added 3 commits December 3, 2026 08:18
The reduce reads the `HEAD` of each zero-transition candidate ahead, at
most one window of them. A candidate the merge never takes kept its slot:
one whose blob keeps another edge, or one that already has a condemned row
and settles through its own `HEAD`. After one window of such candidates no
hint was admitted for the rest of the shard and every later `HEAD` ran one
at a time on the round thread. On S3 a round sent 12948 of 28792 `HEAD`s
that way.

Blobs close in strictly ascending order within a shard, so a candidate
below the current one has no later consumer. `topUpHeadHints` now discards
issued hints below the current blob, skips unissued ones below it and keeps
the slot of the current blob; the rest is dropped when the shard ends. The
take site is unchanged.

The `fold_reduce` row of `system.cas_gc_log` gains
`candidate_head_reads_issued`, `_takes`, `_awaited`, `_unhinted`,
`_discarded` and `_wait_us`.

Tests: `CASGCReadAhead.AHintedUnreadyTakeIsAwaited` waited out a 10 s guard
on every run; its read is now released after the take has read its clock,
plus 50 ms. The overlap latch of the stale-candidate tests is a 5 s
watchdog that a second worker ends at once.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The reduce hints three kinds of blob `HEAD`: candidates that may reach
in-degree zero, pending rows before their body delete, and rows whose blob
gained a reference. All three throttled on one count, `pendingHeads`. The
kind that filled the window first kept the others out: a pending row that
found the window full was hinted only when the fold settled it, which is a
serial request the round thread waits for. On GCS 8320 of 16893 pending
rows went that way in one run, and the round thread spent 605 s of a 723 s
`fold_reduce` waiting for `HEAD`s.

`GcReadAhead::pendingHeads(family)` counts the hinted `HEAD`s of one kind
and each hinting site throttles on its own count. The requests the pool
has in flight are bounded by its threads as before; the round thread can
add one inline request of its own.

`CASGCReadAhead.PendingRowsAreHintedWhileUnmergedCandidatesFillTheirOwnWindow`
runs 80 pending rows interleaved with 80 candidates that keep an owner:
1 row is hinted at settle time, 80 with the shared count.

The `fold_reduce` row of `system.cas_gc_log` gains
`pending_head_reads_issued`, `_takes`, `_awaited`, `_hinted_at_settle`,
`_discarded`, `_wait_us`, `intent_creates_awaited`, `intent_create_wait_us`
and `head_discard_wait_us`.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
With the `HEAD` look-ahead fixed, a GC round on a store with a network
round trip is bound by the GC I/O pool: in a drain of a fixed backlog the
pool threads are busy in store requests in every phase. Drain of 11340
unique blobs, blobs per second of round time, at 16 / 32 / 48: S3
50 / 78 / 99, GCS 33 / 54 / 71. A backlog with shared content and two
waves of removals, at 16 / 48: S3 39 / 60, GCS 26 / 52.

On RustFS with fast metadata the gain is 5 to 8 %. On RustFS in its
default `strict` mode, which is bound by its write rate, 16 and 48 give
the same rate (68 and 69 blobs per second) and the same request errors.

`PoolConfig::gc_io_concurrency` follows the setting. A test that measures
request counts at a window of 16 now sets it.

A server that takes the new default sends up to three times as many GC
requests at once; `docs/en/antalya/cas/configuration.md` says how to keep 16.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [39af98e]

@filimonov
filimonov force-pushed the work/antalya-26.8/cas-gc-orphan-sweep-premise branch from 1b5c936 to 8e53f78 Compare December 3, 2026 18:55
filimonov and others added 2 commits December 3, 2026 19:56
The orphan sweep deletes a manifest of a build of epoch E only if
(1) the namespace's fold cursor has consumed the seal that closes
epoch E, and (2) no record above the cursor names the manifest as a
removal target (`Gc/CasOrphanManifestSweep.h`). It built the
namespace's protection view (a ref table recovery plus a second chain
walk) before testing a listed key against either condition. When every
listed build is of the fold cursor's own epoch, condition (1) refuses
all of them, so the view decided nothing; on S3 it took 40 s of a 67 s
phase.

Test condition (1), together with the coverage and hold checks, first:
they need only the sampled coverage. Build the view at the first key
that passes. Condition (2) needs the view and is applied with it. A
refusal before the view is a retain, so no key becomes deletable that
the full premise would retain. Keys that pass go through the same
view, ownership check and full premise as before.

The namespace work budget is charged when a view is built: a namespace
whose keys are all refused before the view takes no slot, so the next
namespace gets the view in the same round. An uncatalogued namespace is
charged at its first key, as before.

Keys refused before the view are counted in the new
`retained_before_view` phase metric, not in a `retained_*` class, since
their ownership is unknown.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`precommitAdd` checked the build's epoch only at entry. A caller could
pass that check, stall across a whole self-remount, and then append an
`AddPrecommit` for its old-epoch manifest into the new epoch. The orphan
sweep assumes a grant never crosses epochs and may already have deleted
that body.

Re-check the epoch inside the closure passed to `appendRefOps`. It runs
in the namespace's flush, after the remount published its epoch, so a
superseded build is refused there with the typed admission refusal and
its precommit intent is rolled back.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@filimonov filimonov added the CAS label Dec 3, 2026
@filimonov
filimonov force-pushed the work/antalya-26.8/cas-gc-orphan-sweep-premise branch from 8e53f78 to 39af98e Compare December 3, 2026 18:57

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.

2 participants