Skip to content

Measure cancellation server-side in test_cancel_backup.py - #112217

Merged
alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
groeneai:fix-cancel-backup-server-side-timing
Jul 30, 2026
Merged

alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
groeneai:fix-cancel-backup-server-side-timing

Conversation

@groeneai

@groeneai groeneai commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #108459

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

test_backup_restore_on_cluster/test_cancel_backup.py::test_cancel_backup and
::test_cancel_restore are flaky: 14 FAIL/ERROR rows over 24 days, 11 distinct PRs, plus one
run on master and one on 26.6
(30-day CIDB window, excluding the unrelated signature
separated at the end of this description).

The signature CIDB shows is a mask, not the defect. test_context_raw is truncated to the
last frames, so what CIDB reports is NoTrashChecker.__exit__ asserting with both relaxation
lists empty:

test_cancel_backup.py:441 - in test_cancel_backup
    with NoTrashChecker() as no_trash_checker:
test_cancel_backup.py:375 - in __exit__
    assert (error in self.expect_errors) or (error in self.allow_errors)
E   AssertionError: assert ('QUERY_WAS_CANCELLED' in [] or 'QUERY_WAS_CANCELLED' in [])

The job logs show the body exception that ran first, identically in all 12 rows whose logs were
fetched (the 12 that existed when this was investigated; two more have landed since):

test_cancel_backup.py:487: in test_cancel_backup
    assert time_to_cancel <= 6  # A backup should be cancelled quite quickly.
E   assert 6.5760968409999805 <= 6

time_to_cancel was a client-side stopwatch, so it measured the integration harness rather
than the cancellation.
Every node.query(...) here is a docker exec of a fresh
clickhouse-client, and the measured window spanned 3-4 of them plus wait_status's whole-second
poll quantum. Decomposing each failure using timestamps the test already prints
(system.backups.end_time minus the wall clock at the KILL):

PR reported time_to_cancel engine-side upper bound harness overhead
104484 6.58 2.28 4.29
105684 6.93 2.50 4.43
109374 6.18 3.24 2.94
110186 8.13 2.22 5.91
110199 8.64 2.76 5.87
110231 6.22 2.38 3.85
110254 6.97 2.02 4.96
111196 6.72 2.49 4.23
111353 6.68 2.08 4.60
26.6 (release branch) 7.74 2.59 5.15
98472 6.51 1.90 4.61
master 6.48 2.15 4.34

Engine-side: max 3.24 s, median 2.33 s, i.e. every single failure is comfortably inside the
6 s intent.
The cancellation was prompt in all 12; the assertion failed on measurement
overhead alone, which is why the failure is rare, recurring, and both arch- and
sanitizer-agnostic. There is nothing to fix in the engine.

The fix measures the same interval between two server-recorded timestamps, so client
round-trip latency is no longer added to it while the cluster-wide cancellation is still inside
it (up to the error-path cap described below). wait_status does still poll over the same
period, but neither endpoint can be moved by a poll: the left one is written before the polling
starts, and the right one is stamped by the backup thread rather than by the observing SELECT.

  • kill_query issues the KILL ... SYNC with an explicit query_id and returns it. Once the
    operation has finished, get_query_start_time reads that query's own
    query_start_time_microseconds from system.query_log. Taking the start from the KILL
    statement itself (rather than a separately issued SELECT now64(6)) is what stops a client
    launch from being added to the interval: in the 104484 run one client-to-server transition
    stalled 4.192 s, which alone would consume the whole budget. Doing the lookup after the
    fact keeps the lookup's own cost out of the measurement too.
  • wait_status returns the end_time it already reads and prints. BackupsWorker::setStatus
    stamps it at the terminal transition, which the initiator reaches only after
    waitOtherHostsFinish, so distributed propagation stays inside the bound. That matters: the
    KILL's own duration is not a sufficient oracle, because waitOtherHostsFinish is gated on
    !is_internal_backup, so a KILL aimed at a non-initiator returns before the initiator reaches
    the terminal status (measured 0.65-1.10 s of propagation in 9 of the 12 rows). On the error
    path that wait is itself capped by backup_restore_finish_timeout_after_error_sec, which this
    module sets to 3 s, so what the interval bounds is the cancellation up to that cap rather than
    an unconditional last-host completion. That is the same terminus the previous assertion had -
    time_to_cancel ended at the same wait_status return - so nothing is narrowed here; a remote
    host still cancelling afterwards is caught by the existing
    assert get_num_system_processes(nodes, ...) == 0 on the next line.

The 6 s upper bound is unchanged, and it stays a single end-to-end assertion. Nothing is
loosened, no second oracle is added, and a genuinely slow cancellation still fails: measured on
this branch, tightening the bound to 1 fails, and to 0.001 fails.

The assertion is now two-sided (assert 0 <= time_to_cancel <= 6), which only tightens it. The
previous oracle was a single time.monotonic() stopwatch and so could not produce a negative
value; these are two independent CLOCK_REALTIME reads, so a backward wall-clock step between
them can now yield a negative interval, which would otherwise satisfy <= 6 silently. The lower
bound makes that a loud failure instead. (It catches the negative case, not every backward step:
a step smaller than the true interval still leaves a positive value.) All 20 runs of the
verification below produced positive intervals (min 0.146 s), so the clause cannot flake on the
normal path.

Second, independent change: no_trash_checker.allow_errors = ["QUERY_WAS_CANCELLED"] is now set
on entry to the checker, while expect_errors stays where it was, after the cancellation has
been observed. That removes the mask for this failure mode, so a body exception raised after the
cancellation was induced reports itself instead of costing another investigation. The list is
deliberately minimal rather than broad, so __exit__ still fails on any other unexpected error
name. allow_errors is deliberately the hoisted one:
__exit__ treats expect_errors as must-have-been-observed, so hoisting that would create a
new mask with inverted polarity for any failure before the cancellation. This matches
#108459, which hoisted allow_errors
for two sibling functions in this file and never expect_errors.

test_cancel_restore has the same defect and is fixed identically. It is a confirmed carrier
rather than a speculative one: PR #109374's log shows assert 6.143040713999653 <= 6 followed by
the same mask. It has one recorded row against test_cancel_backup's 13, but the defective
construct is identical, so fixing only one of the two would leave a known carrier in place.

Why not the query_duration_ms oracle that test_backup_restore_new/test_cancel_backup.py
uses.
It was deliberately removed from this file in 19bcc5550bad04, and
c26e0b413fa619 then replaced the per-step timeouts with the single end-to-end
assert time_to_cancel <= 6. This PR keeps that single end-to-end assertion and changes only how
its two endpoints are obtained.

Verification

  • Mechanism reproduced deterministically by injecting a 6 s harness delay into the measured
    window: on master the old assertion fails at assert 6.660929953679442 <= 6 followed by the
    mask, byte-matching the CI signature; on this branch the same injection passes, because the
    server-recorded interval cannot see a delay that happens after end_time was stamped. A second
    injection before the KILL also passes, confirming that client round-trip cost outside the two
    server-recorded endpoints is not added to the measurement.
    (A 4 s injection is marginal, because whether it trips the old bound depends on how long the
    KILL itself took that run, so both directions are measured at one common 6 s delay.)
  • Both measurements taken in the same run, 10 runs: server-side interval 0.887-1.993 s (median
    1.291), old client stopwatch 1.528-3.147 s (median 2.193), i.e. 0.605-1.166 s of harness
    overhead removed per run
    . Worst server-side observation leaves 3.0x headroom under the
    unchanged 6 s bound.
  • Each change proven load-bearing by mutation: reverting only the measurement makes the injected
    delay fail again; removing only the allow_errors hoist brings the mask back; hoisting
    expect_errors instead reproduces the inverted-polarity mask.
  • Whole module 7/7 passing, and 20/20 passing under pytest --count 10 of both fixed functions
    (server-side interval min 0.146 / median 1.186 / max 2.151 s across those 20 runs, no negative
    values, i.e. ~2.8x headroom under the unchanged 6 s bound at the worst observation).

