Skip to content

Don't record a cancelled marks-loading task in system.errors - #118928

Merged
alexey-milovidov merged 5 commits into
masterfrom
fix-marks-cancel-in-system-errors
Sep 20, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
fix-marks-cancel-in-system-errors

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Related: #118477

MergeTreeMarksLoader::loadMarksAsync throws ASYNC_LOAD_CANCELED ("Background task for loading marks was canceled") from the pool task when is_canceled is set. That flag is set only by ~MergeTreeMarksLoader, which then calls future.wait and drops the future without ever reading it, so the exception is never observed by anyone - it exists only to stop a task whose result has become useless. Constructing a DB::Exception, however, records the error code in system.errors and system.error_log.

Since load_marks_asynchronously became enabled by default, this happens on any server whenever a reader is dropped before its marks are needed, so ASYNC_LOAD_CANCELED accumulates in system.errors during completely normal operation, where it looks like a failure. ProfileEvents::LoadingMarksTasksCanceled, incremented right above the throw, is the proper counter for this event.

The fix constructs the exception inside an Exception::SuppressErrorCodesScope, so the control-flow signal is kept out of the error statistics and everything else stays as it was.

This also made test_backup_restore_on_cluster/test_cancel_backup.py::test_cancel_restore flaky. Its NoTrashChecker asserts that no unexpected error code appears in system.errors on the cluster nodes during the test, and the test's own SELECT ... FROM system.query_log query cancelled one queued marks task - ProfileEvents['LoadingMarksTasksCanceled'] = 1 out of 18 BackgroundLoadingMarksTasks for query 0e316a97-8cb4-4f63-b3f9-fd88e773ed43 in the captured query_log of node2:

node2: Found errors: ['QUERY_WAS_CANCELLED', 'ASYNC_LOAD_CANCELED']
ASYNC_LOAD_CANCELED     Background task for loading marks was canceled

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=a63831d1ff39052ac6dfdce45bf38de316ab583e&name_0=MasterCI&name_1=Integration%20tests%20%28amd_msan%2C%201%2F8%29

Test: 05223_marks_loader_canceled_task_not_in_system_errors. The cancellation happens only when the loader's destructor wins the race against the marks-loading thread pool, and no query shape could force that reliably, so the test uses the new test-only fail point marks_loader_hold_task_until_canceled, which holds the pool task (bounded) until the loader is destroyed. The query drops the reader of a column with its marks unread behind a PREWHERE that filters out every row, and the test checks LoadingMarksTasksCanceled in system.query_log and that system.errors gained no ASYNC_LOAD_CANCELED. Without the suppression the test reports 2 new errors.

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 into CHANGELOG.md):

Don't count a cancelled marks-loading background task as an error in system.errors and system.error_log. Previously ASYNC_LOAD_CANCELED was recorded during normal operation whenever a reader was dropped before its asynchronously loaded marks were needed.


Workflow [PR]
Sync PR [sync-upstream/pr/118928]

`MergeTreeMarksLoader::loadMarksAsync` throws `ASYNC_LOAD_CANCELED` from the
pool task when `is_canceled` is set. That flag is set only by
`~MergeTreeMarksLoader`, which then calls `future.wait` and drops the future
without reading it, so the exception is never observed by anyone - it exists
only to stop a task whose result has become useless. Constructing it, however,
records the error code in `system.errors` and `system.error_log`.

Since `load_marks_asynchronously` became enabled by default, this happens on
any server whenever a reader is dropped before its marks are needed, so
`ASYNC_LOAD_CANCELED` accumulates in `system.errors` during completely normal
operation. `ProfileEvents::LoadingMarksTasksCanceled`, incremented right
above, is the proper counter for the event.

Construct the exception inside an `Exception::SuppressErrorCodesScope` so the
control-flow signal is kept out of the error statistics.

This also made `test_backup_restore_on_cluster/test_cancel_backup.py::test_cancel_restore`
flaky: its `NoTrashChecker` asserts that no unexpected error codes appear in
`system.errors` on the cluster nodes during the test, and the test's own
`SELECT ... FROM system.query_log` query cancelled a queued marks task
(`ProfileEvents['LoadingMarksTasksCanceled'] = 1` of 18 background tasks).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=a63831d1ff39052ac6dfdce45bf38de316ab583e&name_0=MasterCI&name_1=Integration%20tests%20%28amd_msan%2C%201%2F8%29

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bad6185]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR suppresses ASYNC_LOAD_CANCELED from system.errors for discarded asynchronous marks-loading tasks and adds a stateless regression test around a new failpoint. The production fix looks correct, but the new test still leaves a server-global failpoint armed if the script exits early, so the change is not ready as-is.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/05223_marks_loader_canceled_task_not_in_system_errors.sh:37] The new test enables the server-global marks_loader_hold_task_until_canceled failpoint and only disables it on the happy path. If the SELECT hangs, fails, or the script exits under set -e while that failpoint is armed, later stateless tests on the same server inherit a forced stall in every MergeTreeMarksLoader::loadMarksAsync task and start failing for unrelated reasons.
    Suggested fix: add an EXIT trap that always runs SYSTEM DISABLE FAILPOINT marks_loader_hold_task_until_canceled, and keep the explicit disable at line 47 if you want the post-query assertions to run after the failpoint is already cleared.
Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit bad6185.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 80.60% 80.70% +0.10%

