Repository navigation
Fix a replication queue stuck forever on a duplicated ALTER_METADATA entry - #117107
Conversation
…` entry
A replica created by cloning another one ends up with two `ALTER_METADATA`
entries of the same `alter_version` in its queue: the dummy one prepended by
`StorageReplicatedMergeTree::cloneMetadataIfNeeded`, and the one copied from
the source replica's queue. Both of them finish the same alter, and
`ReplicatedMergeTreeAltersSequence::finishMetadataAlter` used `operator[]`, so
the second completion inserted the already erased alter back into the sequence
as unfinished. Being the smallest version, it stayed at the head forever and
every later metadata alter was postponed with
Cannot execute alter metadata queue-0000000003 with version 9 because another alter 7 must be executed before
The replication queue never drained, so `SYSTEM SYNC REPLICA` hung until
`receive_timeout` and the replica never picked up the newer schema.
In the opposite interleaving, where the second entry is examined only after the
first one has completed, `canExecuteMetaAlter` postponed that entry forever
instead, because its version was already below the head - so the queue got
stuck either way. Both cases are fixed: a repeated completion is a no-op, and
an entry whose alter is already finished is allowed to execute, which
`StorageReplicatedMergeTree::executeMetadataAlter` handles as a no-op.
CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=db05a1cdad9653e2ac26ae6c1ecd819a07ac77e5&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%204%2F4%29
Closes: #53498
|
Workflow [PR], commit [706967b] Summary: ✅
AI ReviewSummaryThis PR fixes a real sequencing bug in Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 706967b.
Changed lines: Changed C/C++ lines covered: 74/74 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes276 object files changed (+40.55 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units376 translation units recompiled, 3123 s compile time in total, 375 of them have a recent master baseline. |
A replica created by cloning another one ends up with two
ALTER_METADATAentries of the samealter_versionin its replication queue:StorageReplicatedMergeTree::cloneMetadataIfNeeded, and/metadata_versionbut has not drained that entry yet).Both entries finish the same alter, and
ReplicatedMergeTreeAltersSequence::finishMetadataAlterusedoperator[], which inserts. So the second completion put the already erased alter back into the sequence as unfinished. Being the smallest version it stayed at the head forever, and every later metadata alter was postponed:The replication queue never drained, so
SYSTEM SYNC REPLICAhung untilreceive_timeoutand the replica never picked up the newer schema.In the opposite interleaving, where the second entry is examined only after the first one has completed,
canExecuteMetaAlterpostponed that entry forever instead, because its version was already below the head - so the queue got stuck either way.Both cases are fixed:
finishMetadataAlteris a no-op instead of resurrecting the alter, andALTER_METADATAentry whose alter is already finished is allowed to execute, whichStorageReplicatedMergeTree::executeMetadataAlteralready handles as a no-op ("Attempt to update metadata of version ... to older version ...").Added
src/Storages/tests/gtest_replicated_merge_tree_alters_sequence.cpp, which replays the exact sequence of sequence operations taken from the failing CI log, in both interleavings.This is the root cause of the long-standing flakiness of
test_replicated_database/test.py::test_simple_alter_table[ReplicatedMergeTree], which is the test that creates a replica after a delay and then synchronizes it.CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=db05a1cdad9653e2ac26ae6c1ecd819a07ac77e5&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%204%2F4%29
Closes: #53498
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a replication queue of a
ReplicatedMergeTreetable getting stuck forever after a new replica was added by cloning an existing one. The queue could contain twoALTER_METADATAentries for the sameALTER, and finishing the second one made all subsequentALTERs wait indefinitely, soSYSTEM SYNC REPLICAtimed out and the new replica never picked up the newer schema.Workflow [PR]
Sync PR [sync-upstream/pr/117107]