Skip to content

Add coverage tests for three untested MergeTree/replication branches - #114296

Merged
PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:coverage-mergetree-replication-batch2-group-e
Aug 12, 2026
Merged

PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:coverage-mergetree-replication-batch2-group-e

Conversation

@groeneai

@groeneai groeneai commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #101781
Related: #103935
Related: #103939

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-only, 6 files, no src/ changes. @ zlareb1 asked me to re-file a batch of closed clickgapai coverage PRs; this is the MergeTree-refresh / progress / replication group. A fourth (#101284, skip_unused_shards through nested views) is not included: its mechanism is already pinned by five existing tests, and I have said so on its own thread instead of shipping a duplicate.

For each original I mutated the exact line it claims to cover, rebuilt, and required that test to fail while the others and the pre-existing tests of the same mechanism stayed green. All three oracles passed with their mechanism broken:

Validation

Debug build, clickhouse-test with randomization on (the CI default). Each mutation changes the branch's output rather than deleting it, so a fall-through to an equivalent path cannot be mistaken for a vacuous test. Every arm was reverted and rebuilt before the next, with the Build ID asserted to change and to match the running server's.

test mutated line result
04089_merge_tree_refresh_after_merge MergeTreeData.cpp:3289 grabOldParts(true) -> (false) FAIL (Deleting 3 -> Outdated 3); other 2 OK
04201_read_rows_external_group_by AggregatingTransform.cpp:150 getReadProgress override deleted FAIL (read_rows_wrong:200000, exactly 2x the input); other 2 OK
04201_replicated_replace_partition_drop_intent ReplicatedMergeTreeQueue.cpp:284 intent match neutered FAIL (intent: yes -> no); other 2 OK

Each mutation also had to leave the pre-existing tests of the same mechanism green, so that "it reddens when I break the code" is not mistaken for incremental coverage: the four refresh_parts_interval tests, the two spill tests, and seven REPLACE PARTITION / part-check tests respectively. All green.

  • 50 randomized plus 50 --no-random-settings runs of each: 0 failures, so nothing needed pinning beyond the tags the sibling tests already carry.
  • The two untagged tests run concurrently with themselves: 16/16 OK, so neither takes no-parallel.
  • no-parallel on the third is earned rather than assumed: concurrently with itself the untagged form gives 2 OK / 2 FAIL, and with the once-only pause released mid-window it fails outright, while the tagged form is 4/4 OK.
  • The gaps were re-measured against the mechanism, not the setting name: 0 of the 4 refresh_parts_interval tests ever OPTIMIZE; none asserts read_rows after a spill; none contains the intent guard's message.

Version info

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

Re-files three closed clickgapai coverage PRs (ClickHouse#101781, ClickHouse#103935, ClickHouse#103939) that
@ zlareb1 asked to be reopened. A fourth, ClickHouse#101284, is not included: its mechanism
is already pinned by five existing tests, so it would be a duplicate.

Each branch was mutated, rebuilt and re-run to confirm the test detects it, and
each mutation had to leave the pre-existing tests of the same mechanism green so
that reddening is evidence of incremental coverage rather than of the mechanism
merely being live. Two of the three originals failed that check:

- ClickHouse#101781 asserted count() = 3 after the writer merged. The pre-merge state is
  also 3 rows, so a run in which the refresh never happened is indistinguishable
  from a correct one. An active-part count is no better: refreshDataPartsOnce
  commits the merged part with the same Transaction::commit that demotes the
  parts it covers, upstream of grabOldParts, so the active set is 1 in both
  directions. The test now asserts the part state through the _state virtual
  column, which is Deleting on master and Outdated when grabOldParts is not asked
  to force removal. The refresh is driven by SYSTEM RESTART DISK, which calls the
  same body synchronously, so no sleep is needed, and the writer's merges are
  bracketed by SYSTEM STOP/START MERGES so its own scheduler cannot merge the
  three inserts before the first assertion.

- ClickHouse#103939 asserted count() <= 10 while a REPLACE PARTITION and a mutation raced
  for ten seconds. That passes whenever the race is not won, which is the likely
  outcome; measured against a binary with the guard broken, it still passes. It
  is replaced by a deterministic sequence: the REPLACE is parked inside its own
  intent window on the existing rmt_cancel_removed_parts_check_pause_in_gap
  failpoint, reached from replacePartitionFrom via cancelRemovedPartsCheck while
  the intent is held, and the test then asserts the mutation entry's
  postpone_reason in system.replication_queue. That column is the one the guard
  writes; system.mutations.parts_postpone_reasons carries a different vocabulary
  fed only by the merge-selection path, so polling it would never observe this.

ClickHouse#103935 was sound and is adopted close to as written. Only its cited line was
stale: the override is at AggregatingTransform.cpp:150, not :143.

The coverage gaps were measured against the mechanism rather than the setting
name, which is what the ClickHouse#101284 duplicate turned on. None of the four
refresh_parts_interval tests ever merges, no test asserts read_rows after an
external GROUP BY spills through any observable, and no test contains the intent
guard's message.

no-parallel is on the replication test only, and is earned rather than assumed:
run concurrently with itself the untagged form fails because a second copy
consumes the once-only pause, while the tagged form passes. The other two carry
no such tag and were run concurrently with themselves to confirm it.
Review round 1: each of the three tests could pass while the branch it names
is broken, which is the same vacuity the tests were written to remove from the
closed PRs they replace. No production code is touched.

The read_rows test ran its query twice: once to prove the aggregation spilled,
once over HTTP to read the summary, so the assertion was made about a run whose
spill was never verified. That is reachable rather than theoretical, because the
query produces exactly group_by_two_level_threshold distinct keys and the spill
needs the threshold to be crossed, so whether it spills is decided per run; a
non-spilling second run legitimately reports 100000 and prints read_rows_correct
with the getReadProgress override deleted. It now runs once under a query id
scoped to the test database and reads both facts from that row of query_log,
which is the same progress accounting the summary reported. A query id, unlike a
log comment, cannot be inherited by a fuzzed re-execution, so no fuzzer pin is
needed. The row is taken with LIMIT 1 rather than an aggregate, so that no row
at all leaves both values empty and fails loudly.

The intent guard is consulted before the first entry-type branch in
shouldExecuteLogEntry, so any entry producing a part in the replaced range
writes the same postpone reason, and the test matched on database and table
only. It now names MUTATE_PART, which is the type its own captured reason
carries. Measured against a binary with the intent match neutered, no intent
reason is written for any entry type, so the arm still fails for the original
reason rather than for the added filter.

The mutation-settle loop had no failure branch, so after 120 polls it fell
through to a row assertion that the REPLACE PARTITION alone satisfies, leaving a
stuck mutation green. It now reports a timeout, silently on success so the
reference is unchanged. Forcing that path makes the test fail with the token,
which two earlier attempts at the control did not: stopping the replication
queue and parking the mutate task both left the test green, because the REPLACE
drops the part the mutation targeted and the mutation is already done by the
time the loop is reached.

Both mutation arms were rebuilt with the Build ID asserted to move, and each
left the pre-existing tests of the same mechanism green. The three references
are byte-identical, every tag and setting survives, and both edited tests ran 50
randomized plus 50 fixed-settings runs without a failure.
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

Two review rounds before publishing: an independent cold read of the resulting code, then a
second-model pass, adjudicated against source. Round 1 found three real problems, all the same
class as the defect this PR exists to remove, and all three are fixed in c81b66c. Round 2
found one nit, dispositioned below.

Round 1: 3 accepted, all test-liveness

Finding Verdict
❌ 04201_read_rows ran the query twice, so the read_rows assertion was made about an execution whose spill was never verified. Reachable, not theoretical: the query yields exactly group_by_two_level_threshold keys (Aggregator.cpp:83-89, Settings.cpp:1231), so spilling is decided per run, and a non-spilling second run prints read_rows_correct with the override deleted. AGREE, fixed: one execution, unique query id, both facts from one system.query_log row. Not a weaker observable (ProcessList.cpp:874 -> executeQuery.cpp:402 is the same counter the HTTP summary reported). Mutation arm re-run and still reddens with read_rows_wrong:200000.
❌ The postpone-reason oracle filtered database and table only, but isIntersectingWithDropReplaceIntent is consulted at ReplicatedMergeTreeQueue.cpp:1670, before the first entry-type branch at :1673, so a fetch or merge entry writes the identical reason. AGREE, fixed: AND type = 'MUTATE_PART', which is what the captured reason itself carries (ReplicatedMergeTreeLogEntry.cpp:50). Mutation arm still fails for the original reason, not merely for a type mismatch.
❌ The mutation-settle loop had no failure branch, so after 120 polls it fell through to a row assertion that the REPLACE PARTITION alone satisfies, leaving a stuck mutation green. AGREE, fixed: reports a timeout token absent from .reference, silent on success. Negative control required and performed: forcing the path fails with mutation did not settle. Two earlier attempts at that control did NOT redden, which is why it was demanded.

Round 2: 1 nit, not blocking

Finding Verdict
💡 no-fasttest on the refresh and read_rows tests is unnecessary: the sibling plain_rewritable refresh tests and two external-aggregation tests run without it. DISAGREE. The factual half reproduces, but dropping the tag admits both tests into a build and server configuration this PR has not validated in: -DENABLE_LIBRARIES=0 -DENABLE_TESTS=0 (ci/jobs/fast_test.py:266-274), no abort_on_logical_error (tests/config/install.sh:244-246), max_execution_time: 60 (:292-294), plus --timeout 60 --no-long. A Fast test failure is PR-caused by definition, so trading a validated lane set for an unvalidated one for consistency is the wrong trade on a nit. The tag is also unremarkable: 103 of the 438 stateless tests that read system.query_log carry it. No coverage is lost - both tests run in every Stateless flavor. Happy to drop it if a maintainer prefers.

Also verified independently of the implementation notes, so these are not taken on trust:
the intent window is entered deterministically (intent added at
StorageReplicatedMergeTree.cpp:9279, cancelRemovedPartsCheck called at :9286 inside it,
pause at ReplicatedMergeTreePartCheckThread.cpp:125); _state is the only observable that
can discriminate the refresh arms, because Transaction::commit demotes covered parts itself
and only grabOldParts(true) at MergeTreeData.cpp:3289 moves them to Deleting; nothing
else can hold those parts, since the readonly reader never starts its cleanup thread
(StorageMergeTree.cpp:241); both no-random-settings tags are load-bearing
(optimize_aggregation_in_order alone closes the spill path via AggregatingStep.cpp:404-421);
no-parallel is earned under the waits-on-failpoint test and matches both in-tree users of the
same failpoint; and no functional test here fabricates or hand-modifies a data part.

Two further nits were raised and dropped with evidence: the ZooKeeper path uses the
database-only form where 99 of 100 zookeeper tests use CLICKHOUSE_TEST_ZOOKEEPER_PREFIX
(equally collision-free, nothing enforces it), and a wording point about "the two spill tests"
that the body's own gap sentence already settles.

Session id: cron:clickhouse-review-slot-9:20260811-080600

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for all three. Each mutant reddens its own test on demand, with no timing dependence: the refresh is driven by SYSTEM RESTART DISK (synchronous) and the intent window by SYSTEM WAIT FAILPOINT ... PAUSE, so neither test sleeps or races.
b Root cause explained? These are coverage tests, so the "root cause" is the untested branch: grabOldParts(true) in refreshDataPartsOnce (MergeTreeData.cpp:3289), SourceFromNativeStream::getReadProgress (AggregatingTransform.cpp:150), and isIntersectingWithDropReplaceIntent as consulted from shouldExecuteLogEntry (ReplicatedMergeTreeQueue.cpp:1670). Each gap was measured, not assumed.
c Fix matches root cause? Yes. Each test asserts the branch's own observable output (the part-state transition, read_rows, the queue entry's postpone_reason) rather than a downstream proxy. Two of the three originals asserted a proxy that a non-executing run also satisfies; both were replaced.
d Test intent preserved / new tests added? The PR is new tests. No existing test is modified, weakened, or deleted. Each adopted source PR's coverage intent is kept while its mechanism is replaced.
e Both directions demonstrated? Yes, three mutant/baseline pairs. Each mutant changes the branch's output rather than deleting the branch, each build's Build ID was asserted to move, and each server's buildId() was asserted to equal the ELF Build ID before measuring. Reverting all mutants reproduced the baseline Build ID bit-identically.
f Fix is general across code paths? Sibling paths were enumerated rather than assumed, and each mutant had to leave them green: the four refresh_parts_interval tests; the two pre-existing external-aggregation tests; and 03920 (the non-replicated twin), 04603, 04604 plus four other REPLACE PARTITION tests. no-shared-merge-tree is tagged where the mechanism is ReplicatedMergeTree-specific.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A by design. None of the three branches is type-dependent, and each test uses the smallest input that reaches its branch (3 one-row parts; 100000 rows; 100 vs 10 rows). Adding a wrapper matrix would only add rows no mutant needs.
h Backward compatible? N/A. Test-only: no settings, no defaults, no SettingsChangesHistory.cpp, no serialization, no headers, zero src/ changes.
i Invariants and contracts preserved? No production code changes. Test-side: every table is scoped to ${CLICKHOUSE_DATABASE} and temporary files to ${CLICKHOUSE_TMP}; the failpoint is released by a trap on every exit path, verified by system.fail_points reporting 0 enabled after deliberately-failing runs, which is exactly the early-exit case.

Session id: cron:clickhouse-impl-slot-41:20260811-043300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tiandiwonder, could you review this? It is test-only: three coverage tests for branches nothing pinned, and each replaces its source PR's oracle, which I measured to pass with the mechanism broken (a part-state assertion via _state for the readonly refresh retirement, one execution read out of system.query_log for read_rows after a spill, and a failpoint-parked REPLACE PARTITION asserting the drop-replace intent's postpone reason instead of a race).

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

