Skip to content

Speed up server shutdown for databases with many tables - #104969

Merged
serxa merged 17 commits into
ClickHouse:masterfrom
jaymebrd:parallel-table-shutdown
Aug 27, 2026
Merged

serxa merged 17 commits into
ClickHouse:masterfrom
jaymebrd:parallel-table-shutdown

Conversation

@jaymebrd

@jaymebrd jaymebrd commented May 14, 2026 •

Copy link
Copy Markdown
Member

Table shutdown runs sequentially per table, which can make server shutdown take many minutes to 1hr+ on clusters with many thousands of tables.

This PR parallelises the table shutdown drain inDatabaseWithOwnTablesBase::shutdown:

  • src/Databases/DatabasesCommon.cpp: the prepare phase flushAndPrepareForShutdown stays sequential and the expensive, table-independent shutdown() drain (ZooKeeper sessions, interserver endpoints, background pools) runs concurrently via a dedicated thread pool.

The speedup is best measured by SIGTERM-to-exit wall time on many-table clusters.

Changelog category (leave one):

  • Performance Improvement

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

Speed up server shutdown for databases with many tables by shutting tables down in parallel. Controlled by the new database_catalog_shutdown_table_concurrency setting (0 by default, meaning the number of CPU cores).


Workflow [PR]
Sync PR [sync-upstream/pr/104969]

Version info

  • Merged into: 26.9.1.221 (included in 26.9 and later)

@clickhouse-gh

clickhouse-gh Bot commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [185d8ce]

Summary: ❌

job_name test_name status info comment
Docs examples FAIL
Documentation examples FAIL cidb IGNORED

AI Review

Summary

This PR parallelizes the expensive per-table shutdown() phase in DatabaseWithOwnTablesBase::shutdown() while keeping flushAndPrepareForShutdown() sequential, and it adds an integration test that proves the happy-path drain runs concurrently. The main shutdown-ordering regressions from earlier revisions are addressed, but one failure-path hole remains: if the parallel runner setup throws before any task is scheduled, the database still exits shutdown without clearing its table references or UUID mappings.

Findings
  • ❌ Blocker: [src/Databases/DatabasesCommon.cpp:670-675] The new parallel setup (initializeWithDefaultSettingsIfNotInitialized(), shared_pool.get(), and runner.reserve()) runs before any recovery path exists. A bad_alloc, length_error, or thread-pool initialization failure here aborts DatabaseWithOwnTablesBase::shutdown() before any removeUUIDMapping or tables.clear() cleanup runs. DatabaseCatalog::shutdownImpl() only logs that database-level exception and keeps going, so debug/ASan builds can still hit the final uuid_map assertion, while release builds keep those storages alive until process teardown. This PR also makes the destructor retry path depend on the same static pool, so after StaticThreadPool::shutdownAll() there is no serial fallback left. Suggested fix: wrap the whole parallel-runner setup in a recovery path and fall back to the old serial cleanup loop (or inline run_task() execution) whenever the shutdown pool cannot be initialized, acquired, or reserved.
Tests
  • ⚠️ Add a focused failure-path test that forces shutdown-pool setup to fail before task scheduling and proves DatabaseCatalog::shutdownImpl() still empties the UUID map and clears the database tables. The current integration coverage exercises only the happy-path parallel drain.
Final Verdict

Changes requested.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.30% 87.30% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.40% 79.30% -0.10%

