Skip to content

Fix LOGICAL_ERROR in S3Queue concurrent CREATE TABLE IF NOT EXISTS - #102610

Merged
nickitat merged 3 commits into
masterfrom
fix_streaming_storage
Apr 15, 2026
Merged

nickitat merged 3 commits into
masterfrom
fix_streaming_storage

Conversation

@nickitat

@nickitat nickitat commented Apr 13, 2026 •

Copy link
Copy Markdown
Member

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):

Fix LOGICAL_ERROR exception when multiple concurrent CREATE TABLE IF NOT EXISTS queries target the same S3Queue table on a Shared database.


The test will be submitted in private here. It also contains a detailed explanation.

Version info

  • Merged into: 26.4.1.973
  • Backported to: 26.3.10.11, 26.2.17.12, 26.1.12.6

@nickitat
nickitat requested review from kssenii and tuanpach April 13, 2026 18:25
@clickhouse-gh

clickhouse-gh Bot commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d43eada]

Summary: ❌

job_name test_name status info comment
Finish Workflow failure
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py failure

AI Review

Summary

This PR changes StreamingStorageRegistry::registerTable to throw TABLE_ALREADY_EXISTS instead of LOGICAL_ERROR when the same storage is registered twice. That aligns the error semantics with the real condition and supports CREATE TABLE IF NOT EXISTS flows in Shared databases. I did not find high-confidence correctness, safety, performance, or compatibility issues in the final diff.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 13, 2026
@kssenii kssenii self-assigned this Apr 14, 2026
Comment on lines +51 to +52
if (if_not_exists)
throw Exception(ErrorCodes::TABLE_ALREADY_EXISTS, "Table with storage id {} already registered", storage.getNameForLogs());

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.

When I've used if_not_exists - it always had behaviour "do nothing if already exists", while this change is more like "throw if exists, but not a logical error", so it is in general confusing, I'd rather change LOGICAL_ERROR to just TABLE_ALREADY_EXISTS instead of ambiguity with if_not_exists

@nickitat
nickitat added this pull request to the merge queue Apr 15, 2026
Merged via the queue into master with commit 5782fd1 Apr 15, 2026
159 of 161 checks passed
@nickitat
nickitat deleted the fix_streaming_storage branch April 15, 2026 15:57
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 15, 2026
@nickitat nickitat added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Apr 15, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Apr 15, 2026
robot-clickhouse added a commit that referenced this pull request Apr 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 75.00% (3/4) · Uncovered code

Full report · Diff report

clickhouse-gh Bot added a commit that referenced this pull request Apr 15, 2026
Backport #102610 to 26.3: Fix `LOGICAL_ERROR` in `S3Queue` concurrent `CREATE TABLE IF NOT EXISTS`
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Apr 15, 2026
@nickitat nickitat added v25.12-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels Apr 20, 2026
nickitat added a commit that referenced this pull request Apr 20, 2026
Cherry pick #102610 to 26.1: Fix `LOGICAL_ERROR` in `S3Queue` concurrent `CREATE TABLE IF NOT EXISTS`
robot-clickhouse added a commit that referenced this pull request Apr 20, 2026
nickitat added a commit that referenced this pull request Apr 20, 2026
Cherry pick #102610 to 26.2: Fix `LOGICAL_ERROR` in `S3Queue` concurrent `CREATE TABLE IF NOT EXISTS`
@nickitat nickitat removed the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Apr 20, 2026
robot-clickhouse added a commit that referenced this pull request Apr 20, 2026
clickhouse-gh Bot added a commit that referenced this pull request Apr 20, 2026
Backport #102610 to 26.1: Fix `LOGICAL_ERROR` in `S3Queue` concurrent `CREATE TABLE IF NOT EXISTS`
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Apr 20, 2026
@nickitat nickitat removed the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Apr 20, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Apr 20, 2026
clickhouse-gh Bot added a commit that referenced this pull request Apr 20, 2026
Backport #102610 to 26.2: Fix `LOGICAL_ERROR` in `S3Queue` concurrent `CREATE TABLE IF NOT EXISTS`
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Apr 20, 2026
@alexey-milovidov alexey-milovidov mentioned this pull request May 12, 2026
1 task done
groeneai added a commit to groeneai/ClickHouse that referenced this pull request May 14, 2026
Before this change, `tests/docker_scripts/stress_runner.sh` exported
`THREAD_POOL_FAULT_INJECTION=1` before `configure`, so install.sh
symlinked `tests/config/config.d/cannot_allocate_thread_injection.xml`
into the server's `config.d/` and the server started with
`cannot_allocate_thread_fault_injection_probability=0.0001` already
active. `stress.py` then ran a small smoke check (two canary tests)
to validate the setup. The smoke check did, among other things:

    CREATE DATABASE IF NOT EXISTS test_N
        ON CLUSTER test_cluster_database_replicated
        ENGINE = Replicated(...)

