Repository navigation
Fix race between ALTER and RENAME/EXCHANGE TABLES - #103044
Conversation
|
Workflow [PR], commit [e0dce13] Summary: ✅
AI ReviewSummaryThis PR adds Findings❌ Blockers
Final Verdict❌ Changes requested. LLVM Coverage ReportMeasured on commit e0dce13.
Changed lines: Changed C/C++ lines covered: 245/282 (86.88%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…der the DDLGuard in ALTER
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 168/193 (87.05%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 16 line(s) · Uncovered code |
|
Dear @SmitaRKulkarni, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…d a deadlock with state application
…ent commit is rejected by design
|
Two behavioral regressions surfaced while reviewing this PR. Both were reproduced on the PR-head CI binary (26.9.1.1, f1c338e) with a pre-PR 26.9.1.1 master build as control. 1. DDL on the table hangs unboundedly (and unkillably) behind a barrier ALTER that is waiting for a pending mutation.
Repro at pure defaults on plain On the PR head the Holding the guard across the wait is load-bearing — releasing it would reopen the fixed corruption for the 2.
Repro: For completeness, the rest of the mechanism audited clean on my side: the guard is taken on every metadata-commit path I could find (including the replica queue's |
…e, document the bounded `DDLGuard` re-acquire inversion and name the timeout in its error
| { | ||
| DatabaseCatalog::instance().getDatabase(table_id.database_name)->alterTable(query_context, table_id, metadata_copy, /*validate_new_create_query=*/true); | ||
| } | ||
| catch (...) |
There was a problem hiding this comment.
changeSettings is still the only code here that writes the setting-derived escape_index_filenames / secondary_indices[*].escape_filenames fields, but this branch writes an older metadata snapshot back afterwards.
Concrete case: ALTER TABLE ... ADD COLUMN y UInt8, COMMENT COLUMN x 'c', MODIFY SETTING escape_index_filenames = 0.
changeSettings(metadata_copy.settings_changes, ...) publishes the new filename policy, then setInMemoryMetadata(metadata_copy) above restores the old escape_index_filenames value from current_metadata, so this replica keeps using the old index filename policy until the ALTER_METADATA entry is replayed locally.
Please refresh metadata_copy.escape_index_filenames and every index.escape_filenames from the post-changeSettings metadata before publishing metadata_copy, the same way the areNonReplicatedAlterCommands() branch already does.
| catch (...) | ||
| { | ||
| /// Revert in-memory so system.* doesn't diverge from SHOW CREATE TABLE. | ||
| changeSettings(old_metadata.settings_changes, table_lock_holder); |
There was a problem hiding this comment.
The pure isSettingsAlter() path now rolls back correctly on save failure, but the same escape_index_filenames clobber is still present lower in StorageMergeTree::alter in the mixed metadata path around 637/695.
Concrete case: ALTER TABLE ... COMMENT COLUMN x 'c', MODIFY SETTING escape_index_filenames = 0.
There, changeSettings(...) installs the new filename policy in the live metadata, then the later setProperties(new_metadata, ...) republishes the pre-changeSettings escape_index_filenames / secondary_indices[*].escape_filenames values that came from commands.apply(...). After a successful ALTER, SHOW CREATE contains the new setting, but runtime code keeps using the old policy until restart.
Please refresh those derived fields from the post-changeSettings metadata before checkMetadataProperties(...), alterTable(...), and setProperties(...), the same way the replicated mixed branch already does.
|
@evillique green and approved. Let's merge? |
Fix a race between
ALTERandRENAME/EXCHANGE TABLES. A concurrentEXCHANGEcould slip in betweengetStorageIDandIDatabase::alterTableinsideIStorage::alter, soALTERwould throwUNKNOWN_TABLEorCANNOT_ASSIGN_ALTER. In theCOMMENTandSETTINGfast paths it could also leave the in-memory metadata out of sync with the.sqlfile until the next restart.ALTERnow holds aDDLGuardon the storage (with a rename-safe retry on acquisition), and every path that applies a local setting or comment change reverts it if saving the metadata fails.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix the race between ALTER and RENAME/EXCHANGE TABLES.
Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/103044]
Version info
26.9.1.1481(included in26.9and later)