Changed lines: Changed C/C++ lines covered: 110/115 (95.65%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label May 14, 2026
Comment thread src/Databases/DatabasesCommon.cpp Resolved
Comment thread src/Core/ServerSettings.cpp Resolved

@serxa serxa left a comment

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.

Overall looks good to me.

Comment thread src/Databases/DatabasesCommon.cpp Resolved
@jaymebrd
jaymebrd requested a review from serxa May 24, 2026 10:22
@serxa
serxa enabled auto-merge June 2, 2026 11:09
@serxa

serxa commented Jun 4, 2026

Copy link
Copy Markdown
Member

@groeneai can you check what prevents merging and help?

Comment thread src/Core/ServerSettings.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

This sync PR parallelizes per-table shutdown during server stop (a new ShutdownTables thread pool and database_catalog_shutdown_table_concurrency setting) and touches only the shutdown path — no query-execution code. The two flagged ClickBench queries (Q4 -17.9%, Q15 -20.5%) both land inside master's current variance band with essentially unchanged CPU time, so they were correctly kept as no-change; the apparent speedups are run-to-run noise, not an effect of this change. The deterministic envelope suppression is consistent with the diff and requires no correction.

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 7bb9d2a3-416f-4bde-8cf1-7b29bef8e9cc
  • MIRAI run: b582337c-9d21-4ea3-889f-c6870c297d52
  • PR check IDs:
    • clickbench_531127_1784034988
    • clickbench_531140_1784034988
    • clickbench_531146_1784034988
    • tpch_adapted_1_official_531149_1784034988
    • tpch_adapted_1_official_531158_1784034988
    • tpch_adapted_1_official_531165_1784034988

@groeneai

Copy link
Copy Markdown
Collaborator

@serxa diagnosis for #104969 (head 3d4725f0): the only thing blocking merge is the CH Inc sync check (tests failed). It is the sole failure in the combined commit status, which is why mergeStateStatus = BLOCKED. It carries no public target_url, so external contributors cannot see its logs. Could you check it on the CH Inc side to tell whether it is a real internal-test failure or a transient sync-infra flake that just needs a re-run?

Everything else is green:

  • mergeable: MERGEABLE, no conflicts (master merged in on 06-09).
  • 152/152 public checks pass; Mergeable Check, PR, and Style check statuses are all green.
  • All 4 review threads resolved. The two real bot findings are fixed: the max_threads=0 hang (now clamped via std::max<UInt64>(1, ...) in Server + LocalServer) and the over-strict non-UUID chassert in DatabaseWithOwnTablesBase::shutdown (removed). The latest NonZeroUInt64-vs-document-0 nit you already dismissed as acceptable safety margins.
  • Your 2026-06-01 approval stands.

Nothing on the author's side looks blocking. Happy to dig further once the sync logs are visible.

pull Bot pushed a commit to peijunlin2008/ClickHouse that referenced this pull request Jun 11, 2026
`AddDefaultDatabaseVisitor::visit(ASTSelectQuery &, ASTPtr &)` guards its
WITH-traversal on `select.recursive_with` but then dereferences
`select.with()->children` unconditionally. The parser sets the flag together with
a non-empty WITH expression, but AST mutation after parsing (server-side
`BuzzHouse` fuzzing, in particular) can leave the flag set while the expression
is absent, producing a null pointer dereference inside `IStorageCluster::read`.
Surfaced by `BuzzHouse (amd_tsan)` as `STID: 3440-3393` on PRs ClickHouse#104969 and
ClickHouse#105332 (two unrelated PRs in five days).

Guard the dereference with the actual presence of the WITH expression, matching
the pattern already used in `ASTSelectQuery::formatImpl` and
`QueryTreeBuilder::buildSelectQuery`. Valid `WITH RECURSIVE x AS ...` queries
are unaffected.

Adds a `gtest` that constructs the inconsistent AST shape, runs the visitor, and
asserts no fatal failure; the test reliably aborts on the previous code with the
`boost::intrusive_ptr` null-deref assertion.

Closes ClickHouse#105370

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105332&sha=ac51d1463d5def7f7ba0354f581e078cbf10d6c6&name_0=PR&name_1=BuzzHouse%20%28amd_tsan%29

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator

Hi @serxa, gentle ping. PR #104969 is green on public CI and all review threads are resolved; the only thing still blocking merge is the internal CH Inc sync -> Check public build check (status tests failed, no public target_url), which only CH Inc can inspect or re-run. Could you check whether that is a real internal failure or a transient sync-infra flake? Thanks.

@serxa
serxa disabled auto-merge June 16, 2026 13:59
@serxa

serxa commented Jun 16, 2026

Copy link
Copy Markdown
Member

@groeneai Let's merge master into this branch to take new fixes into account and into sync PR

@groeneai

Copy link
Copy Markdown
Collaborator

@serxa branch is ~3.9k commits behind master but mergeable is MERGEABLE, so merging master in is conflict-free. I can't push it myself: @groeneai is an external contributor with no write access to ClickHouse/ClickHouse, and "Allow edits from maintainers" grants fork-branch push to CH Inc maintainers (you), not to external contributors.

@jaymebrd could you merge master into parallel-table-shutdown? It's conflict-free, so the PR "Update branch" button works. That refreshes the internal sync PR (currently pending) with current master. A CH Inc maintainer can also do it via the same button (maintainerCanModify is true).

@serxa

serxa commented Jun 18, 2026

Copy link
Copy Markdown
Member

@groeneai check recent CI failures? do we have fixes for them? are they merged in master?

@groeneai

Copy link
Copy Markdown
Collaborator

@serxa Triaged the 5 public failures at head 39a0842. None are caused by this PR; all are pre-existing trunk flakiness unrelated to the shutdown-parallelism change. No fix is merged in master for either, because neither needs one on the author side.

1. Integration tests (4 shards: asan_ubsan / msan / tsan / arm_binary) - test_format_cannot_allocate_thread::test_it
All four fail identically inside cluster.shutdown(), not in the test body. It is a pre-existing data race on the global getActivePartsLoadingThreadPool() singleton (src/IO/SharedThreadPools.cpp): main-thread teardown (StaticThreadPool::shutdown via the Server::main scope guard, line 82) races a SystemLog flush thread that lazily creates a system table on the way down (SystemLog<...>::prepareTable -> StorageMergeTree ctor -> loadDataParts -> StaticThreadPool::get(), line 100). This has nothing to do with DatabaseWithOwnTablesBase::shutdown from this PR. CIDB confirms: 0 master failures in 30 days; it only surfaces in unrelated PRs (streaming-pool, profile-events, signal-handler work) where the deliberate cannot_allocate_thread failpoint perturbs teardown timing. Caused by this PR: no. Fix exists/merged: no. Re-running the jobs clears it.

2. BuzzHouse (amd_debug) - Inconsistent AST formatting LOGICAL_ERROR (STID 1941-1bfa)
A fuzzer-generated query using caseWithExpression; a generic parser/formatter roundtrip bug (the formatted SQL re-parses to a different AST, tripping the debug-only consistency check in executeQueryImpl). Unrelated to shutdown. The Inconsistent AST formatting class hits master roughly 1-3 times/day every day; this specific variant is fuzzer-only and does not reproduce deterministically. Caused by this PR: no. Fix merged: no.

3. CH Inc sync - internal check, no public target_url; only CH Inc can inspect or re-run (unchanged from prior runs).

Recommendation: nothing on the author side blocks merge. The shutdown code is not implicated by any of the five. Re-running BuzzHouse + the Integration shards should clear them; the only real gate remains the internal sync.

Public CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104969&sha=39a0842660da13a14f507feaa9d2f9f6a3edaf24&name_0=PR

@serxa

serxa commented Jun 23, 2026

Copy link
Copy Markdown
Member

@groeneai Failed test test_format_cannot_allocate_thread/test.py::test_it looks suspicious. Is it related to the changes in this PR?

@groeneai

Copy link
Copy Markdown
Collaborator

@serxa Yes, it looks related to this PR. I need to correct my 06-18 triage: I lumped it in with a pre-existing teardown race, but the hard signature on the current runs is specific to this branch.

Evidence:

  • The crash is LOGICAL_ERROR: The MergeTreePartsLoaderThreadPool is not initialized on the non-TSan shards (asan/msan/coverage/arm_binary), plus a TSan data race on the same pool. CIDB: 11 hits in 90 days, all on this branch (parallel-table-shutdown), 0 on master and 0 on any other PR. The test is green on master (1532 OK / 0 FAIL in 30d). It first appears at head 39a0842 (the 06-18 master merge), not on the earlier 06-10 head.
  • It fails in cluster.shutdown() (module teardown), not in the test body, so it is the server shutdown that aborts. test_format_cannot_allocate_thread is just the canary that happens to restart the node.
  • Stack (identical on the hard-error shards and the TSan shard):
    StaticThreadPool::get() SharedThreadPools.cpp:100 <- MergeTreeData::loadDataParts MergeTreeData.cpp:2413 <- StorageMergeTree::StorageMergeTree StorageMergeTree.cpp:206 <- make_shared<StorageMergeTree> (registerStorageMergeTree.cpp:1079) <- a SystemLog flush thread lazily creating system.background_schedule_pool_log during shutdown.

Mechanism: a SystemLog flush thread lazily CREATES its backing MergeTree table during shutdown; the StorageMergeTree ctor calls loadDataParts -> getActivePartsLoadingThreadPool().get(). This PR moves DatabaseWithOwnTablesBase::shutdown onto a worker pool, which changes the timing and concurrency of the shutdown sequence so that this lazy table creation now overlaps with the global ActivePartsLoading static pool being torn down (StaticThreadPool::shutdownAll() in the Server::main SCOPE_EXIT). On non-TSan builds the pool is already reset -> hard not initialized; on TSan the read of the pool instance races with its reset. The serial shutdown on master does not hit this window.

So it is a latent shutdown-ordering fragility (system logs can lazily create their tables during shutdown and reach a torn-down static pool), and this PR's parallel shutdown is the first thing to surface it.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104969&sha=9d7ff6e40da97cd60ee5769c279c2850e40d5991&name_0=PR

Possible directions: skip lazy system-log table creation when the catalog is shutting down (just drop the unflushed entries, since the table was never materialized), or make sure the new parallel-shutdown work is fully joined before system logs flush so loadDataParts never runs against a pool that is being reset. I can dig into the exact ordering and prepare a fix in a separate PR off master if you want it. Since this is jaymebrd's branch I will not push to it.

Comment thread programs/server/Server.cpp Resolved
Comment thread src/Databases/DatabasesCommon.cpp Resolved
@jaymebrd

Copy link
Copy Markdown
Member Author

@groeneai Failed test test_format_cannot_allocate_thread/test.py::test_it looks suspicious. Is it related to the changes in this PR?

It looks like this PR introduced the race #107291 and our parallel shutdown exposes it

@serxa

serxa commented Jun 24, 2026

Copy link
Copy Markdown
Member

@groeneai Shutting down multiple interdependent pools is tricky. In easy cases, it could be resolved just by the proper ordering. Try to prepare the fix in a separate PR before we can merge this PR. The goal is to add necessary dependencies between startup and shutdown procedures, such that issue you found here is resolved. I hope you will not face circular dependencies; be careful with that (if nothing can prevent them, report back here)

@groeneai

Copy link
Copy Markdown
Collaborator

@serxa Will do. Preparing the fix in a separate PR off master.

Plan: make SystemLogs teardown happen-before the static ActivePartsLoading pool teardown on all paths. Concretely, in DatabaseCatalog::shutdownImpl the shutdown_system_logs() call (which joins the system-log flush threads) is currently skipped if a user database shutdown() throws, so a flush thread can still lazily create its MergeTree backing table after StaticThreadPool::shutdownAll() reset the pool, giving the MergeTreePartsLoaderThreadPool is not initialized abort. Ordering the dependency (always tear down system logs before the global/static pools, even on a throwing path) closes that window.

No circular dependency expected: system logs depend on the static pools and on the system database (shut down last), not the other way around. Will report back here if a cycle shows up. This is a pre-existing latent issue on master that this PR's parallel shutdown exposes, so the fix belongs in its own master PR; I will link it here once it is up.

jaymebrd and others added 6 commits July 20, 2026 16:28
Capture shared error state as shared_ptr<ErrorRecorder> and the logger
by value, dropping `this` and by-ref captures. An orphan task — rare
case where the pool accepts the job but tasks.emplace_back throws —
can outlive shutdown() and would otherwise dangle into the stack frame.

Also read recorder->first_error under the recorder's mutex in the tail,
since an orphan task can still write to it after waitForAllToFinish.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
enqueueAndKeepTrack schedules the task, then tracks it with
tasks.emplace_back. If that emplace_back reallocated and threw after the
task was already scheduled, the catch ran the task inline a second time
while the scheduled copy stayed untracked (and unwaited). Reserve the
tracking vector up front so emplace_back never reallocates; then a throw
from enqueueAndKeepTrack always means the task was never scheduled.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Parallelizing flushAndPrepareForShutdown was unsafe: some tables flush
into other tables there (a Buffer table writes to its destination), and
running that concurrently could hit a destination already in
shutdown-prepared read-only mode and silently drop rows.

Keep the prepare phase sequential (unchanged from master), and
parallelize only the raw shutdown() phase — the expensive,
table-independent drain (ZooKeeper sessions, interserver endpoints,
background pools) that was the actual bottleneck for databases with many
tables. Since prepare already ran, call shutdown() directly instead of
flushAndShutdown() to avoid re-running the flush.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…er-side in test

- database_catalog_shutdown_table_concurrency = 0 now means "number of CPU
  cores" (matching max_database_replicated_create_table_thread_pool_size)
  instead of being clamped to 1; documented in the setting description.
- The integration test asserts on the server-reported "Shut down N tables
  in <db> in M ms" duration instead of wall-clock time, so sanitizer
  overhead on the orchestration side does not make it flaky.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ores)

Per review: default the shutdown pool size to 0, which means "number of
CPU cores", instead of a fixed 16.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@jaymebrd
jaymebrd force-pushed the parallel-table-shutdown branch from 8fcdb66 to 18f21b4 Compare July 20, 2026 15:30
Comment thread src/Databases/DatabasesCommon.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 78.30% 78.20% -0.10%

Changed lines: Changed C/C++ lines covered: 109/114 (95.61%) · Uncovered code

Full report · Diff report

@serxa

serxa commented Jul 26, 2026

Copy link
Copy Markdown
Member

@groeneai, investigate the failure: https://github.com/ClickHouse/ClickHouse/actions/runs/29755463902/job/88491825359 and provide a fix in a separate PR. If the fix is already in progress, link it here.

Note: job logs are no longer accessible via the GitHub API (artifact expired). Cloud benchmark report shows no regression (37 queries, no change). If this is a pre-existing or infrastructure flakiness in the performance comparison, please confirm.

@groeneai

Copy link
Copy Markdown
Collaborator

Confirmed: infrastructure, not a performance regression, and the fix is already merged.

What failed. The GH Actions log is expired, but the check-run annotation survives (gh api repos/ClickHouse/ClickHouse/check-runs/88491825359/annotations) and it is unambiguous:

System.IO.IOException: No space left on device :
  '/home/ubuntu/actions-runner/_diag/Worker_20260720-223401-utc.log'