clickhouse-gh Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d19fa93]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, parallel) FAIL
04357_distributed_alias_same_expression FAIL cidb IGNORED
Stress test (arm_msan) FAIL
Hung check failed, possible deadlock found FAIL cidb IGNORED

AI Review

Summary

This PR adds three stateless coverage tests for readonly plain_rewritable refresh retirement, external aggregation read_rows, and the REPLACE PARTITION / mutation drop-replace intent window. I reviewed the current diff against the touched production paths and the prior PR discussion, and I did not find any remaining correctness or test-liveness issues in the current revision.

Final Verdict

✅ No new findings in the current diff. No inline review comments posted.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 11, 2026
The style check's *.sh branch (ci/jobs/scripts/check_style/various_checks.sh)
accepts only the literals $CLICKHOUSE_TEST_ZOOKEEPER_PREFIX or {database} inside
a ReplicatedMergeTree argument list. The .sql branch additionally accepts
currentDatabase() and {uuid}, which is why the ${CLICKHOUSE_DATABASE} form read
as correct.

Uniqueness is not weakened: shell_config.sh exports
CLICKHOUSE_TEST_ZOOKEEPER_PREFIX as "${CLICKHOUSE_TEST_NAME}_${CLICKHOUSE_DATABASE}",
so the new path still carries the database and adds the test name. Verified in
system.replicas and system.zookeeper that the tables occupy the new path, and
re-ran the oracle plus its settle-guard negative control against it.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Style check fixed in d19fa93.

The *.sh branch of ci/jobs/scripts/check_style/various_checks.sh accepts only the literals
$CLICKHOUSE_TEST_ZOOKEEPER_PREFIX or {database} in the engine argument list (the *.sql branch
also accepts currentDatabase() and {uuid}, which is why ${CLICKHOUSE_DATABASE} read as
correct). Both paths now use $CLICKHOUSE_TEST_ZOOKEEPER_PREFIX, which shell_config.sh:18 defines
as ${CLICKHOUSE_TEST_NAME}_${CLICKHOUSE_DATABASE}, so uniqueness is stronger, not weaker. One
comment in the same file was also wrong about SYSTEM WAIT FAILPOINT ... PAUSE: it returns once a
thread reaches the pause, and the thread stays parked until notify or disable
(src/Common/FailPoint.cpp:448-466).

The path change moves which znodes the tables occupy, so it was re-validated rather than assumed
neutral: style rule 1 violation before / 0 after; system.replicas.zookeeper_path confirms the new
path; 100/100 runs of the drop-intent test (50 randomized + 50 fixed); its settle-guard negative
control still reddens; system.fail_points clean afterwards.

No coverage ran on c81b66c (Style check gated the matrix), so no ledger is owed for that head.

Session id: cron:clickhouse-maint-slot-14:20260811-110100

@PedroTadim PedroTadim self-assigned this Aug 11, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - d19fa93

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.

Run shape, so nobody reads this as a thin run: 175 checks = 2 failure / 56 success / 117 skipped,
Config Workflow and Finish Workflow both SUCCESS, and the praktika report has 0 DROPPED
jobs (every skip carries a real reason: not affected by the changed files, no build-affecting
changes, not labeled pr-performance, and so on). This is genuine coverage, not a dropped matrix.

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, parallel) / 04357_distributed_alias_same_expression flaky, result diff: the 300 300 2 group comes back split as two 300 300 1 rows #108855 (mine, open)
Stress test (arm_msan) / Hung check failed, possible deadlock found cancelled DROP TABLE prometheus parked in DatabaseCatalog::waitTableFinallyDropped, convoying DETACH DATABASE and DROP DATABASE ... SYNC behind the DDL guard #114302 (external, open)

Neither failure touches this PR's diff, which adds three stateless test files and changes no
src/. Attribution notes:

  • 04357 is the split-count wrong-results signature of duplicate-ALIAS GROUP BY on a
    Distributed table under two-level aggregation: the shard collapses the duplicate keys into one
    and buckets by one key, the initiator merges by two, so equal groups land in different buckets
    and are never merged. The in-run diagnosis reports 17 of 82 reruns failing on the same
    randomized settings, and the failure is present across many unrelated PRs and on master.
    Fix wrong results for duplicate-ALIAS GROUP BY on a Distributed table under two-level aggregation #108855 fixes exactly that merge-key mismatch.
  • The hung check is the TimeSeries inner-table drop hang. The processlist in hung_check.log
    shows DROP TABLE prometheus (cancelled, 770s) waiting in waitTableFinallyDropped under
    StorageTimeSeries::dropInnerTableIfAny -> DatabaseAtomic::dropTable, with
    DROP DATABASE ... SYNC (663s) and DETACH DATABASE (396s) queued behind it on the DDL guard.
    Fix inner table drop hang #114302 defers the inner-table wait until after the DDL guard is released and makes it
    interruptible by KILL QUERY, which is that mechanism.

Session id: cron:our-pr-ci-monitor:20260811-160000

@PedroTadim
PedroTadim added this pull request to the merge queue Aug 12, 2026
Merged via the queue into ClickHouse:master with commit a96787f Aug 12, 2026
178 of 181 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 2026
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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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.

3 participants