Repository navigation
Fix LOGICAL_ERROR race between creation and removal of replicated table - #99557
Conversation
|
Workflow [PR], commit [a8a212d] Summary: ✅ AI ReviewSummaryThis PR fixes a real race in ClickHouse Rules
Final Verdict
|
| # shellcheck source=../shell_config.sh | ||
| . "$CURDIR"/../shell_config.sh | ||
|
|
||
| ZK_PATH="/clickhouse/tables/${CLICKHOUSE_TEST_ZOOKEEPER_PREFIX}/race_test" |
There was a problem hiding this comment.
Style check is currently failing on this line because the Replicated*MergeTree ZooKeeper path must contain the literal $CLICKHOUSE_TEST_ZOOKEEPER_PREFIX (or {database}) pattern in the test source.
Please switch to the literal macro form, e.g. ZK_PATH="/clickhouse/tables/\$CLICKHOUSE_TEST_ZOOKEEPER_PREFIX/race_test", so the style rule can validate path isolation and CI passes.
There was a problem hiding this comment.
Style check passed actually.
| throw Exception(ErrorCodes::LOGICAL_ERROR, "There is a race condition between creation and removal of replicated table. It's a bug"); | ||
| { | ||
| /// It is possible if ZooKeeper session expired and ephemeral drop lock was deleted, | ||
| /// allowing another process to complete the removal. Return false so the caller retries. |
There was a problem hiding this comment.
At this point, the caller doesn't handle the returned value, and it doesn't retry.
There was a problem hiding this comment.
Fixed the comment.
- the caller createTableIfNotExistsAttempt() does retry to remove the entries before craate.
- the caller dropReplia() doesn't retry.
| # Simulate another process completing the ZK cleanup: delete the entire path. | ||
| ${CLICKHOUSE_KEEPER_CLIENT} -q "rmr '${ZK_PATH}'" 2>/dev/null ||: | ||
|
|
||
| # Resume. tryGetChildren returns ZNONODE; with the fix we return false instead of throwing. |
There was a problem hiding this comment.
The comment is inconsistent with the actual behavior here.
At this failpoint (ZNONODE on tryGetChildren), removeTableNodesFromZooKeeper now returns true (table path already fully removed), not false.
Please update the comment to avoid confusion for future maintenance.
|
The fix LGTM. There are still 2 remaining comments left by the bot. |
|
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 91.18% (31/34, 0 noise lines excluded) |
…on finishes the Keeper cleanup StorageKafka2::removeTableNodesFromZooKeeper is a copy of the StorageReplicatedMergeTree create/drop coordination protocol, and it kept both throw sites that PR ClickHouse#99557 removed from the original: - tryGetChildren(keeper_path) returning ZNONODE - the final tryMulti removing {drop_lock, dropped, keeper_path} returning ZNONODE Both encode the invariant "while I hold the ephemeral dropped/lock node, the table's Keeper path cannot disappear". That invariant only holds while the Keeper session is alive. When the session expires, Keeper itself deletes the ephemeral lock, another replica legitimately finishes the removal, and the resumed thread observes ZNONODE. Session expiry mid-cleanup is a normal distributed-systems outcome, which is why every occurrence in the CI database is on a Stress test check (thread fuzzer + fault injection). The second message is byte-identical to the one reported by CI, so the signature ClickHouse#99557 fixed is still reachable on master through this sibling. Both branches now log a warning instead, matching the resolution the maintainers already reviewed and merged for StorageReplicatedMergeTree: ZNONODE on the root path means the table IS completely removed, so return true; ZNONODE on the final multi means only part of the removal happened, so completely_removed stays false. Neither caller relied on the throw. Two PAUSEABLE_ONCE failpoints make both races deterministic in a regression test modelled on 04036_replicated_table_race_creation_removal.sh. Related: ClickHouse#99557
…ROP injection Two test-only hardenings; the source fix is unchanged. Pin ignore_drop_queries_probability = 0 on every DROP TABLE. The whole test mechanism is "DROP TABLE k2_race SYNC reaches StorageKafka2::removeTableNodesFromZooKeeper and pauses on the failpoint", but the stress runner appends --client-option ignore_drop_queries_probability=0.2 to every worker and clickhouse-client --fake-drop (upgrade check) sets it to 1. Because StorageKafka2 does not override storesDataOnDisk, InterpreterDropQuery::executeToTableImpl takes the branch that rewrites the query into TRUNCATE, and StorageKafka2 does not implement truncate either, so IStorage::truncate throws NOT_IMPLEMENTED and the failpoint is never reached. Two DROPs are load-bearing, so about one stress run in three would have failed by dice alone. No tag escapes this: no-stress is rejected outright and --stress-tests disables the no-<build> filter. Assert each tolerate branch's own warning from system.text_log. Previously the only committed assertion was "the DROP did not throw", which does not pin the branches individually: replacing the tryGetChildren branch with a bare fall-through lets execution reach the final tryMulti, whose ZNONODE the other new branch tolerates, so the DROP still succeeds and the scenario still passes. The predicate is scoped to this run's own kafka_keeper_path (which embeds the per-run random database) so rows from an earlier --test-runs iteration cannot satisfy it, and to level = 'Warning' because the server also records the text of this very SELECT - needle included - at Debug level. Related: ClickHouse#99557
…on finishes the Keeper cleanup StorageKafka2::removeTableNodesFromZooKeeper is a copy of the StorageReplicatedMergeTree create/drop coordination protocol, and it kept both throw sites that PR ClickHouse#99557 removed from the original: - tryGetChildren(keeper_path) returning ZNONODE - the final tryMulti removing {drop_lock, dropped, keeper_path} returning ZNONODE Both encode the invariant "while I hold the ephemeral dropped/lock node, the table's Keeper path cannot disappear". That invariant only holds while the Keeper session is alive. When the session expires, Keeper itself deletes the ephemeral lock, another replica legitimately finishes the removal, and the resumed thread observes ZNONODE. Session expiry mid-cleanup is a normal distributed-systems outcome, which is why every occurrence in the CI database is on a Stress test check (thread fuzzer + fault injection). The second message is byte-identical to the one reported by CI, so the signature ClickHouse#99557 fixed is still reachable on master through this sibling. Both branches now log a warning instead, matching the resolution the maintainers already reviewed and merged for StorageReplicatedMergeTree: ZNONODE on the root path means the table IS completely removed, so return true; ZNONODE on the final multi means only part of the removal happened, so completely_removed stays false. Neither caller relied on the throw. Two PAUSEABLE_ONCE failpoints make both races deterministic in a regression test modelled on 04036_replicated_table_race_creation_removal.sh. Related: ClickHouse#99557
…ROP injection Two test-only hardenings; the source fix is unchanged. Pin ignore_drop_queries_probability = 0 on every DROP TABLE. The whole test mechanism is "DROP TABLE k2_race SYNC reaches StorageKafka2::removeTableNodesFromZooKeeper and pauses on the failpoint", but the stress runner appends --client-option ignore_drop_queries_probability=0.2 to every worker and clickhouse-client --fake-drop (upgrade check) sets it to 1. Because StorageKafka2 does not override storesDataOnDisk, InterpreterDropQuery::executeToTableImpl takes the branch that rewrites the query into TRUNCATE, and StorageKafka2 does not implement truncate either, so IStorage::truncate throws NOT_IMPLEMENTED and the failpoint is never reached. Two DROPs are load-bearing, so about one stress run in three would have failed by dice alone. No tag escapes this: no-stress is rejected outright and --stress-tests disables the no-<build> filter. Assert each tolerate branch's own warning from system.text_log. Previously the only committed assertion was "the DROP did not throw", which does not pin the branches individually: replacing the tryGetChildren branch with a bare fall-through lets execution reach the final tryMulti, whose ZNONODE the other new branch tolerates, so the DROP still succeeds and the scenario still passes. The predicate is scoped to this run's own kafka_keeper_path (which embeds the per-run random database) so rows from an earlier --test-runs iteration cannot satisfy it, and to level = 'Warning' because the server also records the text of this very SELECT - needle included - at Debug level. Related: ClickHouse#99557
fix #99385
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
Version info
26.4.1.210