Skip to content

Add a configurable interval between CAS orphan manifest sweeps - #2800

Merged
filimonov merged 23 commits into
antalya-26.8from
feature/cas-orphan-sweep-scheduling
Nov 24, 2026
Merged

filimonov merged 23 commits into
antalya-26.8from
feature/cas-orphan-sweep-scheduling

Conversation

@k-morozov

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

Copy link
Copy Markdown
Collaborator

Each eligible GC fold previously planned a page of the orphan-manifest sweep. Planning may replay a namespace's ref log to reconstruct ownership even when every listed manifest still has an owner.

The new disk setting cas_orphan_manifest_sweep_interval_sec sets the wait between complete traversals (default 3600 seconds). A nonempty manifest_sweep_cursor lets the next ordinary fold continue the current traversal without waiting. An interval of 0 allows a page on every eligible fold. A cas_manifest_sweep_list_budget_keys of 0 pauses the sweep and preserves its cursor.

The schedule controls when a fold can list cas/manifests/. The GC still decides whether to fold from ref-log changes, blob deletion work (pending or standing rows, or a candidate due for an intent), and the ordinary deferral limit. With default thresholds an idle pool defers eight invocations before folding. An unsuppressed fold can still list blob-intents/ and commit its independent intent_sweep_cursor while the manifest sweep waits.

The round publishes the manifest cursor and the new orphan_manifest_sweep_completed_at_ms field in the same conditional update of gc/state. Reaching the end of the key space records completion before physical deletion. Suppression and a failed state precondition preserve the last accepted progress. Lease renewal and takeover preserve the schedule. A successful rebuild resets it. A generation 4 leader can read state written before the completion field existed. If a leader without the setting rewrites that state, the cursor survives and the completion time becomes unknown. The shared decimal UInt64 reader now rejects overflow.

With a known completion time, a positive interval and an empty cursor, a clock reading of zero keeps the sweep waiting. If the saved time is ahead of a positive clock reading by exactly one interval or less, the leader waits. A larger gap permits a fresh traversal on an ordinary fold. A zero reading at commit preserves the previous timestamp while accepting cursor progress.

The defer_decision phase metric run_orphan_manifest_sweep reports eligibility even on deferred rounds. The post-commit orphan_sweep phase reports orphan_manifest_sweep_page_listed and orphan_manifest_sweep_completed separately from the number of physical deletions.

Local verification at aebec330e50f: all 879 focused C++ tests passed across 82 suites, including the empty ref-log case and blob-intent sweep progress while the manifest sweep waits. The stateless scheduling test 05814 passed through Praktika (1/1). Across two successive folds, only the first listed a manifest page with the default interval. Both folds listed a page with interval zero. Both configurations retained the inserted rows and reported zero dangling references.

Changelog category (leave one):

  • Performance Improvement

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

Added the cas_orphan_manifest_sweep_interval_sec setting to control when a new CAS orphan manifest sweep starts after the previous traversal completes.

Documentation entry for user-facing changes

Updated the CAS configuration and garbage-collection architecture documentation.

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)

Describe the hourly interval, accepted traversal progress and bounded
retries after suppression. Explain the settings and phase metrics in
the operator and format documentation.

Context: https://gist.github.com/filimonov/1b96ea358804b1c6e22c45380cc65469
Signed-off-by: Konstantin Morozov <[email protected]>
Cover clock boundaries, legacy state, page progress, round adoption,
retry pacing and recovery. Use explicit zero intervals in fixtures
that need successive orphan sweeps, including `CASWriterDuties`.

Add a stateless test for the default and zero interval through manual
GC rounds, with data and FSCK checks.

Context: https://gist.github.com/filimonov/1b96ea358804b1c6e22c45380cc65469
Signed-off-by: Konstantin Morozov <[email protected]>
Add `cas_orphan_manifest_sweep_interval_sec` with a default of 3600.
Persist traversal progress with the round state CAS and continue active
pages without the interval wait.

Use generation-scoped local retry pacing after committed suppression.
Keep ordinary fold triggers and destructive checks unchanged.

Validation: release build, 77 focused C++ tests and the scheduling
stateless test through Praktika.