When thread-pool fault injection fired during the async load of the
Replicated database (`Code: 439. Cannot schedule a task: fault
injected`), the server raised the exception after it had already
started streaming the HTTP response, so
`WriteBufferFromHTTPServerResponse` deliberately broke the chunked
encoding. The client (`clickhouse-test` → `clickhouse_execute_http`)
saw `http.client.IncompleteRead`, the per-test retry was exhausted,
and the smoke check aborted the whole stress test job.

The protocol break is by design — the server uses it to signal that a
streamed response is incomplete and must not be consumed as if it were
successful. Retrying it on the client (the previous attempt) would mask
genuine server failures.

Instead, this commit applies @azat's prescription: run the smoke check
against a server that does *not* have the thread-pool fault injector
installed, then enable it only once the smoke check has passed.

- `tests/docker_scripts/stress_runner.sh` no longer exports
  `THREAD_POOL_FAULT_INJECTION=1` before `configure`. install.sh leaves
  `cannot_allocate_thread_injection.xml` uninstalled. The server starts
  with `cannot_allocate_thread_fault_injection_probability=0` (default),
  so the smoke check runs deterministically.
- `stress.py` gains `--enable-thread-pool-fault-injection`. When set,
  `run_func_test` calls a new `install_thread_pool_fault_injection()`
  helper after the smoke-check loop. The helper symlinks the canonical
  config and runs `SYSTEM RELOAD CONFIG` with retries (the reload can
  itself transiently fail under ZooKeeper fault injection and
  ThreadFuzzer). `stress_runner.sh` passes the flag; the upgrade runner
  does not. If the smoke check raises, the install path is not reached
  and the post-stress cleanup `rm -f`s any stale symlink.
- The obsolete `CANNOT_SCHEDULE_TASK` / `Fault injection` entries are
  removed from the smoke-check `ignored_errors` list. Tolerating them
  would now mask a genuine setup failure since the injector is not
  active during the smoke check.

The failure mode recurs ~weekly across unrelated master PRs (e.g.
ClickHouse#104058, ClickHouse#103490, ClickHouse#102351, ClickHouse#102610, ClickHouse#102203, and master CI on
2026-04-28). Tracked by @alexey-milovidov's directive on PR ClickHouse#96844:
ClickHouse#96844 (comment)

Failing report example (PR ClickHouse#96844, commit 9c4f6f5, MSan stress):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96844&sha=9c4f6f5a34d4bb45fcf73f20c464ba8d855a0c1f&name_0=PR&name_1=Stress%20test%20%28arm_msan%29

Validation: `tmp/test_install_thread_pool_fault_injection.py` (not
committed) covers (a) the symlink+reload mechanics, (b) fail-close when
the source config is missing, (c) flag off → no install, (d) flag on →
install runs once after smoke check, (e) install does not run when
smoke check raises an unrecoverable error, (f) the obsolete entries
are gone from `ignored_errors`. All six pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v25.12-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants