252 Commits
Author SHA1 Message Date
Chester 8dea219836 Merge branch 'master' into fix-80759-protocol-metrics 2026-10-01 11:17:10 +08:00
Antonio Andelic 456be6b485 Keeper: shut down dispatcher before forced exit
Complete both Keeper dispatcher shutdown phases when non-TCP handlers exceed the drain deadline, then call `safeExit`. Pass `false` to the post-connection phase because timed-out handlers may still exist.

Related: https://github.com/ClickHouse/ClickHouse/pull/118014

Related: https://github.com/ClickHouse/ClickHouse/pull/118014#discussion_r3969271789
2026-09-09 14:09:10 +00:00
Antonio Andelic 3d75f62462 Keeper: split TCP drain from dispatcher shutdown
Keep Keeper and RAFT available while non-TCP protocol handlers drain, but stop Keeper TCP handlers and preserve their sessions for the dispatcher close sweep.

Fix the shutdown integration test to avoid an `Expect: 100-continue` ordering timeout and verify the drained session without assuming the total session count.

Related: https://github.com/ClickHouse/ClickHouse/pull/118014

Related: https://github.com/ClickHouse/ClickHouse/pull/118014#pullrequestreview-5152941426

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118014&sha=f1be5cc212c435a2da482f7127e96f353deecb4b&name_0=PR
2026-09-09 11:23:44 +00:00
Antonio Andelic f1be5cc212 Keeper: drain HTTP handlers before dispatcher shutdown
Separate Keeper HTTP-control connections from Keeper TCP connections during shutdown. Drain HTTP handlers while Keeper state remains live, then stop the dispatcher to release TCP session-ID waiters and finish queue accounting after TCP handlers exit.

Review: https://github.com/ClickHouse/ClickHouse/pull/118014#discussion_r3966433308
PR: https://github.com/ClickHouse/ClickHouse/pull/118014
2026-09-09 09:49:11 +00:00
Antonio Andelic 772d8a3e97 Finalize Keeper shutdown after handlers exit
Stop Raft and complete pending session-ID requests before waiting for Keeper TCP handlers. Drain and check the request dispatcher queues only after the handlers exit, when all response deallocation callbacks have completed.
2026-09-07 13:05:47 +00:00
Antonio Andelic 12435ea416 Keep Keeper available during storage shutdown
Shut down storages before closing embedded Keeper connections so replicated storages can still use Keeper during cleanup. Then close the sockets and stop the dispatcher before waiting for TCP handlers, which wakes idle connections without waiting for their session timeout.\n\nComplete pending session-ID requests only after the Raft commit thread has stopped to avoid racing with a late committed session.
2026-09-07 07:44:55 +00:00
Antonio Andelic e97a5427e7 Keeper: close active connections during shutdown
Idle Keeper sessions can keep their handlers blocked in a socket poll until the negotiated session timeout expires. Shut down registered connection sockets after stopping the listeners so blocked reads and polls return immediately.

Add an integration test that keeps a negotiated session idle while the server terminates.
2026-09-04 07:01:52 +00:00
James Sanders 89a37d404b Reload TLS CA certificates (caConfig) without restart
CertificateReloader already hot-reloads the certificate and private key, but
the trusted CA certificates were loaded once by Poco at startup and never
refreshed, so rotating a CA required restarting every server and Keeper.

Keep a MultiVersion snapshot of an X509_STORE per prefix, rebuilt whenever the
caConfig path, its modification time or loadDefaultCAFile changes, and verify
peer certificates against the current snapshot from an
SSL_CTX_set_cert_verify_callback installed once per context (default server
and client contexts, per-protocol contexts and the NuRaft contexts). The
SSL_CTX itself is never modified after initialization, same as for the
existing certificate callback.

The caConfig paths (and the client certificate and key) are now also watched
by ConfigReloader in clickhouse-server and clickhouse-keeper, so replacing the
file on disk is enough to trigger the reload.
2026-08-31 18:25:52 +00:00
Alexey MilovidovandClaude Fable 5 569563b697 Merge branch 'master' into fix-80759-protocol-metrics
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-30 22:41:04 +00:00
Groene AI 8ab15993a0 Report a handler configuration error on the Keeper control endpoints too
The two `keeper_server.http_control` listeners built their handler factory inside the
`createServer` callback, so an invalid `<handlers>` section came out of the listen error
handler rather than as itself. Measured on the unfixed binary: without `listen_try` it was
`Code: 210 ... Listen [127.0.0.1]:50744 failed: ... (NETWORK_ERROR)`, and with `listen_try`
it was reduced to advice about `<listen_host>` while keeper kept running without the
control endpoint.

`createKeeperHTTPHandlerFactory` reads `keeper_server.http_control.handlers` and throws
`INVALID_CONFIG_PARAMETER` / `UNKNOWN_ELEMENT_IN_CONFIG` from it, and that parse cannot
fail for any socket reason, so it is hoisted above `createServer` behind a port guard
matching `createServer`'s own early return, the same shape already used for the HTTP,
HTTPS and Prometheus listeners here and in `clickhouse-server`.

This is the last listener in the family, reported by review on the Prometheus hoist. The
regression test grew control cases for both exits of the error handler, the port guard and
a valid section; the two error cases redden against the pre-hoist binary while the
Prometheus cases stay green, so they discriminate this half. The test is renamed since it
now covers both listeners.
2026-08-20 12:39:02 +00:00
Groene AI 85c778d1c8 Report a handler configuration error in clickhouse-keeper too
The standalone Prometheus listener of clickhouse-keeper built its handler factory inside the
createServer callback, like the server did, so an invalid <prometheus.handlers> section came
out as

  Code: 210. DB::Exception: Listen [127.0.0.1]:9363 failed: Code: 137. DB::Exception:
  Unknown type no_such_prometheus_type ... (NETWORK_ERROR)

and with listen_try it was reduced to advice about <listen_host> while keeper carried on with
no metrics endpoint. It is the same shared parse, createPrometheusHandlerFactoryImpl, that
the server reaches, so the same hoist above createServer fixes it, behind a port guard
matching that function's own early return. Keeper HTTP-control is still not changed.

Measured on both binaries: before, wrapped into NETWORK_ERROR and swallowed under listen_try;
after, a bare UNKNOWN_ELEMENT_IN_CONFIG in both, and startup stops rather than running
without the endpoint. A valid section still serves metrics, keeper without <prometheus> and
with <prometheus> but no <port> both stay healthy, and rebuilding with the guard forced on
refuses that last configuration, so the guard is load-bearing.

The regression test drives the keeper entrypoint directly, following
04498_keeper_psi_metrics_setting. Ports are randomized and retried on collision because
nothing in the environment is unique per concurrent copy, and a collision before the
Prometheus listener is reported rather than asserted through, so it cannot pass for the
wrong reason.
2026-08-20 09:43:27 +00:00
Alexey Milovidov 481689ad3e Remove the default /etc/metrika.xml substitution file
The `include_from` server setting used to fall back to `/etc/metrika.xml`
whenever that file existed. This is surprising: a file outside the ClickHouse
configuration directory, with unrelated access rights and a name that has
nothing to do with ClickHouse, could silently supply configuration
substitutions. Most users do not know the file is consulted at all.

Now `include_from` is empty by default and substitutions are only read from
the path it explicitly names. The fallback is removed from the server config
processor, from the users' configuration (access storages), from Keeper, and
from disks created by SQL.

Closes: https://github.com/ClickHouse/ClickHouse/issues/102836
2026-08-10 12:52:31 +00:00
superdiaodiao 8396c4191f Report protocol metrics for servers declared under <protocols>
AsynchronousMetrics derived TCPThreads, HTTPThreads and friends from a fixed
map keyed on the listener's port_name, which is a config key. A listener
declared under <protocols> has port_name == "protocols.<name>.port", so it
matched nothing and reported no metrics at all.

ProtocolServerAdapter now carries a ServerType::Type and AsynchronousMetrics
matches on that instead. For a <protocols> listener the type is the innermost
layer of its stack, since tls and proxy1 only wrap another protocol.

This also gives metrics to tcp_with_proxy_port, tcp_ssh_port and
arrowflight_port, which were never in the map either, and sums the values of
listeners that share a protocol instead of letting the last one win.

Change-Id: I895895b64814c3638f06c664accb6e4be6de984c
Closes: https://github.com/ClickHouse/ClickHouse/issues/80759
2026-08-02 12:08:23 +08:00
Alexey Milovidov 06c2d2e631 Merge remote-tracking branch 'origin/master' into memory-worker-rss-speculative-reserve
Branch was 1157 commits behind master and the only CI red was the chronic
master-wide `Hung check failed, possible deadlock found` flake (13-70/day on
master itself; this PR is a compile-time no-op under `SANITIZER` so it cannot
affect the `arm_asan_ubsan` stress run). Re-merge to refresh CI on the current
master and to re-run the AI review against the already-updated PR description.

The merge conflicted only in `src/Common/MemoryWorker.cpp`: master evolved the
`memory_worker_dynamic_hard_limit` apply block to skip adjustments smaller than
`min_change_ratio` (1%) of the current limit, still naming the local
`current_hard_limit`. The branch had renamed that local to `installed_hard_limit`
to avoid shadowing the `current_hard_limit` the speculative-reserve block reads
earlier in `updateResidentMemoryThread` (`-Wshadow`/`-Werror`). Kept master's new
threshold logic verbatim and renamed its local to `installed_hard_limit`; the
`LOG_TRACE` already references `installed_hard_limit`. No behavior change.

Verified the resolved `MemoryWorker.cpp` compiles cleanly (`-fsyntax-only`,
`-Werror -Wall -Wextra`) against the merged tree.
2026-06-19 15:40:51 +00:00
Miсhael Stetsyuk eae0a521c6 Merge pull request #107291 from ClickHouse/static-thread-pool-shutdownall
Fix stuck shutdown in server and local and join all global pool threads in all binaries
2026-06-17 13:44:41 +00:00
linjiayu 6de0190ce9 Fix keeper_server.http_control.secure_port serves plaintext HTTP instead of HTTPS 2026-06-16 13:50:33 +08:00
Michael Stetsyuk b219eaf99e Join threads from global thread pool before exiting from main 2026-06-11 21:45:31 +00:00
Alexey MilovidovandClaude Opus 4.8 756cb4b634 Address review: cap speculative RSS reservation before addition; drop dead Keeper wiring
Cap the speculative reservation at `current_hard_limit - resident` *before*
adding it to `resident`, and skip speculation entirely once
`resident >= current_hard_limit`. This removes any chance of the signed
`Int64` addition overflowing (the previous code added a hard-limit-sized
`reserve` to `resident` and only capped afterwards), as flagged in review,
while preserving full early-throw power: once the published RSS reaches the
hard limit, the next positive allocation already trips the
`will_be_rss > current_hard_limit` branch in `MemoryTracker::allocImpl`.

Stop wiring `memory_worker_rss_speculative_reserve_ratio` into
`clickhouse-keeper`: it never sets the global hard limit (it enforces
`keeper_server.max_memory_usage_soft_limit` separately), so the speculation
gate `current_hard_limit > 0` makes the setting a no-op there. Leaving it
disabled (`ratio = 0`) avoids exposing a setting that cannot take effect.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 11:04:45 +00:00
Alexey Milovidov eabaac30ac Merge remote-tracking branch 'origin/master' into memory-worker-rss-speculative-reserve 2026-06-02 21:41:44 +00:00
Alexey Milovidov ff8b4f248c Merge pull request #100976 from ClickHouse/fix-compiler-warnings
More warnings
2026-05-31 16:52:22 -07:00
Alexey Milovidov c5f6743535 Merge remote-tracking branch 'origin/master' into memory-worker-rss-speculative-reserve 2026-05-30 04:07:26 +00:00
János Benjamin Antal a91de4a336 Merge branch 'master' into convert-asserts-to-chasserts 2026-05-28 10:25:28 +02:00
Alexey Milovidov c1e6c562d5 Merge remote-tracking branch 'origin/master' into memory-worker-rss-speculative-reserve 2026-05-23 23:51:18 +00:00
Alexey Milovidov d6a1fe8f98 Merge remote-tracking branch 'origin/master' into fix-compiler-warnings
# Conflicts:
#	src/Functions/seriesPeriodDetectFFT.cpp
#	src/Functions/stl.hpp
#	src/Functions/tests/gtest_string_similarity.cpp
2026-05-23 07:21:41 +00:00
János Benjamin Antal 5b8d01b95c Merge remote-tracking branch 'origin/master' into convert-asserts-to-chasserts 2026-05-21 12:05:22 +00:00
Alexey Milovidov 81e77b648f Merge remote-tracking branch 'origin/master' into fix-compiler-warnings
# Conflicts:
#	programs/local/fuzzers/clickhouse_fuzzer.cpp
2026-05-21 10:55:59 +00:00
Michael Kolupaev 62b6f1bb31 Merge remote-tracking branch 'origin/master' into fwd 2026-05-20 12:16:13 -07:00
Alexey Milovidov 539ec53406 Merge remote-tracking branch 'origin/master' into memory-worker-rss-speculative-reserve 2026-05-20 16:01:55 +00:00
Jimmy Aguilar Mena b9e7652d85 Merge pull request #104940 from nauu/fix-keeper
Fix max_memory_usage_soft_limit hot reload
2026-05-20 14:59:04 +00:00
János Benjamin Antal 3300c78b1d Even more finds 2026-05-20 10:04:07 +00:00
nauu 6aba3b670c fix max_memory_usage_soft_limit hot reload 2026-05-19 23:26:04 +08:00
Alexey MilovidovandClaude Opus 4.7 88104b93b1 Wire memory_worker_rss_speculative_reserve_ratio into Keeper
`programs/server/Server.cpp` and `programs/local/LocalServer.cpp` were
passing the new server setting `memory_worker_rss_speculative_reserve_ratio`
into `MemoryWorkerConfig`, but `programs/keeper/Keeper.cpp` was building
its `MemoryWorkerConfig` without it, so the configured value was silently
ignored by `clickhouse-keeper`. Add the missing `ServerSetting`
declaration and the corresponding field initialiser. Spotted by AI review
on https://github.com/ClickHouse/ClickHouse/pull/104976.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 00:21:35 +00:00
Michael Kolupaev 446c193967 Merge remote-tracking branch 'origin/master' into fwd 2026-05-14 12:45:22 -07:00
Alexey Milovidov ac598f3a7e Merge remote-tracking branch 'origin/master' into fix-compiler-warnings
# Conflicts:
#	programs/main.cpp
2026-05-06 03:18:15 +00:00
Alexey Milovidov 19af6905c2 Merge remote-tracking branch 'origin/master' into fix-compiler-warnings
# Conflicts:
#	src/AggregateFunctions/AggregateFunctionTheilsU.cpp
#	src/Interpreters/ProcessList.cpp
#	src/Interpreters/ThreadStatusExt.cpp
2026-04-24 14:12:17 +00:00
Alexey Milovidov 7207971d60 Merge remote-tracking branch 'origin/master' into revert-98038-revert-96025-clickhouse-help 2026-04-24 01:49:47 +00:00
Sema ChecherindaandClaude Opus 4.6 6e4e8ddfef Reduce default HTTP header limits to prevent pre-auth memory exhaustion
The defaults for `http_max_fields` (1,000,000) and
`http_max_field_name_size` (128 KB) allowed unauthenticated HTTP
clients to trigger large memory allocations before any authentication
check, since HTTP headers are fully parsed before authentication occurs.

This reduces:
- `http_max_fields`: 1,000,000 -> 1,000
- `http_max_field_name_size`: 128 KB -> 4 KB

Also adds `http_max_request_header_size` to cap the total size of all
HTTP headers combined, and `http_headers_read_timeout` to enforce a
wall-clock deadline on header parsing (via `DeadlineReadBuffer`).

Applied to both ClickHouse server and Keeper.