Context: https://gist.github.com/filimonov/1b96ea358804b1c6e22c45380cc65469
Signed-off-by: Konstantin Morozov <[email protected]>
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [aebec33]

@filimonov filimonov mentioned this pull request Nov 15, 2026
2 of 31 tasks
A manifest LIST failure aborts a due sweep before the round CAS. The
generation stays unchanged, so every idle GC invocation forces another
full fold while the failure persists.

Record the adopted parent generation when page planning throws, then
propagate the exception. The existing bounded fold deferral paces idle
retries; changed refs and due graduations can still force a fold. Sweep
progress remains tied to a successful round CAS.

Strengthen the lost-CAS test with an eligible orphan and a successful
control that deletes the same manifest shape.

Tests: 88 focused C++ tests passed.
Signed-off-by: Konstantin Morozov <[email protected]>
An unfinished traversal already has a durable `manifest_sweep_cursor`. Use it
to continue the sweep and keep only the last accepted completion time in
`gc/state`. This removes redundant active and start fields while preserving
the hourly interval after a completed traversal.

Validate the cursor and EOF transition in both directions, retain legacy
state decoding, and reject overflowing decimal UInt64 strings. Update the
schedule, GC, codec, and documentation tests for the single-field state.

Signed-off-by: Konstantin Morozov <[email protected]>
@k-morozov
k-morozov marked this pull request as ready for review November 17, 2026 16:42
Signed-off-by: Konstantin Morozov <[email protected]>

# Conflicts:
#	docs/en/antalya/cas/architecture/garbage-collection.md
The initial orphan sweep now forces a fold on a fresh pool. Disable it in the deferred-round logging fixture so the test continues to prove that a deferred leader round establishes GC health and emits no completion log line. The first-fold and waiting-defer cases are covered by the orphan sweep schedule tests.

Signed-off-by: Konstantin Morozov <[email protected]>
@k-morozov k-morozov changed the title CAS orphan sweep scheduling Add a configurable interval between CAS orphan manifest sweeps Nov 18, 2026
k-morozov and others added 2 commits November 18, 2026 12:27
Cover the selector's precedence when a traversal is disabled or already
active, and exercise retry behavior after a failed page plan. Verify
that an unrelated fold or a fresh GC instance re-enables the sweep's
fold requirement. Pass the sweep decision explicitly in the defer
predicate tests and assert the new phase metric name.

The metric assertions are expected to become green with the following
naming change.

Related: #2800

Co-authored-by: Codex (GPT-6) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>
A due sweep prevents an otherwise idle GC round from deferring, but the
old `force_orphan_manifest_sweep` name suggested that it forced the sweep
itself. Rename the decision and its `defer_decision` phase metric to
`orphan_manifest_sweep_requires_fold`, and require callers of
`shouldDeferRound` to supply it explicitly.

Name the leader-local generation marker for the forced-fold suppression
it records. Document how a failed page plan or a safety hold suspends
that requirement for the adopted snapshot generation while other fold
triggers and bounded retries remain available.

Related: #2800

Co-authored-by: Codex (GPT-6) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>
@k-morozov
k-morozov requested a review from filimonov November 18, 2026 11:30
@DimensionWieldr

Copy link
Copy Markdown
Collaborator

🤖 [Posted by an LLM agent on behalf of @DimensionWieldr]

AI audit note: This review comment was generated by AI (Grok 4.7).

Audit update for PR #2800 (CAS orphan manifest sweep scheduling):

Confirmed defects:

Medium: A due sweep retries every GC tick after any failure that is not inside `planManifestCursorPage`
    Impact: An idle pool whose sweep is due (the default until the first committed completion, and for the whole in-progress traversal) repeats a full fold on every `cas_gc_interval_sec` tick while a seal write, prune, or other pre-commit error persists. `gc_fold_max_defer_rounds` no longer bounds that case, so a backend outage multiplies ref-log scans and unadopted fold-seal writes. A lost `gc/state` CAS is left immediate on purpose.
    Anchor: `src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Gc/CasGc.cpp` / `Gc::runRegularRound`, `Gc::fold`
    Trigger: Sweep decision is `StartSweep` or `ContinueSweep`, `planManifestCursorPage` returns, then a later pre-commit call throws (fold-seal `PUT`, retention prune).
    Why defect: `force_orphan_manifest_sweep` bypasses deferral whenever the in-memory retry marker does not match the adopted generation. That marker is set only when page planning throws (`Gc::fold` catch sets `orphan_manifest_sweep_retry_generation` and rethrows) or after a committed suppressed round. Choosing to fold already zeroes `rounds_since_last_fold_`, and the round CAS never happens, so the cursor and completion time stay due and the next tick is forced again.
    Fix direction (short): Arm the same generation marker for every pre-commit failure of a requested sweep, and still leave a lost `gc/state` CAS immediate.
    Regression test direction (short): Fail the fold-seal write after a successful manifest `LIST` and assert the next idle rounds defer until `gc_fold_max_defer_rounds`.

Medium: A wall clock of 0 is reported as corrupt `gc/state` and the round cannot commit
    Impact: On a host whose wall clock is still at the Unix epoch, every folding round that lists a sweep page throws `CORRUPTED_DATA` after `pruneSupersededGenerations` and before the `gc/state` CAS. No round is adopted, so reclamation stops. That code is non-transient, so the scheduler records `Failed` and clears leadership; other replicas can steal and repeat the same fold. `cas_orphan_manifest_sweep_interval_sec = 0` does not avoid it. Fresh and upgraded pools hit this immediately because a missing completion time is 0, which means "start now".
    Anchor: `src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Gc/CasOrphanManifestSweepSchedule.cpp` / `updateOrphanManifestSweepSchedule`, called from `Gc::runRegularRound`
    Trigger: `now_ms_fn` returns 0 while `orphan_manifest_sweep_completed_at_ms` is 0 (or the interval is 0) and the manifest `LIST` succeeds.
    Why defect: 0 is the stored "never completed" sentinel, and `orphanManifestSweepDecisionOf` treats that sentinel as `StartSweep` before it looks at the clock. The commit path then rejects that same sample (`progress_at_ms == 0`) as `CORRUPTED_DATA`. The throw sits after the pre-CAS prune and before the retry marker is updated, so the failure also takes the unpaced path above.
    Fix direction (short): Commit cursor progress when the clock sample is 0 and leave the previous completion time unchanged; do not use `CORRUPTED_DATA` for a clock reading.
    Regression test direction (short): Run one authoritative round with an injected clock of 0 and assert `gc/state` commits and the completion field stays 0.

Coverage summary:

Scope reviewed: sweep decision, `gc/state` codec, deferral and retry marker, fold planning, round CAS, rebuild/restart/takeover, and the scheduler's single-threaded `Gc` instance.
Categories failed: post-plan pre-commit failure pacing; zero wall-clock progress sample.
Categories passed: interval and overflow math, legacy and three-field decode, cursor/wrap agreement with `planManifestCursorPage`, list-failure and suppression pacing, rebuild and lease handoff, and cross-leader CAS (the retry marker is process-local and the scheduler mutex covers it).
Assumptions/limits: static review of the PR head. Unit tests were not re-run here.

A due orphan manifest sweep forced an idle fold on every GC tick when
page planning succeeded but the fold seal write or generation prune
failed before the round committed. The retry marker only covered
exceptions from `planManifestCursorPage`.

Use a scope guard to record the adopted parent generation when fold
preparation exits by exception. Disable the guard immediately before
the `gc/state` commit attempt so conflicts and unknown write outcomes
preserve the existing retry behavior. Name that boundary flag
`gc_state_commit_started`.

Add deterministic seal-write and prune failure tests that require two
idle deferrals before the next fold, then verify successful recovery.
Update the retry documentation. Built `unit_tests_dbms` and `clickhouse`
and ran the 70 scheduling, defer and retention tests successfully.

Related: #2800
Review: #2800 (comment)

Co-authored-by: Codex (gpt-6.1-sol) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>

k-morozov commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

Confirmed: seal-write or prune failures could force an idle fold on every GC tick. Fixed in 48e5e7b.

A zero wall-clock sample near commit made
`updateOrphanManifestSweepSchedule` reject a valid page with
`CORRUPTED_DATA`, preventing the GC round from committing its progress.

Validate the decision and cursor independently of the clock sample.
Preserve the previous completion timestamp when the sample is zero,
while allowing the page cursor to be adopted through the existing
`gc/state` CAS. A later EOF with a positive sample records completion
and restores interval pacing.

Add regression coverage for intermediate pages, EOF, previous completion
timestamps, clock recovery, zero interval and a conflicting state CAS.
Update the scheduling documentation. Built `unit_tests_dbms` and
`clickhouse` and passed all 75 scheduling, defer and retention tests.

Related: #2800
Review: #2800 (comment)

Co-authored-by: Codex (gpt-6.1-sol) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>

Copy link
Copy Markdown
Collaborator Author

Confirmed: a zero clock sample rejected valid orphan manifest sweep progress and prevented the GC round from committing. Fixed in 5bbe2b9.

@DimensionWieldr

Copy link
Copy Markdown
Collaborator

AI audit found no more defects.

No CI fails are PR-caused.

Full CAS checks run: https://github.com/Altinity/clickhouse-regression/actions/runs/44552771941

  • No fails caused by this PR.

LGTM.

@DimensionWieldr DimensionWieldr added the verified Approved for release label Nov 20, 2026
A due or unfinished orphan manifest sweep forced an idle GC fold on
every tick, bypassing the ordinary eight-round deferral. Large pools
therefore performed more folds while a traversal was in progress.

Use the sweep schedule only to gate page planning inside an ordinary
fold. Restore the five-argument `shouldDeferRound` predicate and remove
the forced-fold suppression marker, scope guard and
`orphan_manifest_sweep_requires_fold` phase metric. Keep
`run_orphan_manifest_sweep` as the page-eligibility metric.

Exercise the ordinary cadence across initial, continuation and next
traversal pages for zero and one-hour intervals. Adapt failure and clock
tests to the ordinary fold conditions, remove force-specific cases and
document the resulting pacing. Cursor and completion adoption retain
their existing conditional `gc/state` write.

Validation: built `unit_tests_dbms` and `clickhouse`, passed 83 scoped
C++ tests, and passed `05428_cas_orphan_manifest_sweep_schedule` through
Praktika. The new cadence test failed before the change.

Related: #2800

Co-authored-by: Codex (gpt-6.1-sol) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>

Copy link
Copy Markdown
Collaborator Author

Removed sweep-driven forced folds in 9eca0a3. Sweep pages now run only during ordinary GC folds.

k-morozov and others added 9 commits November 23, 2026 11:27
Remove the obsolete orphan-manifest sweep trigger from the documented
contract of `shouldDeferRound`. Sweep eligibility only gates page planning
within an ordinary fold.

Validation: comment-only diff; `git diff --check` passed. Build and tests
were not run.

Related: #2800

Co-authored-by: Codex (GPT-6) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>
Explain when the sweep revisits a manifest whose writer stopped before `precommitAdd`. Describe when to enable the interval setting during an upgrade and how an older GC leader can discard the last completion timestamp.

Co-authored-by: Codex (gpt-6.2-astra) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>
The 05428 prefix also selects the Iceberg metadata log test. Give the CAS test and its reference a distinct number so either test can be selected by prefix.

Co-authored-by: Codex (gpt-6.2-astra) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>
Parse quoted `UInt64` fields with `tryReadIntText` and overflow checking. Reject a leading plus and trailing bytes to preserve the CAS wire format. Cover the maximum value, overflow, leading zeros and malformed inputs in `CASJsonVocab.DecimalUInt64String`.

Co-authored-by: Codex (gpt-6.2-astra) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>
A skipped sweep or a mismatch between the wrap flag and the cursor indicates a caller error. Report `LOGICAL_ERROR` with the decision, wrap flag, cursor emptiness and progress timestamp. Verify the diagnostics for both violations, including when the clock reads zero.

Co-authored-by: Codex (gpt-6.2-astra) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>
Document how `now_ms_fn` timestamps a completed orphan manifest sweep and determines when the next sweep may start. The heartbeat fence-out threshold and per-round deadlines use `mono_ms_fn`.

Co-authored-by: Codex (gpt-6.2-astra) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>
Allow the next ordinary fold to start a traversal when the saved completion time is more than one interval ahead of the leader clock. A zero clock reading preserves the wait for a known completion time with a positive interval.

Cover the exact threshold, overflow, and recovery on an ordinary fold. Document how the schedule handles a future completion time.

Review: https://gist.github.com/filimonov/8cdc2dd82770046cbbe84fbc271d77bf
Related: #2800

Co-authored-by: Codex (gpt-6.2-sol) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>
Keep the generation 4 blob intent sweep on its own cursor while the manifest sweep waits for its interval. Commit both cursors and the manifest completion timestamp in the same conditional update of `gc/state`.

Exercise intent progress during the manifest cooldown and retain multi-round coverage for an empty ref stream. Renumber the stateless scheduling test to 05814 because the release branch uses 05486 for blob intent requests.

Related: #2917
Related: #2800

Co-authored-by: Codex (gpt-6.2-astra) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>
Describe the catalog recheck for a tentative manifest and the reads it adds to a planned page. Distinguish the mount-floor check from the ownership and fold-coverage checks for cataloged namespaces. Clarify how generation 4 leaders with and without the interval setting can share a pool during rollout.

Co-authored-by: Codex (gpt-6.2-astra) <[email protected]>
Signed-off-by: Konstantin Morozov <[email protected]>

@filimonov filimonov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@filimonov
filimonov merged commit 67a57a9 into antalya-26.8 Nov 24, 2026
363 of 378 checks passed
filimonov added a commit that referenced this pull request Nov 24, 2026
Brings in #2800 (orphan manifest sweep schedule). No textual conflicts.

Signed-off-by: Mikhail Filimonov <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
filimonov added a commit that referenced this pull request Nov 24, 2026
With #2800 the orphan manifest sweep runs on an interval, so the second round of the test lists four prefixes, not five.

Signed-off-by: Mikhail Filimonov <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alsugiliazova

Copy link
Copy Markdown
Member

Lower-severity notes

Configuration

Low: the interval has no upper bound, so a mistyped value silently stops the sweep after the next traversal completes

  • Anchor. ContentAddressedSettings.cpp (DECLARE(UInt64, orphan_manifest_sweep_interval_sec, 3600, ...)), and the Gc constructor, which validates other settings but not this one.
  • Trigger. An operator sets cas_orphan_manifest_sweep_interval_sec to 36000000 instead of 3600. Once a traversal completes, the next one starts roughly 416 days later.
  • Why it matters. A LIST budget of 0 is documented as a deliberate pause. A large interval does the same thing without saying so. The only sign is run_orphan_manifest_sweep = 0 on every defer_decision row, and orphan_manifest_sweep_waiting_for_clock stays 0 because the leader's clock is not behind. Orphaned manifests and the blobs they reference leak until someone notices.
  • Fix direction. Reject or clamp values above a sane maximum (for example 7 days) at disk load, or log a warning.

Recovery latency (behaviour change, documented)

Low: retries that used to happen on the next pass now wait a full interval

  • Anchor. updateOrphanManifestSweepSchedule records completion when the page reaches the end of the key space, before the deletes that run after the commit (phase 18).

  • What changes. Two cases used to be retried on the very next traversal, a few rounds later at most:

    • A manifest whose post-commit delete fails on the last page of a traversal.
    • A manifest the sweep passed while its build was still active, if the writer then died before precommitAdd.

    Both now wait until the interval elapses and the next traversal reaches the key. With the defaults that is more than an hour. The cost is a storage leak only, and the PR's configuration docs describe it. It is listed here because it is the change the regression and soak suites can observe (see below).

Documentation

Low: the README and the GC architecture docs describe a state format that never shipped

  • Anchor. Formats/README.md ("The previous three-field schedule also stored orphan_manifest_sweep_active and orphan_manifest_sweep_started_at_ms ... rollback to that intermediate reader is unsupported"). garbage-collection.md repeats this.
  • Why it matters. No build on antalya-26.8 ever wrote or read those keys; they existed only in this PR's history. An operator reading "rollback is unsupported" may think some released build is affected. The open follow-up #2954 is a natural place to remove the paragraph.

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.

5 participants