Out of scope, so that the row accounting is unambiguous. A 30-day CIDB search for
%test_cancel_backup.py::test_cancel_% returns 40 rows in total, which decompose as:

module test signature rows PRs
test_backup_restore_on_cluster test_cancel_backup timing / mask 13 11 + master + 26.6
test_backup_restore_on_cluster test_cancel_restore timing / mask 1 1 (#109374)
test_backup_restore_on_cluster test_cancel_backup leftover znode 12 2
test_backup_restore_on_cluster test_cancel_restore leftover znode 12 2
test_backup_restore_new test_cancel_backup timing / mask 2 1

The 14 bold rows are what this PR fixes. The 24 leftover-znode rows are a different assertion in
the same file (__exit__ reporting a leftover /clickhouse/backups/... node) and occur only on
#109785 and
#109786, never on master or any other
PR, so they belong to those cancellation-engine branches. The remaining 2 rows are a different
module, test_backup_restore_new/test_cancel_backup.py, which this PR does not touch and which
contains no timing assertion at all.

Version info

  • Merged into: 26.8.1.470 (included in 26.8 and later)

groeneai and others added 5 commits July 27, 2026 11:58
`test_cancel_backup` and `test_cancel_restore` assert that a cancellation is
prompt, but they measured it with a client-side `time.monotonic()` stopwatch
spanning `kill_query` through `wait_status`. In this harness every
`node.query(...)` is a `docker exec` of a fresh `clickhouse-client` (0.5-1 s
each), and that window held three to four of them plus `wait_status`'s
whole-second poll quantum, so the assertion bounded harness round-trip overhead
rather than the cancellation.

The result was a chronic flaky failure: 24 rows over 25 days across 13 pull
requests, two of them on master. Decomposing all 12 rows of that signature
family with timestamps the test already prints, the engine-side cancellation was
1.90-3.24 s (median 2.33) in every single failure against harness overhead of
2.94-5.91 s. The engine cancelled promptly every time; only the measurement was
wrong.

Measure the same interval between two server-recorded endpoints instead: the
KILL query's own `query_start_time_microseconds`, read from `system.query_log`
by an explicit `query_id`, and the initiator's `system.backups.end_time`. No
`clickhouse-client` launch is inside that interval, while the cluster-wide
cancellation still is -- `end_time` is stamped at the terminal transition, which
the initiator reaches only after `waitOtherHostsFinish`, so distributed
propagation remains bounded. Taking the start from the KILL statement itself
matters: in one recorded run a single client-to-server transition stalled
4.192 s, which alone would consume the whole budget.

The bound stays at 6 s. One assertion in, one assertion out, and no second
oracle: `query_duration_ms` was deliberately removed from this file in
19bcc55 and consolidated into the single end-to-end bound in
c26e0b4.

Separately, hoist `no_trash_checker.allow_errors` to checker entry so a body
failure surfaces as itself rather than being masked by `NoTrashChecker.__exit__`
asserting with both relaxation lists still empty -- which is what CIDB reported
for this test, hiding the real assertion. `allow_errors` is the correct one to
hoist because `__exit__` treats `expect_errors` as must-have-been-observed, so
hoisting that would create a new mask with inverted polarity for any failure
occurring before the cancellation. This matches ClickHouse#108459, which hoisted
`allow_errors` for two sibling functions in this file.

Co-Authored-By: Claude Opus 5 <[email protected]>
Follow-up to the server-side measurement in this file, addressing two review
findings.

First, `kill_query` did the `system.query_log` lookup itself, immediately after
the `KILL ... SYNC` returned and before returning to the caller -- that is, in
between the two server-recorded endpoints the test measures. Because both
endpoints are server-recorded those two client round trips add no wall clock of
their own, which is precisely the defect being fixed; but an unscoped
`SYSTEM FLUSH LOGS` is a MergeTree INSERT into every system log on that node,
and `node_to_cancel` is the node the initiator is still waiting for in
`waitOtherHostsFinish` in two of the three draws. Any perturbation is therefore
one-way upward, toward the assertion this file exists to stop failing, and it
contradicts the invariant the code comment states.

Move the lookup into `get_query_start_time`, called only after `wait_status` has
returned, so the measurement performs no work at all inside the interval it
measures. `kill_query` now returns the `query_id` it used; `system.query_log` is
a persisted MergeTree table, so the row is still there afterwards. The flush is
narrowed to `query_log` while it moves. The single-row guard moves with the
code, so a vanished oracle still fails loudly instead of silently skipping the
timing check.

Second, add a lower bound to both assertions. The two endpoints are independent
`CLOCK_REALTIME` reads, whereas the previous oracle was `time.monotonic()`. A
backward wall-clock step landing inside the window would otherwise produce a
negative interval that silently satisfies the upper bound, turning a too-slow
cancellation into a pass. The upper bound is unchanged at 6 s; the lower bound
only tightens.

Co-Authored-By: Claude Opus 5 <[email protected]>
Comment-only follow-up; no assertion, helper or behaviour is touched.

Three comments claimed that no clickhouse-client launch is inside the
measured interval. The measurement's own queries were moved out of the
interval, but wait_status still polls on a one-second quantum over the
same period, so the claim was stronger than the code delivers. Neither
endpoint can be moved by a poll (the KILL's query_start_time_microseconds
is written before the polls run, and end_time is stamped by the backup
thread in BackupsWorker::setStatus, not by the observing SELECT), so the
defensible statement is that client round-trip latency is no longer added
to the measurement. Reworded to say that instead.

The lower bound's justification claimed it catches a backward clock step
making a too-slow cancellation look fast. With a true interval T and a
step S the measured value is T - S, which is only negative for S > T, so
a 3 s step during an 8 s cancellation still satisfies the upper bound.
Reworded to state what the clause actually guards: the switch from a
single time.monotonic() stopwatch to two independent CLOCK_REALTIME reads
makes a negative interval possible, and the lower bound turns that into a
loud failure rather than a value that silently passes the upper bound.

Co-Authored-By: Claude Fable 5 <[email protected]>
The comment said the interval covers "the whole cluster-wide cancellation"
because end_time is stamped after the initiator finished waiting for the other
hosts. That wait is bounded on the error path: BackupsWorker calls
waitOtherHostsFinish(throw_if_error = false), which BackupCoordinationStageSync
turns into a wait capped by backup_restore_finish_timeout_after_error_sec, set
to 3 s by this module's own profile. So the cancellation is inside the interval
only up to that cap. The conclusion is unchanged: this is the same terminus the
previous client-side stopwatch used, and a host still cancelling afterwards is
caught by the get_num_system_processes() assertion that immediately follows.

Comment-only, zero behaviour change.

Co-Authored-By: Claude Fable 5 <[email protected]>
The comment above the time_to_cancel computation had grown to 12 lines of
motivation and history, roughly three times the longest comment block this
file already had. Per the project convention that context belongs in the
commit message rather than in code comments, it is reduced to the invariant a
reader needs at that line: both endpoints are server-recorded, so neither
wait_status's polling loop nor the system.query_log lookup above it can move
them, and the right endpoint is stamped after the initiator waited for the
other hosts, capped on the error path by
backup_restore_finish_timeout_after_error_sec (3 s in this module's profile).

The rationale removed from the code is preserved here.

The measured interval terminates at the same wait_status() return the previous
time.monotonic() stopwatch ended at, so this change narrows nothing: the
assertion covers exactly the same span of the cancellation as before, it is
only measured from two server-recorded timestamps instead of a client-side
stopwatch.

A host that is still cancelling past the 3 s error-path cap is not left
unchecked: the pre-existing assert get_num_system_processes(nodes, ...) == 0 on
the following line fails if any node still has the operation running.

The point of using two server-recorded endpoints is that no client round trip
is added to the measurement. The KILL QUERY's own client launch happens before
the left endpoint is recorded, and the system.query_log lookup that resolves
that endpoint runs after the terminal status was stamped, so neither is inside
the interval.

No behaviour change: the delta is comment text only.
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review - 6 rounds, 3 majors found and fixed, 1 nit noted (click to expand)

Before publishing, this PR went through six rounds of independent cold review, each paired with a
second-model review pass (a different model, reviewing the resulting code with no access to the
authoring rationale). Rounds 1-5 raised 14 findings that were adjudicated against the code (13
upheld, 1 withdrawn); the sixth round and the final second-model pass each raised nothing. The
three majors that changed behaviour are below, with the one nit that was noted rather than acted
on. The remaining upheld findings only corrected this PR's own description or a code comment and
are not itemised.

Finding Verdict
❌ The measurement did work inside the interval it measures. kill_query ran an unscoped SYSTEM FLUSH LOGS plus the system.query_log read after the KILL ... SYNC and before returning, i.e. strictly between the two endpoints. Because both endpoints are server-recorded, those launches add no wall clock of their own, but they can inflate end_time through contention on the very node the initiator is still waiting for in waitOtherHostsFinish, which is 2 of the 3 random node_to_cancel draws, and the perturbation is one-way upward. It also contradicted the invariant this PR itself asserts. AGREE, fixed. kill_query now returns the KILL's query_id; the timestamp is resolved after wait_status returns, via a helper using SYSTEM FLUSH LOGS query_log (narrowed) and the same single-row loud-failure assert. Nothing runs between the two endpoints any more.
❌ The timing oracle had no lower bound. The two endpoints are independent CLOCK_REALTIME reads, whereas the previous oracle was time.monotonic(). A backward wall-clock step inside the ~1-2 s window would yield a negative or under-reported interval that silently satisfies <= 6, losing detection rather than failing. Two further scenarios the finding suggested were checked and are unreachable: a 0 end_time is impossible (setStatus writes status and end_time_us under one infos_mutex, and system.backups reads under the same mutex, while wait_status returns only after asserting a final status), and a malformed timestamp raises in strptime. AGREE, fixed. Both call sites now assert 0 <= time_to_cancel <= 6; the 6 s upper bound is unchanged.
❌ The "whole cluster-wide cancellation is inside the interval" claim overstated the terminus. A cancellation is an exception path, so waitOtherHostsFinish is called with throw_if_error = false, which makes the wait bounded by backup_restore_finish_timeout_after_error_sec; this module's own profile sets that to 3 s, after which checkIfOtherHostsFinish stops waiting and the terminal status stamps end_time. So the interval bounds the cancellation only up to that cap. AGREE on the mechanism, fixed in the comment and the description. The remedy the finding suggested (pin that timeout above 6 s, or use a last-remote-completion endpoint) was not taken: the timeout lives in a module-wide profile shared by three other test files, and per-host rows are filtered out of system.backups, so no such endpoint is readable from the initiator. Importantly the cap is not something this PR introduces or narrows - the previous time.monotonic() assertion ended at the very same wait_status(...) return - and a host still cancelling past the cap is caught by the pre-existing assert get_num_system_processes(nodes, ...) == 0 on the next line.
💡 Four further NoTrashChecker blocks in this file still assign their relaxation lists late and share the same masking class (get_backup_id_of_successful_backup, test_error_leaves_no_trash, and the two short-disconnection blocks). A final cold pass corrected an earlier claim here that none of them had ever been observed: re-deriving the mask signature per function over 30 days gives test_cancel_backup 13, test_cancel_restore 1, and test_short_disconnection_doesnt_stop_restore 1 (PR #109030, assert ('KEEPER_EXCEPTION' in [] or 'KEEPER_EXCEPTION' in [])), the other blocks 0. So one of the four is a confirmed carrier, not a latent one. Noted, still deliberately out of scope, and tracked for its own PR. Its failing statement is a transient from the ZooKeeper disconnection the test induces on purpose, not the timing assertion fixed here, so folding it in would put two unrelated root causes in one PR. test_short_disconnection_doesnt_stop_backup has the same shape with 0 observed rows and belongs in that same follow-up.

The failure premise and the row accounting were also re-verified independently of the authoring
notes. Over 30 days a CIDB search for %test_cancel_backup.py::test_cancel_% returns 40 rows,
which decompose into 14 rows of the timing/mask signature in this module (13 for
test_cancel_backup across 11 distinct PRs plus one master and one 26.6 run, and 1 for
test_cancel_restore), 24 leftover-znode rows confined to #109785 and #109786, and 2 rows in the
unrelated test_backup_restore_new module. Job logs fetched for four of the mask rows show the
masked body exception in each case (assert 6.576 <= 6, 8.635 <= 6, 6.722 <= 6,
6.509 <= 6), while the system.backups timestamps those same logs print put the engine-side
cancellation at roughly 2-5 s, i.e. inside intent.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The natural failure is a timing coincidence, so the mechanism is reproduced on demand by injecting a post-KILL harness delay into the client-measured window: on master the run fails with assert 6.660929953679442 <= 6 followed by the NoTrashChecker.__exit__ both-lists-empty assert (assert ('QUERY_WAS_CANCELLED' in []), byte-matching the CI signature. The same injection on this branch passes. (At a 4 s delay the injection is marginal (it depends on how long the KILL itself takes), so both directions are measured at one common 6 s delay.)
b Root cause explained? Yes. time_to_cancel was a client-side time.monotonic() stopwatch spanning kill_query -> wait_status. Every node.query(...) here is a docker exec of a fresh clickhouse-client (0.5-1 s each), and the window held 3-4 of them plus wait_status's whole-second poll quantum, so the assertion bounded harness overhead rather than the cancellation. Decomposing all 12 CIDB rows of this signature with timestamps the test already prints: engine-side cancellation 1.90-3.24 s (median 2.33) in every failure vs 2.94-5.91 s of harness overhead. The __exit__ assert CIDB reports is a mask: the body raised at the timing assert, so expect_errors was never assigned.
c Fix matches root cause? Yes, it changes how the interval is measured, to two server-recorded endpoints (the KILL's own query_start_time_microseconds keyed on an explicit query_id, and the initiator's system.backups.end_time), so client round-trip latency is no longer added to it: wait_status still polls over the same period, but neither endpoint can be moved by a poll, since the left one is written before the polling starts and the right one is stamped by the backup thread rather than by the observing SELECT. The system.query_log lookup itself was moved out of kill_query into a helper called only after wait_status() returns, so the measurement performs no work of its own inside the interval it measures. The upper bound stays 6 s (a lower bound 0 <= was added, which only tightens): no widened bound, no long tag, no reduced dataset, no retry loop, no no-random-* tag.
d Test intent preserved / new tests added? Yes. One assertion in, one out. Coverage is not reduced: tightening the bound to 1 still fails (assert 1.727685 <= 1) and to 0.001 still fails, both against the new two-sided form; and the interval still spans post-KILL distributed propagation (mechanism: end_time is stamped only after waitOtherHostsFinish, which is gated on !is_internal_backup and, on the error path a cancellation takes, capped by backup_restore_finish_timeout_after_error_sec (3 s in this module's profile) - the same terminus the previous assertion had, with a host still cancelling past the cap caught by the get_num_system_processes(nodes, ...) == 0 line; measured for a non-initiator KILL the interval exceeds the KILL's own query_duration_ms in 3 of 4 runs, the fourth being a 23 ms near-tie at the resolution floor of the two instruments). The happy-path assert "QUERY_WAS_CANCELLED" in get_error(...) and the expect_errors requirement are untouched. This is a test-only flakiness fix, so no new product test applies.
e Both directions demonstrated? Yes. Post-KILL delay: master FAIL (7.046611601021141 <= 6 + mask) / branch PASS. Pre-KILL delay: master FAIL (8.464172929991037 <= 6) / branch PASS. Same both-directions result for test_cancel_restore (master 8.350874878000468 <= 6).
f Fix is general across code paths? Yes. Timing-bound carriers re-derived by grep -nE "assert (waited|time_to_|time_before)": both test_cancel_backup and test_cancel_restore are fixed (the latter is a confirmed live carrier, PR #109374 shows assert 6.143040713999653 <= 6 plus the same mask). test_long_disconnection_stops_backup's > 3 / < 45 bounds are deliberately untouched: overhead can only push the lower bound up, and the upper has ~40 s of slack. kill_query's assert waited < timeout is unreachable (no caller passes timeout since c26e0b413fa619) and is left as-is rather than cleaned up, to stay in delta.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for datatypes (test-only change, no product code). The relevant input axis is the randomised cancel draw (random.choice over three options): both the initiator and non-initiator structures were forced and pass for both functions, and they were verified to have materially different timing signs. Integration-test randomisation (max_joined_block_size_rows, max_block_size, query_plan_join_swap_table) does not touch this path.
h Backward compatible? (maintainer-approved exception only) N/A, test-only. No setting default, no serialization format, no SettingsChangesHistory.cpp entry.
i Invariants and contracts preserved? Yes. Both helper changes are purely additive return values. wait_status has 8 call sites; only the two being fixed consume the value and the other 6 ignore it unchanged. kill_query has exactly 2 call sites, both in the fixed tests. No assertion was added inside kill_query and the previously removed duration/timeout comparison is not reintroduced; the existing prints are kept so grep-able log output stays recognisable. The relocated lookup preserves the same guarantee from the other side: a programmatic scan shows zero node.query( calls between the KILL ... SYNC and the wait_status(...) return at both call sites, and the len(rows) == 1 loud-failure guard moved with the code (verified by mutation: pointing the read at a nonexistent query_id fails from inside the new helper). Cross-container timestamp comparability holds (the harness uses no time namespace, so both DateTime64(6) values are on the shared host CLOCK_REALTIME), and because the two endpoints are independent CLOCK_REALTIME reads rather than the previous time.monotonic(), a backward wall-clock step between them can now yield a negative interval, which would satisfy <= 6 silently; both assertions therefore carry a lower bound that turns that into a loud failure (it catches the negative case, not every backward step), proven load-bearing by negating the interval, which fails with the clause and passes without it. Zero negative intervals across all 20 --count 10 runs (min 0.146 s). The whole module still passes 7/7 with the relocated lookup.

Session id: cron:clickhouse-impl-slot-46:20260727-175800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @pamarcos - could you review this? It fixes a flaky timing assertion in test_cancel_backup.py: time_to_cancel was a client-side time.monotonic() stopwatch spanning 3-4 docker exec clickhouse-client launches, so assert time_to_cancel <= 6 bounded harness overhead rather than the cancellation (engine-side was 1.90-3.24 s in all 12 failing CI rows). The same interval is now measured between two server-recorded timestamps, with the 6 s bound unchanged.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7d27246]

Summary: ✅


AI Review

Summary

This PR replaces the client-side stopwatch in test_backup_restore_on_cluster/test_cancel_backup.py with server-recorded timestamps from system.query_log and system.backups, and hoists the QUERY_WAS_CANCELLED allowance so NoTrashChecker no longer masks a real body failure. I did not find any blocking or major issues in the current diff; the new timing oracle is aligned with the stated goal of measuring cancellation rather than harness latency, and the current Praktika run is all green.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 7d27246

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

CI is fully finished on this head and there are no failures: Finish Workflow = success,
the praktika aggregator reports PR: OK, and 174 check runs resolve to 30 success / 144
skipped, with zero queued or in-progress. CIDB agrees for this commit (0 FAIL/ERROR rows
across every reporting check).

Check / test Reason Owner / fixing PR
n/a no failing check on this commit n/a

Green checks that actually exercised the change: Integration tests (amd_asan_ubsan, targeted),
Integration tests (amd_asan_ubsan, flaky), plus the amd_tsan, amd_msan,
amd_asan_ubsan (db disk, old analyzer) and arm_binary (distributed plan) integration shards,
Style check and Code Review. The remaining jobs are skipped by the changed-files filter,
which is expected for a diff confined to tests/integration/test_backup_restore_on_cluster/.

Session id: cron:our-pr-ci-monitor:20260728-100000

@alexey-milovidov alexey-milovidov self-assigned this Jul 30, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 30, 2026
Merged via the queue into ClickHouse:master with commit a09867f Jul 30, 2026
178 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 30, 2026
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Aug 7, 2026
…n_stops_backup

test_long_disconnection_stops_backup fails as `assert 45.54 < 45`. `time_to_fail`
was the difference of two `time.monotonic()` reads in the pytest process, so it
charged the backup's abort latency for the `iptables` `docker exec` in
`drop_instance_zk_connections` and, dominantly, for one fresh clickhouse-client
process per poll iteration of `wait_status`. That overhead grows with the abort
latency itself, so a contended runner crosses the ceiling while the engine is
nowhere near it.

PR ClickHouse#112217 established this for the two sibling tests in this file and converted
them to server-recorded timestamps, adding `seconds_between` and making
`wait_status` return the server-stamped `end_time`. This call site was left
behind: `end_time` was already returned and simply discarded here. It was the
file's last timing assertion on a client-side stopwatch.

The left endpoint is now a `SELECT now64(6)` on the initiator, issued last before
the disconnection. `now64` is evaluated on the server, so the client launch falls
outside the interval, while placing the marker before the drop keeps the whole
abort covered and can only widen the interval on its left edge, never shrink it.
Both bounds (`> 3` and `< 45`) are unchanged, so the assertion becomes strictly
tighter against a real abort-latency regression rather than being relaxed.

Unlike the two siblings, no `0 <= time_to_fail` guard is added: the retained
`> 3` already excludes the negative interval a backwards wall-clock step could
produce, and is strictly stronger. Verified by calling the helper directly, an
epoch-zero `end_time` yields a large negative value that satisfies `< 45` but
fails `> 3`, and an empty or `\N` `end_time` raises instead of silently passing.

Validation: an instrumented probe printing both numbers side by side shows the
server-side value smaller in 20 of 20 runs (gap min 0.264, median 0.680, max
1.318 s), the median alone exceeding the 0.54 s overshoot the failure reported.
Both directions were demonstrated with a per-run ceiling placed between the two
measurements: the client-side arm fails 6 of 6 with the original signature, the
server-side arm passes 6 of 6. Since the two disconnection cases differ in floor,
the lower bound was checked per case: 15 runs with a non-initiator dropped, min
6.236 s, and 5 with the initiator itself dropped, min 9.673 s. 50 repeats of the
test pass, and a 5x module run over all 7 tests is 35 of 35 on both the pristine
and the fixed arm with identical failing sets.
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 13, 2026
…e-timing

Measure cancellation server-side in test_cancel_backup.py

(cherry picked from commit a09867f)
clickhouse-gh Bot added a commit that referenced this pull request Aug 13, 2026
Backport #112217 to 26.7: Measure cancellation server-side in test_cancel_backup.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci 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.

4 participants