Backport of ClickHouse/clickhouse-private#53097.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 20:00:59 +02:00
Alexey Milovidov 49940c0453 Merge remote-tracking branch 'origin/master' into revert-98038-revert-96025-clickhouse-help 2026-04-20 02:08:29 +00:00
Alexey Milovidov 2093a3876d Merge remote-tracking branch 'origin/master' into fix-compiler-warnings
# Conflicts:
#	src/Common/WKB.cpp
#	src/Functions/array/arrayDotProduct.cpp
#	src/Interpreters/InterpreterSelectIntersectExceptQuery.cpp
#	src/Interpreters/InterpreterSelectQueryAnalyzer.cpp
#	src/Interpreters/InterpreterSelectWithUnionQuery.cpp
#	src/Server/KeeperHTTPHandlerFactory.cpp
#	src/Storages/MergeTree/MergeTreeReaderTextIndex.cpp
2026-04-19 11:57:10 +00:00
Michael Kolupaev 3159ee9d03 Merge remote-tracking branch 'origin/master' into fwd 2026-04-15 20:26:02 -07:00
Pervakov Grigorii 088a37e4c9 Merge branch 'master' into raft_reload_certs 2026-04-13 17:33:48 +02:00
Michael KolupaevandClaude Opus 4.6 944cff3d3c Extract KeeperRequestDispatcher from KeeperDispatcher
Split request processing (batching, session management, request/response
threads) into a separate `KeeperRequestDispatcher` class, leaving
`KeeperDispatcher` as a thin shell for snapshots, session ID assignment,
session cleanup, and cluster configuration management.

Key interface changes:
- `KeeperStateMachine` now takes a `KeeperResponseCallback` instead of
  a `ResponsesQueue &`, decoupling the state machine from the queue type.
- `KeeperServer` constructor takes `KeeperResponseCallback` instead of
  `ResponsesQueue &`.
- `KeeperServer::KeeperRaftServer` moved from .cpp anonymous definition
  to the header for visibility.
- `ZooKeeperResponseCallback` moved to `KeeperCommon.h`, returns `bool`
  for future flow control.
- `shutdown` now takes a `closed_all_connections` parameter.
- Consolidated `finishSession` calls into a single `SCOPE_EXIT` in
  `KeeperTCPHandler`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 15:45:25 -07:00
Alexey Milovidov 49ce5f9f0a Merge remote-tracking branch 'origin/master' into revert-98038-revert-96025-clickhouse-help 2026-03-30 07:43:50 +00:00
Alexey Milovidov 371e0b496d Merge remote-tracking branch 'origin/master' into fix-compiler-warnings 2026-03-29 23:20:54 +00:00
Alexey Milovidov e1628e842e Merge branch 'master' into revert-98038-revert-96025-clickhouse-help 2026-03-28 23:50:35 +01:00
Alexey MilovidovandClaude Opus 4.6 d5f952b04a Enable -Wmissing-prototypes compiler warning
Add `static` to file-local functions and forward declarations
for cross-TU functions to satisfy `-Wmissing-prototypes`.

This ensures all functions have visible prototypes before their
definitions, improving code quality and catching accidental
linkage issues.

Reference: https://github.com/ClickHouse/ClickHouse/issues/76944

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 20:11:07 +00:00
Alexey MilovidovandClaude Opus 4.6 ad7c4352fb Address review comments: remove stale #embed comments and add missing deps
- Remove "CMake doesn't recognize changes in #embed-ed files" comments
  from all files, since this PR now tracks those dependencies.
- Add conditional `OBJECT_DEPENDS` for `FrequencyHolder.cpp` NLP blobs
  (guarded by `if (EXISTS ...)` for when the submodule is not checked out).
- Add `OBJECT_DEPENDS` for `attachInformationSchemaTables.cpp` which was
  also missing dependency tracking for its embedded SQL files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 00:40:29 +01:00
Robert Schulze 2961824d5d Merge remote-tracking branch 'ClickHouse/master' into is_embed 2026-03-24 13:12:13 +00:00
Michael Stetsyuk 705a1e1fb4 Support soft memory limit for standalone keeper running as server 2026-03-20 11:17:05 +00:00
Robert Schulze 898b0d8270 Add comments 2026-03-15 19:01:55 +00:00