Skip to content

Give each CAS request its own window; let the owner stop CAS work - #2970

Draft
filimonov wants to merge 21 commits into
antalya-26.8from
work/antalya-26.8/cas-request-window
Draft

filimonov wants to merge 21 commits into
antalya-26.8from
work/antalya-26.8/cas-request-window

Conversation

@filimonov

@filimonov filimonov commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Every CAS metadata request now binds its own window (cas_request_window_ms), loops above the request engine end on a count, the owner of CAS work can stop it, and a retry after a lost conditional write reads right before it writes. Before, several requests of one operation shared one deadline, so a slow first request left the later ones no time, and KILL QUERY, max_execution_time, SYSTEM CAS GC STOP and server shutdown did not reach CAS retry loops.

Changes

  • Windows and counts. Each request (read, conditional write, settling read, listing page) gets a fresh window. Loops end on a count: 100 decisions or catalog submissions, 8 blob publications, 8 recovery walks. No deadline is shared between requests. CasOperation::freeze, Retry::asSingleAttempt and the recovery time budget are removed; the offline tools keep one outside cap.
  • Retry after a lost race. A read and the conditional write decided on it are one probe; pauses come only between probes. Before, a retry read the object, paused, and wrote on the body read before the pause, so with other writers committing more often than once per pause it lost every time. Now a write from the cached catalog that loses is decided again at once on the read that settled it; a write decided on a fresh read that loses is followed by a pause, a new read and a write. A clean 412 on that path costs no settling read, and a submission after a pause never starts from the cache. The pause after the n-th consecutive clean loss is min(750 ms, 40 ms * (n - 1)) plus up to a quarter, so the first retry comes at once; a conflict that settled a transport fault keeps the fault schedule and restarts the count. readModifyWrite and readModifyWriteOnPresence share one loop. The catalog erase loop refreshes GC authority before its catalog read on a retry.
  • Stopping by the owner. A query's stop is consulted only where stopping is safe: after a failed attempt, before its retry (the failure pause is checked every 200 ms), and at the head of CAS-owned resumable scans (manual GC rows, decommission lives, groups and keys, a blob before its publication). It never refuses a healthy first attempt, a decision, a wait or a cleanup step, so multi-step SQL and finalizers (MergeTreeTransaction rollback, temporary-table drop) behave as on a plain S3 disk. A vetoed retry ends with the failed attempt's own exception. Background owners (GC scheduler stop, shutdown removal of an Atomic table's namespace, pool teardown) are checked at more points and end with ABORTED.
  • Unknown outcomes stay visible. A sent write whose outcome stays unknown ends as NETWORK_ERROR "outcome unresolved", and later steps of the same call cannot replace that. writeLoop classifies one attempt first and then chooses the next step; a catalog update decides how a step ended before it looks at the submission cap.
  • Shared ref-log flush. CAS's owner checks do not reach the flush a leader does for other queries' items. The leader still flushes in its own query's thread group, so the S3 client reports an unsuccessful answer as that query's stop: a killed leader's failed chunk can fail the batch and cost one lane recovery, as before this change. The lane stays usable.
  • Shared exceptions. CAS no longer annotates a query's stored exception and hands each waiting thread its own copy of a shared failure.
  • Removal. After a DROP whose Live -> Removing write was sent and then failed, the table stays closed for writes until the DROP is retried. A refused insert leaves no cleanup duty behind.

Risks / notes

  • Behavior change under catalog contention: a catalog update that keeps losing races to other pool members now ends after 100 submissions instead of at a shared deadline. One lost race costs a conditional write, a pause and a read; 100 losses in a row take 67 to 84 s of pauses. docs/en/antalya/cas/configuration.md#contention-bound states the bound. Whether 100 is the right count for pools with tens of members is open; it is one constant (kCasMaxDecisions).
  • No code outside the CAS directory changes behavior: the only edit there is column comments in ContentAddressedGarbageCollectionLog.cpp. Two things that need shared code are left out on purpose: a cancellation mask for finalizers (the S3 client still replaces an expected 404 or 412 with a killed query's exception, as before this change), and an explicit "this removal is retried" signal from the catalog's drop worker (inferred today from the path shape and the absent query context in tableRemovalResumesAfterRestart).
  • Found by this pull request's count: the regression jobs cas_alter_attach_3 and cas_s3_cache_alter_attach_3 failed once on a branch built on an earlier head (CAS: pace part uploads and stop them on KILL QUERY #2974) with "CAS ref catalog update: did not converge after 100 submissions": a CREATE TABLE ... ON CLUSTER lost 100 catalog writes in 11 s while other replicas were erasing rows. The read-pause-write order is older than this change; the shared deadline (about a thousand attempts in 120 s) used to outlast such a burst. Commits 18 to 21 fix the order. The CI scenario itself (parallel DDL on three replicas, a 1 MB catalog) was not reproduced locally.
  • A stopped query whose catalog write lost a race ends at its next failed read, with ABORTED "conflict" when that write was decided on the cached catalog and with the query's own stop otherwise. No further write follows in either case.
  • The series is cut for reading: commits 1-4 are windows and counts, 5-14 the stop, 15 integration tests, 16 docs, 17 a test fix for the "db disk" lane, 18-21 the retry order (product, unit tests, integration test, docs). Only the branch head is built and tested; intermediate commits share hunks of CasRequests and are not built one by one.
  • Not measured yet, planned before this leaves draft: catalog conflicts under mass DDL on several replicas of one pool; churn and ALTER/ATTACH PARTITION timings.

Testing

  • Unit gate CAS*:ReadBufferFromS3SessionRelease*:S3BulkDeleteFallback*:ReadBufferFromFileView* on this exact tree: release 5491 passed; ASan 5491 passed, 3 skipped, no sanitizer reports.
  • Integration tests/integration/test_cas_request_window (21 tests, S3 fault proxy): 21 passed on the release server in the default lane and in the "db disk" lane.
  • Stateless 05023_query_thread_log_progress_per_query on the CAS storage lane: passed. An earlier head ran the shared flush in a separate thread group; each flush then wrote a system.query_thread_log row and this test failed, so the group is removed.
  • About 270 unit tests are new. 19 existing tests change meaning: tests that asserted "ends at the shared deadline" now assert the count or the request's own window. The retry-order tests journal the requests of one caller (for example WRWPRW: write, read, write, pause, read, write) against a rival that commits during every pause; they fail on the old order with "did not converge after 100 submissions".
Existing tests that change meaning
Test Becomes
CASPoolMeta.AdmitOrValidateEndsAtTheDeadlineUnderPerpetualConflict counts 100 decisions and checks the cap text
CASRequests.ReadModifyWriteLosesNoIncrementUnderContentionAndBoundsAHotKey (second half) gives up for the attempt count, not the deadline
CASRefCatalog.CasUpdateEndsAtTheDeadlineNotAfterAHundredUnsleptIterations ends after 100 paced submissions
CASRefCatalog.CreateNamespaceStep1DoesNotPausePastItsDeadline pauses once, decides again and creates the row
CASRefCatalogRemoval.PerpetualConflictGivesUpWithinOneWindowNotAtTheAttemptCap inverted: 100 erases, 99 pauses
CASRefCatalogRemoval.AWriterLandingDuringEveryBackoffCannotStarveTheErase (second half) a long pause after one refused erase no longer ends the call
CASCatalogLifecycleReconciler.AnAuthorityReadFailingInTheCatalogLaneEndsByTheCancelDeadline the failing read ends one window after its own start
CASRefCatalogBirthWiring.APerpetuallyChurningCatalogEntryIsPacedAndEndsWithinOneWindow exactly 32 rounds
CASRefWriterNamespaceRemoval.DropWithASlowCreatorFenceReadEndsAtTheEntryDeadline the fence read ends at its own window
CASRefWriterNamespaceRemoval.DropSpendsOneWindowAcrossItsReads, .DropSpendsOneWindowAcrossItsCatalogUpdate each failing request ends one window after its own start
CASRefWriterNamespaceRemoval.AWaitLongerThanTheWindowEndsTheDropAndLeavesTheLaneOpen the drop succeeds; the lane-reopen check moves to a failure before any write
CASPartWrite.EnsureBlobPresentIsBoundedByTheOneWindowItCaptured 8 publications, the last injected message
CASConfirmExactRef.CopyConfirmStopsRetryingTheSlotReadAtTheCallersDeadline measured against the read's own start
CASConfirmExactRef.CopyConfirmRefusesAtItsDeadlineWhileAMutationNamingTheSourceStaysQueued no spare-envelope requirement before a pass
CASRefWriterRecoveryRetry.TransientFailureLongerThanBudgetPropagates propagates after 8 walks
CASContentAddressedSettings.RequestWindowSettingSetsTheWindowAndTwiceTheRecoveryBudget the recovery half is gone
CASRetry.AFrozenPolicyIsOneDeadlineAndTheLeaseStillWins, the three-plane pool test rewritten for the outside cap

Changelog category (leave one):

  • Improvement

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

Content-addressed storage: each metadata request has its own cas_request_window_ms window and retry loops end on a count, so one slow request no longer takes the time of the next. KILL QUERY, max_execution_time, SYSTEM CAS GC STOP and server shutdown now end CAS retries: a killed query stops at the next failed request instead of retrying for the whole window. A retry after a lost conditional write reads the object right before it writes, so concurrent DDL on several replicas of one pool no longer starves a catalog update.

Documentation entry for user-facing changes

  • Documentation is written: docs/en/antalya/cas/configuration.md (request window, contention bound and the pause schedule), docs/en/antalya/cas/operations/troubleshooting.md (stopping CAS work, a DROP that failed after its removal write), docs/en/antalya/cas/architecture/garbage-collection.md, docs/en/operations/system-tables/cas_gc_log.md.

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)

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [e0780e2]

filimonov and others added 16 commits November 27, 2026 04:27
Each request binds `cas_request_window_ms` when it is sent; requests share no deadline.
`Retry::bind` takes the smallest of the window, an outside cap (a tool's own deadline) and
the lease, and records which one won in `Retry::Bound::Source`.
Decision loops end after `kCasMaxDecisions` (100) with `GaveUp::Why::Attempts`; a fence or
lease lost during the last request is reported instead of the count.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hot-key lane, catalog updates and erases, namespace life and drop, the blob publication
loop and the copy-source confirm poll no longer freeze one deadline for the whole loop.
Each request binds its own window. The loops end at count caps (100 decisions or
submissions, 8 blob publications); the confirm poll's deadline only decides whether
another pass starts.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`recovery_retry_budget_ms` is removed. The walk that fails at `kCasMaxRecoveryWalks` rethrows
its own error; a restart at the cap fails as "did not converge".

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No loop freezes a deadline any more. A tool's own deadline stays an outside cap
through `Retry::cappedAt`.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The owner is the query or a background owner (`OwnerScope::background`). `OwnerScope::owed`
marks work owed to a possibly-sent write or a failed commit; `OwnerScope::shared` marks work
done for several callers. `CasOwner.h` lists where work may end and the facts that classify
a failure. Adds the killable-query test fixture.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A query's stop is consulted only after a failed attempt: it vetoes the retry, and the call
ends with that attempt's error. A write attempt is classified first, then the loop picks
its next step; a sent write that stays unresolved ends as `NETWORK_ERROR` (210). Local faults surface unchanged, and a stopped owner's
exception is no store answer in the backend or the sentinel probe.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A catalog step decides its exit before the submission cap and the pause, by one rule.
A write that saw its query stop starts no further discretionary request. An earlier
unresolved write is reported at every non-commit exit, also from the catalog erase.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stopped follower withdraws its queued item, or waits for its result once a leader carved it.
A leader checks its owner before each flush and withdraws its own pending item.
An exceptional erase notifies waiters; a shared failure is rethrown as each thread's own copy.
The leader flushes in its caller's thread group under `OwnerScope::shared`: CAS's owner checks
do not reach shared work, but the S3 client still reports an unsuccessful answer as a killed
leader's stop.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only a walk that threw lets a stopped owner end recovery; the walk itself is owed.
A sent stamp or tombstone that stays unresolved keeps its retry-later exit after a stop,
and a query stop confirms real corruption before ending recovery. The backoff sleeps in
slices, and a stopped background owner leaves the wait for another caller's recovery.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stop before a blob publication ends the upload with the previous publication's error;
a stopped owner's failure is not retried, and a landed body stays debris. A refused
precommit owes no cleanup of its own and keeps an earlier call's duty. The commit compensation and the rename undo are owed. Upload
workers check they run in the submitter's thread group.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only the catalog's drop worker removes an `Atomic` table directory without a query, and
it retries after a restart, so shutdown may stop it. The removal lane stays closed after
any sent removal write, and its reopen proof is owed. Waits for the lane and for writer
cleanup duties use `waitStoppable`.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A round stopped by `SYSTEM CAS GC STOP` or by its query is recorded as `Stopped`.
A manual round checks its query at scan heads, and its read-ahead and delete workers run in
the round's thread group. Committed orphan nominations are deleted before the janitor
runs, and the post-commit phases are one owed scope.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The decommission drain checks a killed query per page of the manifest listing and per
key. `runBounded` workers check their thread group before any request. Catches in the
tools leave a query's stored exception unannotated.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`s3_fault_proxy.py` moves to `helpers/s3_mocks` and can hold a request until the test
releases it. `test_cas_request_window` covers per-request windows, kills and query
timeouts end to end.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@filimonov
filimonov force-pushed the work/antalya-26.8/cas-request-window branch from 5f79613 to d42bd3d Compare November 27, 2026 07:08
@filimonov
filimonov requested a review from k-morozov November 27, 2026 10:01
`test_shutdown_hands_atomic_drop_to_restart` listed the local
`metadata_dropped` directory. On the "db disk" lanes the database disk is
remote, the directory is empty, and the test failed although the server
stopped the removal as expected ("Cannot drop table ... Will retry later:
... CAS table namespace removal stopped by server shutdown"). The test now
checks that `DatabaseCatalog` logs no removal of the table's metadata
before the exit and logs it after the restart.

https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2970&sha=d42bd3d271cdf293f9fec5bf61bfe4ea079ff6fc&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%208%2F8%29
#2970

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
filimonov added a commit to filimonov/ClickHouse that referenced this pull request Nov 27, 2026
37 new tasks (CAS-539 to CAS-575) and notes on 35 existing ones.

- CAS-540, CAS-541: studies of a ref catalog per server root and of group
  commit in the hot-key lane.
- CAS-542 to CAS-571: findings of the review rounds of
  Altinity#2970 that are not fixed in
  it, the upstream changes it depends on (CAS-565 to CAS-570) and one
  measurement task. CAS-543 is closed: the flush thread group it describes
  was removed from the PR.
- CAS-572, CAS-573: blob uploads ignore the remote write throttle; a slow
  uplink with many parallel blob streams.
- CAS-574, CAS-575: soak scenarios S13 and S47 fail on their own limits.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
filimonov added a commit to filimonov/ClickHouse that referenced this pull request Nov 27, 2026
`move_factor` 0.1 moved every part off `local1` right after its insert on
a host whose disk is 96% full, and S37 failed its routing check. Free-space
moves are not under test there; `move_factor` is now 0.

`RUN_HISTORY.md` and the scenarios' `BACKLOG.md` get the rows of the
2026-11-27 run of all scenarios on the build of
Altinity#2970.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@filimonov filimonov added the CAS label Nov 27, 2026
filimonov and others added 4 commits November 28, 2026 19:51
After a conditional write lost a race, the engine read the object, paused,
and then wrote on the body it had read before the pause. With other writers
committing more often than once per pause every retry was refused: a
`CREATE TABLE ... ON CLUSTER` lost 100 submissions of the ref catalog in
11 s and failed with "did not converge after 100 submissions".

A read and the write conditioned on it are now one probe with nothing
between them; pauses come only between probes:
- a write from the cached catalog that loses is decided again at once on
  the read that settled it;
- a write decided on a fresh read that loses is followed by a pause, a new
  read and a write. A clean 412 on that path is no longer settled by a read
  of its own, and a submission after a pause never starts from the cache;
- the pause after the n-th consecutive clean loss is
  min(750 ms, 40 ms * (n - 1)) plus up to a quarter: the first retry comes
  at once. A conflict that settled a transport fault keeps the fault
  schedule and restarts the count;
- `readModifyWrite` and `readModifyWriteOnPresence` share one loop;
- the catalog erase loop refreshes GC authority before its catalog read on
  a retry, and `resolveNamespaceLife` paces by its collisions.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stopped query whose catalog write lost a race ends at the next failed
read. On the cached path that read settles the refused write and the query
ends with its conflict; on the fresh path it is the read before the next
attempt and the query ends with its own stop. The test runs both in a
fixed order; no further `PUT` follows in either.

Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Mikhail Filimonov <mfilimonov@altinity.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

2 participants