Repository navigation
Conversation
Fixes the 26.3-only ClickHouse#80648 data loss that makes 04238_alter_rename_column_merge_race fail with "expected 10 non-empty rows, got 0": a concurrent RENAME COLUMN plus OPTIMIZE FINAL permanently fills the renamed column with its DEFAULT in the merged part. StorageMergeTree::optimize calls merge() synchronously on the query thread, so the merge-selection read inside the currently_processing_in_background_mutex runs with a query context. MergeTreeData overrides getInMemoryMetadataPtr with a per-query metadata cache, which InterpreterOptimizeQuery has already populated with the pre-ALTER snapshot, so the read returns metadata that predates the rename while selection pairs it with parts that already carry the mutation. MergeTask derives storage_columns from that snapshot and never re-reads metadata, so the stale column list is what gets written. Reading with bypass_metadata_cache=true makes that read honour the invariant the comment above it already states. This restores what the backport of ClickHouse#104822 lost: 26.4+ declare the accessor as (ContextPtr, bool) with no default, which forces every caller to state a context, whereas on 26.3 the parameter is defaulted, so the cherry-picked call compiled unchanged as getInMemoryMetadataPtr() and silently selected the cache-consulting path. Taking that PR's own added src/ lines longer than 25 characters that are not comments, whitespace-normalized and deduplicated, and testing membership against each branch's copy of the seven files it touches, gives 113 of 113 present on 26.4 through 26.7 and on master, and 111 of 113 on 26.3. The two absent lines are exactly this metadata read and the assignment that follows it. Measured on two servers built from this tree, each on its own port and data directory, loops interleaved so the arms are load-matched, with enable_shared_storage_snapshot_in_query left at its default. Every arm asserts SELECT lower(buildId()) against the port it uses and aborts on mismatch. Base reddens 16 times in 7000 iterations and the fix 0 (Fisher exact two-sided p = 3.0e-05); after swapping the two binaries onto each other's port and data directory the effect follows the binary, base 30/7000 against fix 0/7000 (p = 1.8e-09). At the runner level, 80 runs of the unmodified test per arm give 3 failures on base carrying the exact CI signature and 80/80 OK on the fix. scheduleDataProcessingJob keeps its bare read: its only StorageMergeTree caller is the background pool, where there is no query context, so that read already bypasses. No test file was modified; 04238_alter_rename_column_merge_race is the oracle and is byte-identical across branches. No setting, format or API change.
This was referenced Aug 15, 2026
Merged
Contributor
|
Workflow [BackportPR], commit [2dbae14] Summary: ✅ |
Collaborator
Author
CI finish ledger - 2dbae14Every failure below has an owner. Attempt 2 of the BackportPR run is fully green
Evidence that the row is unrelated to this change: this test has 8486 OK / 0 FAIL on Session id: cron:our-pr-ci-monitor:20260815-043000 |
Member
|
The fix is already merged |
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed data loss when a
RENAME COLUMNruns concurrently withOPTIMIZE TABLE ... FINALon aMergeTreetable: the merged part could be written with the pre-rename column list, permanently filling the renamed column with itsDEFAULT.Description
26.3-only fix for issue 80648, authorized in #113929 (comment).StorageMergeTree::optimizecallsmergesynchronously on the query thread, so the merge-selectionmetadata read runs with a live query context.
MergeTreeDataoverridesgetInMemoryMetadataPtrwitha per-query cache that
InterpreterOptimizeQueryhas already populated with the pre-ALTERsnapshot,so the read returns metadata predating the rename while selection pairs it with parts that already
carry the mutation.
MergeTasktakesstorage_columnsfrom that snapshot and never re-reads, so themerged part keeps the old column list and the renamed column stays
DEFAULT.Passing
bypass_metadata_cache=truemakes the read honour the invariant the comment above it alreadystates.
scheduleDataProcessingJobkeeps its bare read: its only caller is the background pool, whichhas no query context, so it already bypasses.
26.4and later declare the accessor as(ContextPtr, bool)with no default, forcing every caller tostate a context, so the read is already fresh there.
25.8has the same bare read but shipsenable_shared_storage_snapshot_in_querydefaulting tofalse.26.3is the only supported branchwith both the defaulted parameter and that setting
true, which is why the backport of 104822compiled unchanged as
getInMemoryMetadataPtr()and took the cache-consulting path.Validation on two interleaved, load-matched servers built from this tree, setting at its default:
base reddens 16 of 7000 iterations against 0 for the fix (Fisher exact p = 3.0e-05); swapping the
binaries onto each other's port and data directory keeps the effect with the binary (30/7000 against
0/7000); 80 runner runs of the unmodified
04238_alter_rename_column_merge_raceper arm give 3 basefailures with the exact CI signature and 80/80 on the fix. None of the 211 merge and mutation tests
with a verdict in both arms regressed.