Changed lines: Changed C/C++ lines covered: 15/15 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Sep 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit bad618597a3b64968c1d4b5d2bad171d840ec5da with master failed: RuntimeError: CI logs cluster query failed: SELECT file, countIf(side = 'pr') AS pr_cou….

See the job log for details.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118928&sha=519e282a1862f06554a861bc1e202f89481b3458&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%206%2F6%29 (test_storage_kafka/test_multi_consumer_quota.py::test_multi_consumer_with_partition_affinity, tracked in #119632) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

Investigated. The failure is unrelated to this pull request (the diff is MergeTreeMarksLoader.cpp; the test exercises StorageKafka2 partition locking), and it is already root caused and tracked at #119632, which I opened at your request on 2026-09-12.

Root cause, in short: KeeperHandlingConsumer::lockTemporaryLocksLocked gates its anti-starvation rule on the consumer's own previous-round quota (tmp_locks_quota > 0 && has_replica_without_locks), so a consumer arriving with quota 0 skips the rule and takes a temporary lock while a same-shard replica holds nothing; prepareToPoll clears tmp_locks and re-locks inside the same call, so a partition the peer needs is gone again within one Keeper round trip. It is an unreleased regression (the zero-entitlement consumer class needs computeConsumerQuota, master only) and it requires kafka_num_consumers > 1.

No fix pull request exists, and the reason is your own ruling on this defect on 2026-09-12: "That is a protocol addition and the Kafka owners' call, so please do not force it from this side", and that waiting on the Kafka owners on #116844 was the correct thing to do (comment). I have not forced it since. Every per-consumer and per-storage shape falls to the two defects you agreed with in that same comment (the abstention's only local bound is the incumbent's kafka_consumer_reschedule_ms, which belongs to the peer; and with three or more replicas each storage's phase is independent over one Keeper-wide lock set). The surviving shape is an explicit demand signal in Keeper (a per-replica ephemeral marker beside is_active, with the abstention conditioned on the marker rather than on a duration), written up here.

What has changed since that ruling:

If you want the demand-signal pull request from my side now, say go and I will open it against master. Otherwise I keep waiting on the Kafka owners as you directed, and #119632 stays the owner to cite for this red.

The `Finish Workflow` check rejects a bug-fix PR without a new test. The
cancellation only happens when `~MergeTreeMarksLoader` wins the race against
the marks-loading thread pool, which could not be forced from a test before.
Add the test-only fail point `marks_loader_hold_task_until_canceled`, which
holds the pool task (bounded, polling `is_canceled`) until the loader is
destroyed, and the test `05223_marks_loader_canceled_task_not_in_system_errors`
that drops a reader with its marks unread behind a `PREWHERE` filtering out
every row, then checks `LoadingMarksTasksCanceled` in `system.query_log` and
that no `ASYNC_LOAD_CANCELED` error was added to `system.errors`.

Without the `Exception::SuppressErrorCodesScope` the test reports 2 new
`ASYNC_LOAD_CANCELED` errors, with it 0 (checked locally, 12 passes with
randomized settings).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118928&sha=519e282a1862f06554a861bc1e202f89481b3458&name_0=PR&name_1=Finish%20Workflow
PR: #118928

Co-Authored-By: Claude Fable 5.1 <[email protected]>

query_id="${CLICKHOUSE_DATABASE}_marks_canceled_$RANDOM"

$CLIENT -q "SYSTEM ENABLE FAILPOINT marks_loader_hold_task_until_canceled"

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.

This enables a server-global failpoint but only clears it on the happy path. If the read below hangs/regresses or the test is interrupted while the failpoint is armed, later stateless tests on the same server inherit a forced stall in every MergeTreeMarksLoader::loadMarksAsync task and start failing for the wrong reason.

Please add the usual defensive EXIT cleanup here, e.g.

trap '$CLIENT -q "SYSTEM DISABLE FAILPOINT marks_loader_hold_task_until_canceled" >/dev/null 2>&1 || true' EXIT

and keep the explicit SYSTEM DISABLE FAILPOINT on the normal path if you want the post-query assertions to run with the failpoint already cleared.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Sep 20, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 20, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

I am taking the "Ok." as the sign-off on this pull request rather than the go-ahead for the StorageKafka2 change, so I am not opening the demand-signal pull request, and your position from 2026-09-12 stands (that is a protocol addition and the Kafka owners' call, so do not force it from this side): #118642 (comment)

One thing did change since my comment above. #120111 replaces the registered-replica count in getActiveReplicasInfo with a count of replicas whose ephemeral is_active node exists, which closes the liveness half of the missing input I described on #116844. It does not clear this red by itself, because both replicas in test_multi_consumer_with_partition_affinity stay alive and the count there is unchanged, but once it merges the only remaining gap for #119632 is the per-replica demand marker.

If you want that from my side now, one word on #119632 and I will open it against master.

Merged via the queue into master with commit 43c13f5 Sep 20, 2026
175 of 177 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-marks-cancel-in-system-errors branch September 20, 2026 23:38
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 20, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

The red cited above (never acquired any partition within 240s) is fixed by #120556, merged 2026-09-25 and backported to 26.9 in #122325: it removes that per-replica liveness assertion and checks an upper bound instead. Since the merge the test has 4,726 passing runs (510 on master), and its only failure was on a backport head that does not contain the fix, so nothing is pending from my side.

@clickhouse-gh clickhouse-gh Bot added comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants