Repository navigation
Cherry pick #123649 to 26.9: Fix distributed queries failing when Native binary type encoding is enabled - #125064
Merged
Merged
Conversation
The initiator's server-side `Connection` (RemoteQueryExecutor, RemoteInserter, the Distributed async queue) never takes format settings, so it always reads and writes `Native` blocks with textual type names. Since fa40b43 `TCPHandler` builds its wire `NativeWriter` and `NativeReader` from the query's format settings, and a secondary query carries the initiator's settings. With `output_format_native_encode_types_in_binary_format = 1` the shard wrote binary-encoded types that the initiator parsed as names (`SYNTAX_ERROR`, or `UNKNOWN_CODEC` for `Dynamic`, whose type index is read as a 43-byte length); with `input_format_native_decode_types_in_binary_format = 1` the shard parsed the initiator's blocks, including the empty external-tables block of every remote SELECT, as binary types (`CORRUPTED_DATA`). `TCPHandler` now clears both flags in the wire format settings of a `SECONDARY_QUERY`, at all six sites. The query context is unchanged, so a shard still applies the settings to formats it reads or writes itself (`remote(..., file(..., Native))`); stripping them on the sender side in `ClusterProxy::stripInitiatorOnlySettings` would break exactly that. This is the cause of the `04819_dynamic_aggregate_function_state_version` failures in the ParallelReplicas coverage lane (issue #116341 read it as a teardown race): the 4th fetch is the only one with the encode flag, and it fails whenever a remote replica's packet is read before the local plan finishes. The Native format and protocol specs are updated, and the new test 05317_native_binary_types_between_servers covers remote read, parallel replicas, remote insert and a shard-side file() read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commit made `TCPHandler` ignore both binary type encoding flags for the wire of a `SECONDARY_QUERY`, but `clickhouse-client --query_kind secondary_query` still configured its own `Connection` from them. With both flags set that query worked before (both ends binary) and desynchronized after (server names, client binary): `CORRUPTED_DATA` on INSERT and SELECT. The rule now lives in one function, `getNativeWireFormatSettings`, used by the six `TCPHandler` wire sites and by both places where the client configures its `Connection`. The client's own input and output formats keep honouring the flags. The spec text states the symmetric rule. 05317 becomes a shell test so it can send a secondary query from the client; that part is green on master and red on the server-only fix, while the server-to-server parts stay red on master. The parallel replicas leg now pins `automatic_parallel_replicas_mode = 0`, which the runner randomizes to 2 (statistics only, no parallel read) in a quarter of the runs, and checks `ParallelReplicasUsedCount`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A secondary query's `Native` blocks carry type names only when both peers are at `DBMS_MIN_REVISION_WITH_TYPE_NAMES_FOR_SECONDARY_QUERY` (54493). `getNativeWireFormatSettings` takes the peer's revision: `TCPHandler` passes the client revision from the hello, `clickhouse-client` the server revision it got from `getServerVersion`. A peer built before this change honours both binary type encoding settings for a secondary query, so the unfenced rule broke `clickhouse-client --query_kind secondary_query` with both flags between an old and a new binary in either direction. With the fence every pairing with an older peer behaves as on master; an old initiator with a new shard keeps the master error. Bump `DBMS_TCP_PROTOCOL_VERSION` to 54493 and document the revision in the native protocol and format specs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`processParsedSingleQuery` set the Native wire format settings on the client `Connection` before the reconnect check. A reconnect replaces the object, and the replacement starts with no format settings and with the server revision it has only just learned, so the first query on it ignored both binary type encoding flags: the result failed with `SYNTAX_ERROR` (same order on master for any query kind). The call now runs after the check; nothing in between reads the format settings. The parallel replicas leg of 05317 pins `enable_parallel_blocks_marshalling = 1`, which the runner disables in 5% of the runs, so the step that reaches the two block-marshalling callbacks is always planned. New `test_backward_compatibility/test_native_type_names_secondary_query` runs `clickhouse-client --query_kind secondary_query` with both flags from a 25.3 client against this server and the reverse; it fails in both directions when the revision check in `getNativeWireFormatSettings` is removed. The Native format spec lists the revision in its gate table. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The parallel replicas leg of 05317 read through `test_cluster_one_shard_three_replicas_localhost`, whose 127.0.0.1 replica is a local address and so gets an uncompressed connection (`Cluster.cpp`, `compression` defaults to `!is_local`). Without a codec `convertColumnsToBLOBs` returns the block unchanged, so when the coordinator gave the granule to that replica no BLOB was made and the block-marshalling callback was not checked. The leg now uses the `parallel_replicas` cluster with `max_parallel_replicas = 2` and `load_balancing = 'in_order'`: that cluster lists 127.0.0.2 and 127.0.0.3 first, with fewer replicas than the cluster has the pools are ordered by `load_balancing` on `(error_count, priority, ...)`, and `distributed_replica_max_ignored_errors = 1000` keeps an error count left by another test from moving 127.0.0.1 ahead. Both used replicas are non-local, so whichever reads the granule compresses and marshals it. Shell tests run with `--send_logs_level=warning` and no query of 05317 made the shard log a warning, so no Log block crossed the shard wire. A new part runs the `remote()` read with `send_logs_level = 'trace'` and `--server_logs_file`, so the shard's Log blocks travel to the initiator. The protocol spec row for revision 54493 also names Totals and Extremes blocks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The server sends the user's profile settings in Hello, and the client applies the ones it did not change itself to its context in `applySettingsFromServerIfNeeded`. That ran one line after the client configured its `Connection` from the same context, and the per-query snapshot is restored afterwards, so the Native wire flags of a profile never reached the `Connection`: with both binary type encoding flags in the profile, the server wrote and read binary-encoded types while the client used type names, and every `clickhouse-client` query failed with `Code: 62` (same order on master). Swap the two calls. 05317 gains a part with both flags set on a user; it fails on master and on the previous head, passes now, and fails again with `--apply_settings_from_server 0`. The revision-table rows in protocol.mdx and format.mdx now say that below 54493 a server never applies these settings to its own connection, so between servers the shard and the initiator disagree. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ction Configure the client's Connection with the Native wire settings before the settings sent by the server are applied, as on master. The server writes type fields with output_format_native_encode_types_in_binary_format and the client reads them with input_format_native_decode_types_in_binary_format, so the two flags of a user profile must not reach the Connection one by one: a profile with only the input flag would make the client read every server block as binary types while the server sends type names. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g settings In cluster mode `QueryRunner` sends each job as an initial query over a server-side `Connection`, which never takes format settings and so always reads and writes type names. The remote server runs the job as an ordinary initial query, so it applies `output_format_native_encode_types_in_binary_format` and `input_format_native_decode_types_in_binary_format` from the job's settings to the wire. A job with the output flag set was therefore logged on the initiator as failed with `Code: 62` (`Syntax error (data type)`) while the remote finished it, on master as well. The connection now takes the job's format settings with the two flags swapped: it reads with the flag the remote writes with, and writes with the flag the remote reads with. Taking them unswapped, as `clickhouse-client` does, would break a job that sets only the input flag, which works today (measured: `Code: 246` for it). The remote side is unchanged, so this also works against servers without this change. 05317 gains a part with three jobs (both flags, output only, input only) on a `QueryRunner` table over `test_shard_localhost`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Scalars go through the same writer as Data blocks (`Connection::sendData`) and are read by `TCPHandler::initBlockInput`, so the revision 54493 rule covers them too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ary-types-between-servers # Conflicts: # src/Client/ClientBase.cpp # src/Formats/FormatFactory.cpp
…ary-types-between-servers Renumber `DBMS_MIN_REVISION_WITH_TYPE_NAMES_FOR_SECONDARY_QUERY` to 54494, after `DBMS_MIN_REVISION_WITH_UNIQ_STATE_VERSION_1` (54493) from master, and update the native protocol and format docs accordingly.
The master merge moved DBMS_MIN_REVISION_WITH_TYPE_NAMES_FOR_SECONDARY_QUERY to 54494, since 54493 is now UNIQ_STATE_VERSION_1. The revision row's text and the native settings paragraph still named 54493; format.mdx already says 54494. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ad path `TCPHandler::processUnexpectedData` read the blocks it discards with default format settings, while the main read path (`initBlockInput`) decodes them with `getNativeWireFormatSettings`. A peer encodes its `Data` packets the same way whether the server reads or skips them, so with `output_format_native_encode_types_in_binary_format` and `input_format_native_decode_types_in_binary_format` both set, a query that failed before its external data was read made the skip reader take a binary type code for a type name. The server then closed the connection, and the client reported `Connection reset by peer` instead of the query's error. Route the skip reader through the same helper, so it decodes exactly what the main reader would. 05317 gets a part that sends external data with both flags and fails the query server-side with `max_ast_elements`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-query rule The FLATTENED Dynamic layout snippet still said its per-type names switch to a binary type encoding whenever output_format_native_encode_types_in_binary_format = 1. At revision 54494+ a secondary query writes them as textual names, like the column type field (SerializationDynamic reads the same wire format settings). Co-Authored-By: Claude Opus 5.5 <[email protected]>
… out QueryRunner Review on #123649: with the revision check an old initiator talking to a new shard keeps the old error; without it a new shard also works with an old initiator, because a server-side Connection never takes format settings and always reads and writes type names. This fixes rolling upgrades. The cost is `clickhouse-client --query_kind secondary_query` with these settings between an old client and a new server. The integration test now runs a 25.3 initiator against a new shard with both settings (fails on master with Code 62). The QueryRunner cluster connection change goes to a separate PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-between-servers Fix distributed queries failing when Native binary type encoding is enabled
Resolve the cherry-pick conflicts on 26.9. In ClientBase.cpp and FormatFactory.cpp the conflicting context does not exist on this branch, so only this change's own hunks are kept. The docs hunks are dropped: their files are not at that path on this branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
|
The conflicts are context only. In What I checked:
@murphy-4o, I have After that the robot merges this PR and opens the 26.9 backport PR itself. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #123649
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job