Repository navigation
Fix possible logical error "Unexpected substream ... for column ..." during bump of compatibility setting - #109496
Conversation
Previously `tryToChangeStreamFileNameSettingsForNotFoundStream` only fell back from escaped to unescaped variant subcolumn filenames. This meant a replica with `escape_variant_subcolumn_filenames=0` could not read parts written by a replica with the setting enabled, which is a problem in hydra groups where replicas share a Keeper but may have different values of this compatibility setting during a rollout. Make the fallback bidirectional: toggle `escape_variant_substreams` regardless of its current value so that both directions are tried when the primary filename is not found in the part checksums. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Workflow [PR], commit [b7da162] Summary: ✅
AI ReviewSummaryThis PR makes Final VerdictStatus: ✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 49/51 (96.08%) · Uncovered code |
|
Updating the branch to fix the |
…:ClickHouse/ClickHouse into escape-variant-subcolumn-bidirectional-fallback
…lumn_filenames` `collectFilesForRenames` used `getStreamNameOrHash` (no fallback) to resolve source stream filenames during `RENAME COLUMN`. When a wide part was written with a different `escape_variant_subcolumn_filenames` value than the current setting, the lookup silently failed and the rename was skipped, leaving mismatched filenames and metadata in the mutated part. Switch to `getStreamNameForColumn`, which already includes the bidirectional fallback via `tryToChangeStreamFileNameSettingsForNotFoundStream`, matching how `DROP_COLUMN` resolves streams. Add focused regression tests for `RENAME COLUMN` after toggling the setting in both directions (0->1 and 1->0). Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ile renames Instead of enumerating substream paths via serialization (which computes filenames from the current `escape_variant_subcolumn_filenames` setting), iterate the source part's `columns_substreams.txt` entries directly and apply `getFileNameForRenamedColumnStream` — the same function `addRenamedColumnToColumnsSubstreams` uses. This keeps file renames and `columns_substreams.txt` consistent regardless of whether `escape_variant_subcolumn_filenames` differs between the source part and the current setting. Add `ColumnsSubstreams::tryGetColumnSubstreams` that looks up substreams by column name so callers don't need to search for the column position manually. Fall back to the original `enumerateStreams` approach for old parts without `columns_substreams.txt`. Add a shell test that directly verifies .bin filenames on disk, columns_substreams.txt content, and CHECK TABLE after RENAME COLUMN with a flipped escape_variant_subcolumn_filenames setting in both directions. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…hout `columns_substreams.txt` When `columns_substreams.txt` is missing (old or corrupted parts), the fallback path in `collectFilesForRenames` now uses `getStreamNameForColumn` (with bidirectional fallback) instead of `getStreamNameOrHash`. This ensures renames succeed even when the part was written with a different `escape_variant_subcolumn_filenames` value. Also adds test cases 3 and 4 to the shell test that exercise this fallback by detaching the table, removing `columns_substreams.txt`, re-attaching, flipping the escaping setting, and verifying rename works. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…olumn-bidirectional-fallback
…with master The branch and master both added an identical declaration of `ColumnsSubstreams::tryGetColumnSubstreams`, and the merge kept both, which broke the build in CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109496&sha=afcba83c0970b7ee66c676dd56875243d4f37c9e&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Fable 5 <[email protected]>
…olumn-bidirectional-fallback
… on Linux The test inspects the part directory on disk directly, so it only makes sense on a plain local disk on Linux: - On macOS the filesystem (APFS) is case-insensitive, which makes `MergeTree` hash stream filenames unconditionally (see `MergeTreeData::getFullNameForFile`), so the expected `v.Tuple(a UInt32, b UInt32)%2Ea.bin`-style names never appear and the test failed in `Fast test (arm_darwin)`. The pre-existing `03369_variant_escape_filename_merge_tree` is tagged `no-darwin` for the same reason. - For object storage the local part directory holds metadata files rather than the data itself, so `cat columns_substreams.txt` printed blob metadata instead of the substream list, and removing that metadata file in cases 3 and 4 left the part unreadable. The test failed in every `s3 storage` / `azure` stateless run for this reason. Mirror the tags used by the sibling tests that read part files directly (`04093_rename_column_corrupts_columns_substreams`, `04235_corrupted_columns_substreams_detection`). CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109496&sha=62eeb400eafe86cedff9b5a4e9a36aa722633cda PR: #109496
|
Merged The remaining failures in https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109496&sha=62eeb400eafe86cedff9b5a4e9a36aa722633cda are unrelated to this change:
@groeneai, two of the unrelated failures have no tracking issue - could you investigate them and provide fixes in separate PRs (or link the fixes if already in progress)?
|
|
Thanks for splitting these out. Answers below. 1. Already tracked and fixed in #110997 (head 2. Not a pre-existing flake, and not coverage-build noise. It is a regression with a sharp onset on 2026-07-19, and it is deterministic-ish rather than random. Data, restricted to the exact signature (
All 19 are on one job, The onset is the duration of the test on that job, and it is not gradual. Median runtime of
Bisecting the master runs on that shard puts the step between two adjacent commits: That range contains exactly two merges: #100992 and #108048. #100992 only touches The mechanism, from the job's own All three replicas each scan the full 500,000,001 rows and each write the same 10000 rows. The initiator finishes its local execution at 14:55:55.132, the outer statement gives up at 14:57:55.798, i.e. exactly 120.7s later, against The relevant part of #108048 is that a plain const bool allow_create_select_for_replicated
= (create.isView() && !create.is_populate) || create.is_create_empty || !is_storage_replicated;
So it is neither of the two options you framed. There is no DDL-worker hang (the replicas execute correctly and the table ends up populated on all three), and the timeout is not merely too tight for a coverage build in general: the same job ran this test in 125s for months. The regression is that this statement now costs 3x the populate under Replicated database, plus a serialization that puts the initiator's populate outside the replicas' wait window. I do not have a fix PR yet. I am investigating at full effort and I will post the fixing-PR link in this thread. Two candidate directions I am deciding between, and I want to name my uncertainty rather than guess: tightening Session id: cron:clickhouse-premium-slot-24:20260726-223253 |
Item 2:
|
| shard | before 07-19 | after 07-19 |
|---|---|---|
amd_llvm_coverage ... DBReplicated ... 2/3 |
124.0s (n=4475) | 287.1s (n=1984) |
amd_llvm_coverage, non-Replicated (control) |
113.9s (n=17724) | 113.6s (n=6589) |
3 replicas x ~96s serialized is ~288s, matching 287.1s. So it is not a runner or coverage change.
Mechanism. Carrier is #108048 (merge 696bbe0031dbca). On a Replicated database this statement is one DDL entry that every replica re-executes in full, and a replica blocks on the entry's ephemeral /try znode until the initiator commits its ZooKeeperMetadataTransaction (DatabaseReplicatedWorker.cpp:652-697). So the commit point decides when replicas may start.
Before #108048, createTable fell through to doCreateTable and the commit fired inside commitCreateTable (DatabaseAtomic.cpp:429-430), i.e. before the populate. The N populates overlapped, total ~1x.
After #108048, a plain CREATE ... AS SELECT routes through doCreateOrReplaceTable (InterpreterCreateQuery.cpp:1961-1968). Both writes there run on contexts for which isInternalSubquery() is true (create_context at :2385-2386, make_internal_context at :2424-2441), so neither guarded commit fires; the transaction is committed only by the fallback in DDLWorker::tryExecuteQuery (DDLWorker.cpp:593-597), after the populate and the rename. /try is held for the initiator's whole populate, so the per-replica populates now run strictly one after another. The initiator then waits a fresh distributed_ddl_task_timeout (120s in the CI profile) while replicas that need 165-183s have barely started.
Why I did not just move the commit earlier. The publishing RENAME re-attaches the same transaction object (:2434-2438, attach_existing=true), and that transaction is single-shot: addOp throws LOGICAL_ERROR once it is executed (DDLTask.h:248-253), and DatabaseReplicated::renameTable unconditionally adds ops (DatabaseReplicated.cpp:2568-2595). Committing early also publishes /committed together with a finished_node_path carrying ExecutionStatus(0), i.e. "finished successfully" (DDLWorker.cpp:736-737), while the final table does not exist yet, so a failed populate would leave committed _tmp_replace_* metadata and no final table. That is worse than the old behaviour.
Why I did not just exclude Replicated databases from the temp-table path. That reintroduces #26746 there. Today, when the populate fails the initial query rethrows (DDLWorker.cpp:603-604), the ephemeral /try holder is destroyed, and replicas skip the entry as uncommitted, so no orphan is left on any replica. Under the old path the entry is already committed, so every replica creates and keeps the empty orphan. It would also invert 04547_create_as_select_destination_not_visible_during_populate, which is untagged and currently passes on that exact shard (1689 OK / 0 FAIL over 6 days).
So atomic-publish-with-no-orphan and cross-replica populate concurrency cannot both hold without changing the entry protocol: the commit is simultaneously what makes the publish atomic and what releases the replicas.
Options, in my order of preference:
- Split the statement into two replicated log entries (create, then populate+publish), so the create commits promptly and replicas populate concurrently. Keeps both guarantees, but it is a protocol change in
DatabaseReplicatedand the largest diff. - Allow two commits per entry for this path (commit the create, then a second transaction for the rename). Smaller, but it weakens the single-transaction invariant the
is_create_or_replace_queryflag exists to protect. - Keep the current behaviour and treat the slowdown as accepted for Replicated databases, in which case
03236_squashing_high_memoryneeds a real remedy rather than a timeout bump, and the setting doc fordatabase_replicated_allow_heavy_create("can block DDL queue for a long time") now describes statements that never opted in.
I am happy to implement any of these. @alexey-milovidov which do you prefer?
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 33/35 (94.29%) · Uncovered code |
…olumn-bidirectional-fallback
…name_rename_consistency`
The test inspects the part directory directly: it lists the `.bin` files and reads
`columns_substreams.txt`. With packed part storage all of those live inside a single
blob, so no individual files exist on disk. CI randomizes
`min_bytes_for_full_part_storage` to a large value, which switches the parts to packed
storage and made the test fail in every stateless run:
cat: .../all_1_1_0/columns_substreams.txt: No such file or directory
Pin the setting to its default `0` so the parts always use full storage.
…olumn-bidirectional-fallback
|
🕵 The only red, Stress test (arm_release), was an unrelated harness flake: the fail-close verification query in |
…olumn-bidirectional-fallback
|
🕵 The only non-performance red on the last run, Build (arm_release), is unrelated to this PR: the build itself succeeded, but the Merged the latest |
…-variant-subcolumn-bidirectional-fallback
…m probes The compact reader's check_stream_exists_callback probed columns_substreams.txt with the current escape_variant_subcolumn_filenames value only. For a compact part written with the other value, an optional Variant substream (MapBucketIndexes of a bucketed Map) was reported absent after the setting was flipped, so the reader took the "no bucket index" path and reordered map elements. Add a bidirectional tryGetSubstreamPosition overload on ColumnsSubstreams (mirroring the existing getSubstreamPosition) that retries with the flipped setting, and use it in both compact-reader probes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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. Compile time of recompiled translation units282 translation units recompiled, 3467 s compile time in total, 282 of them have a recent master baseline. |
…tream ... for column ..." during bump of compatibility setting
Backport #109496 to 26.7: Fix possible logical error "Unexpected substream ... for column ..." during bump of compatibility setting
Backport #109496 to 26.5: Fix possible logical error "Unexpected substream ... for column ..." during bump of compatibility setting
Backport #109496 to 26.3: Fix possible logical error "Unexpected substream ... for column ..." during bump of compatibility setting
Backport #109496 to 26.6: Fix possible logical error "Unexpected substream ... for column ..." during bump of compatibility setting
…ected substream ... for column ..." during bump of compatibility setting
…ected substream ... for column ..." during bump of compatibility setting
…ected substream ... for column ..." during bump of compatibility setting
STOR: changing the `compatibility` setting (upgrade) -> exc LOGICAL_ERROR Unexpected substream. Effect in the production build a394e92: wrong/failing (the upstream test fails on it and passes on official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro/residual/109496.PROD263.txt). Upstream patch unchanged, with its test(s): 04409_variant_escape_filename_fallback, 04507_variant_escape_filename_rename_consistency, 04839_variant_escape_filename_compact_map_buckets. Depends on ClickHouse#109178 (26.3 backport ClickHouse#113094), applied before it as on the 26.3 branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dependency of the ClickHouse#109496 backport (d56fb49): its MutateTask.cpp change calls ColumnsSubstreams::tryGetColumnSubstreams, which this change adds, so d56fb49 does not compile without it (found by a syntax check of every file the backports change). The 26.3 branch merged this backport on 2026-07-27, before the ClickHouse#109496 backport (2026-08-13). Fix: a part produced by a mutation of a table with a Dynamic column could miss the variant_discr stream (LOGICAL_ERROR on read); upstream patch unchanged, with its tests 04341, 04342, 04401 and 04412 (the local triage did not reproduce the first two on the production build; the other two need a server). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix possible logical error "Unexpected substream ... for column ..." during bump of compatibility setting.
Version info
26.8.1.1366(included in26.8and later)26.7.4.33,26.6.3.52,26.5.7.55,26.3.18.28