The runner ran out of disk. The job died before uploading anything, which is why the shard reports no rows to CIDB and there is no failing query to look at. All 3 attempts (jobs 88449175162, 88476564379, 88491825359) failed the same way on 3 different runners (i-06fe86cfd8a0d58e4, i-0c6e3990ef5bd7176, i-035463a63bf003ac4), so it was not one bad host.

Not a regression: at 18f21b4 the other 11 perf shards were all green with zero FAIL/ERROR rows, matching the 37-query no-change Cloud result you already have.

Not specific to this PR. Since a disk-death shard reports nothing, I counted incomplete shard sets instead (uniqExact(check_name) < 6 per commit) on Performance Comparison (amd_release, master_head, N/6):

date sets incomplete
07-18 51 1
07-19 42 0
07-20 49 26
07-21 47 44
07-22 55 34
07-23 62 1
07-24 55 0
07-25 32 0

A 3-day fleet-wide window, amd and arm together. I spot-checked other PRs in it (jobs 89032972175, 89041380548, 88991625264) and they carry the byte-identical ENOSPC annotation.

Cause and fix. The window opens with #110009 (merged 07-20T13:16Z), which added populate_data/rebuild_table: the hits datasets are re-inserted into fresh tables and OPTIMIZE FINAL-ed on both the left and right servers, roughly doubling live dataset bytes on top of the ~33.6 GiB of tarballs (hits_100m_single alone is 26.5 GiB). It closes with #111377 (rienath, merged 07-22T15:05Z), which adds cleanup_user_files() after each test and shrinks the two heaviest fixtures (min_max_index 15.2 -> 3.0 GB, join_convert_to_fixed_hash_table 27.4 -> 6.1 GB). Both are on master now (performance_tests.py:1516).

So there is nothing for me to fix in a separate PR: #111377 is the fix, and the rate has been 0-2% since it merged. A rerun of shard 4/6 on a rebased head should be green.

One note while I am here: the other red on this PR, Stress test (amd_asan_ubsan), is also unrelated to the change. It is the t_plt_rb_contains startup-parse failure tracked in #111053. Empirically that signature stopped on master right after #111055, #111661 and #111730 merged (07-23/07-24) - Stress-check hits went 26 on 07-22, 18 on 07-23, 1 on 07-24, 0 since - and all three landed after this head was built, so a rebase should clear it.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Dear @serxa, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@clickhouse-gh clickhouse-gh Bot assigned evillique and unassigned serxa Aug 26, 2026
@serxa serxa self-assigned this Aug 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 185d8ce14 with master 90edfe017 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 711.21 MiB 708.18 MiB -3.03 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

73 object files changed (+118.55 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Databases/DatabasesCommon.cpp.o 327.92 KiB 441.98 KiB +114.06 KiB (+34.78%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

511 translation units recompiled, 4142 s compile time in total, 511 of them have a recent master baseline.

Job report

@serxa
serxa enabled auto-merge August 27, 2026 18:37
@serxa
serxa added this pull request to the merge queue Aug 27, 2026
Merged via the queue into ClickHouse:master with commit a5c2615 Aug 27, 2026
178 of 180 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 28, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@jaymebrd @serxa @evillique — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

otselnik pushed a commit to otselnik/ClickHouse that referenced this pull request Sep 10, 2026
PR ClickHouse#104969 parallelized the table shutdown drain and split the drain's
flushAndShutdown() into a sequential prepare pass (flushAndPrepareForShutdown)
followed by a parallel plain shutdown(). That dropped the second flush that
flushAndShutdown() used to perform.

For a same-database Buffer -> Buffer chain, tables are prepared in table-name
order. When the destination buffer sorts before the source, it is prepared
(and flushed while empty) before the source flushes its rows into the
destination's in-memory buffer. StorageBuffer has no shutdown() override and no
destructor flush, so the parallel drain then destroys those rows silently, with
no error in the log.

Run the prepare pass twice, restoring the pre-ClickHouse#104969 re-flush while keeping the
expensive shutdown drain parallel. Depth-2 chains are rescued regardless of name
order; deeper adversarial chains were already broken before ClickHouse#104969.

Closes ClickHouse#116803.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance 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.

6 participants