Skip to content

Support parallel replicas read for Alias engine - #107830

Merged
scanhex12 merged 6 commits into
ClickHouse:masterfrom
nauu:support_parallel_read
Jun 24, 2026
Merged

scanhex12 merged 6 commits into
ClickHouse:masterfrom
nauu:support_parallel_read

Conversation

@nauu

@nauu nauu commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Alias engine now supports parallel replicas read when the target table is a MergeTree family engine.

As a consequence of the isMergeTree proxy, getCheckTaskList and checkDataNext are also proxied to the target, so CHECK TABLE and CHECK DATABASE work correctly on Alias tables.

Version info

  • Merged into: 26.7.1.22

@clickhouse-gh

clickhouse-gh Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4e77c38]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_binary, parallel) FAIL
03518_alter_logical_race FAIL cidb
Stress test (arm_tsan) FAIL
Logical error: Part A doesn't exist (info: B) (STID: 3208-4421) FAIL cidb
Stress test (arm_msan) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue
Stress test (arm_ubsan) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue
BuzzHouse (amd_tsan) FAIL
ThreadSanitizer: data race (STID: 2604-385d) FAIL cidb
AST fuzzer (arm_asan_ubsan) ERROR

AI Review

Summary

This PR makes Alias report the target's isMergeTree value and delegates CHECK tasks so an Alias over a MergeTree target can participate in parallel-replica reads. The earlier CHECK privilege and task-lifetime issues are fixed, but the broad isMergeTree change still affects default write routing, and the integration test still does not prove that two replicas actually read data. Verdict: block until the global isMergeTree side effect is contained and the test proves multi-replica participation.

Findings

❌ Blockers

  • [src/Storages/StorageAlias.h:30] [dismissed by author -- https://github.com/Support parallel replicas read for Alias engine #107830#discussion_r3438166285] The PR promises parallel-replica reads for Alias, but exposing Alias as MergeTree globally also makes InterpreterInsertQuery::distributedWriteIntoReplicatedMergeTreeOrDataLakeFromClusterStorage treat INSERT INTO alias SELECT ... FROM cluster(...) as a replicated MergeTree destination when parallel_distributed_insert_select = 2 (the default). That path serializes the original INSERT INTO alias to remote replicas and sets the main table to the alias StorageID. If the alias exists only on the initiator, the query now fails remotely; if remote aliases point at different targets, rows are inserted into different tables. This violates existing Alias write semantics where the initiator resolves and writes to the target. Keep isMergeTree false for generic storage capability checks and add a parallel-replica-read-specific unwrap/gate for Alias, or explicitly bypass/rewrite Alias in distributed insert-select so only the intended read path changes.

⚠️ Majors

  • [tests/integration/test_storage_alias_replicated/test.py:119] [dismissed by author -- https://github.com/Support parallel replicas read for Alias engine #107830#discussion_r3450672099] test_alias_with_parallel_replicas still only asserts ParallelReplicasUsedCount > 0. A count of 1 passes when only one replica gets work, so a regression that enables the coordinator but never dispatches a second replica would satisfy the test. Make the execution deterministic, for example by disabling parallel_replicas_local_plan and local preference as needed, keeping enough marks, and asserting >= 2; alternatively verify per-replica query log entries or another signal that both node1 and node2 participated.
Tests
  • ⚠️ The Alias parallel-replica read test still needs a two-replica assertion, not just a nonzero ParallelReplicasUsedCount.
  • ⚠️ Add coverage for INSERT INTO alias SELECT ... FROM cluster(...) with parallel_distributed_insert_select = 2, including either documenting/rejecting missing remote aliases or proving rows are routed to the same target on every replica.
Final Verdict

Status: ❌ Block

Minimum required actions: contain the global isMergeTree side effect for Alias so default distributed insert-select semantics do not change unexpectedly, and strengthen the parallel-replica test to prove that both replicas participate.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jun 18, 2026
@nauu nauu added the can be tested Allows running workflows for external contributors label Jun 18, 2026
Comment thread src/Storages/StorageAlias.h Resolved
Comment thread src/Storages/StorageAlias.h Resolved
@scanhex12 scanhex12 self-assigned this Jun 18, 2026
Comment thread src/Storages/StorageAlias.cpp Outdated

std::optional<CheckResult> StorageAlias::checkDataNext(DataValidationTasksPtr & check_task_list)
{
auto & tasks = dynamic_cast<AliasCheckTasks &>(*check_task_list);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's replace it with assert_cast, like in the StorageLog:

std::optional<CheckResult> StorageLog::checkDataNext(DataValidationTasksPtr & check_task_list)
{
    return file_checker.checkNextEntry(assert_cast<DataValidationTasks *>(check_task_list.get())->file_checker_tasks);
}


{
}

size_t size() const override { return inner->size(); }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's add

chassert(inner);


std::string getName() const override { return "Alias"; }

bool isMergeTree() const override

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.

isMergeTree is used by more than the SELECT parallel-replica planner. With parallel_distributed_insert_select = 2 (the default), InterpreterInsertQuery::distributedWriteIntoReplicatedMergeTreeOrDataLakeFromClusterStorage now treats INSERT INTO alias SELECT ... FROM cluster(...) as a replicated MergeTree destination and serializes the original INSERT INTO alias to every remote node. That changes existing Alias write semantics: if the alias exists only on the initiator, the query now fails remotely; if remote aliases point to different targets, rows go into different tables. Please avoid advertising Alias as MergeTree globally, or explicitly exclude/rewrite Alias in that distributed insert-select path so this PR only enables parallel-replica reads.

@nauu nauu Jun 18, 2026 •

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.

isMergeTree is used by more than the SELECT parallel-replica planner. With parallel_distributed_insert_select = 2 (the default), InterpreterInsertQuery::distributedWriteIntoReplicatedMergeTreeOrDataLakeFromClusterStorage now treats INSERT INTO alias SELECT ... FROM cluster(...) as a replicated MergeTree destination and serializes the original INSERT INTO alias to every remote node. That changes existing Alias write semantics: if the alias exists only on the initiator, the query now fails remotely; if remote aliases point to different targets, rows go into different tables. Please avoid advertising Alias as MergeTree globally, or explicitly exclude/rewrite Alias in that distributed insert-select path so this PR only enables parallel-replica reads.

Alias behaves like a MaterializedVIEW , it is the user's responsibility to ensure the alias is created consistently on all nodes. In practice, when using a Replicated database , DDL including CREATE TABLE xx ENGINE = Alias(yy) is replicated automatically, so all nodes see the same alias pointing to the same target.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree, the comment doesn't make sense

@nauu
nauu force-pushed the support_parallel_read branch 2 times, most recently from fa25b2e to 21ec518 Compare June 21, 2026 06:00
@nauu

nauu commented Jun 21, 2026 •

Copy link
Copy Markdown
Member Author

I still consider this a real compatibility regression because the PR promises parallel-replica reads while this affects default insert-select routing for existing aliases.

This behavioral change is acceptable. When the target table is MergeTree, Alias ought to support parallel_distributed_insert_select=2 , otherwise this will cause performance degradation.

@nauu
nauu force-pushed the support_parallel_read branch 2 times, most recently from a0917fd to f6e5edd Compare June 22, 2026 07:53
" AND type = 'QueryFinish' "
"ORDER BY query_start_time DESC LIMIT 1"
)
assert int(used_count.strip()) > 0, (

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 assertion no longer proves the behavior the test name promises. ParallelReplicasUsedCount is the number of replicas that received read assignments, so 1 satisfies > 0 even when the query used only one replica; then a regression that enables the coordinator for Alias but never actually distributes work to a second replica would pass. In this two-replica cluster please make the execution deterministic, for example by disabling parallel_replicas_local_plan and keeping enough marks/segments, and assert >= 2, or otherwise verify that both replicas participated.

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.

The test's purpose is to verify that the Alias engine supports parallel replicas, ParallelReplicasUsedCount > 0 enough to proves and this also consistent with many existing tests in the codebase .

@nauu
nauu force-pushed the support_parallel_read branch from f6e5edd to 4e77c38 Compare June 22, 2026 09:51
@clickhouse-gh

clickhouse-gh Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.40% +0.10%
Functions 92.60% 92.60% +0.00%
Branches 77.50% 77.60% +0.10%

Changed lines: Changed C/C++ lines covered by tests: 12/15 (80.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@nauu

nauu commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

@groeneai Are the failed tests related to this PR?

@groeneai

Copy link
Copy Markdown
Collaborator

@nauu No, none of the failures are caused by this PR.

This PR only adds isMergeTree() and CHECK TABLE proxying to StorageAlias (plus tests). I checked the stack/error of every failing check on 4e77c38: none contain a single StorageAlias/Alias-engine frame, and each signature is already failing on master and across many unrelated PRs (CIDB, last 30 days). Per-check:

1. Stateless tests (arm_binary, parallel) — 03518_alter_logical_race. Flaked once but passed all 3 reruns ("Failed 0 out of 3 reruns"), so it's not even a hard failure. Known chronic flake (18 distinct refs incl. 1 master in 30d); fix #108003 merged, follow-up #108060 open.
report

2. Stress test (arm_tsan) — LOGICAL_ERROR: Part patch-... doesn't exist in MergeTreeData::modifyPartState via ReplicatedMergeTreeSink::commitPart. Pre-existing trunk issue in the patch-parts / replicated-insert path (no Alias involvement); seen on 3 distinct refs incl. master in 30d.
report

3 & 4. Stress test (arm_msan) and (arm_ubsan) — both Hung check failed, possible deadlock found. This is the single most common stress-test flake on trunk: 686 hits across 301 distinct refs (284 of them on master) in 30d, across every sanitizer. No Alias frames in the hung threads.
arm_msan report / arm_ubsan report

5. AST fuzzer (arm_asan_ubsan) — Client failure (see logs). The fuzzer log tail is a clean sequence of DROP TABLE IF EXISTS statements with no Received signal / segfault / LOGICAL_ERROR / sanitizer report (the client simply disconnected). This job is itself flaky: it fails on 63 distinct refs incl. 7 master in 30d.
report

6. BuzzHouse (amd_tsan) — ThreadSanitizer: data race (STID 2604-385d) in RestorerFromBackup::createTable -> Context::createCopy (the BACKUP/RESTORE path). Pre-existing: 16 distinct refs incl. 4 master in 30d. Nothing to do with an Alias read.
report

Mergeable Check and PR are aggregate roll-ups; they are red only because the children above are red, not independent failures.

Recommendation: rerun the 6 failed jobs (they should pass) or treat them as flaky. None of them blocks on this PR.

@scanhex12
scanhex12 enabled auto-merge June 24, 2026 09:09
@scanhex12
scanhex12 added this pull request to the merge queue Jun 24, 2026
Merged via the queue into ClickHouse:master with commit c2ac697 Jun 24, 2026
160 of 167 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 Jun 24, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @nauu @scanhex12 — a couple of suggestions to make this PR easier for reviewers and the changelog reader.

Description (currently incomplete):

  • Why: Body is the template plus a changelog entry that describes only the CHECK proxying and references CHECK DATABASE (a no-op path), while the headline feature (parallel-replicas read enabled by the new isMergeTree override) is not explained.

  • Suggested addition:

    Explain that StorageAlias::isMergeTree now delegates to the target, which is what makes an Alias eligible for parallel-replicas reads, and clarify that the CHECK delegation covers CHECK TABLE and CHECK ALL TABLES (CHECK DATABASE is a no-op for ordinary databases).

Ignore this if the current title/body is intentional.

zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Support parallel replicas read for Alias engine
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-improvement Pull request with some product improvements 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.

5 participants