Repository navigation
Fix unparseable metadata for a NATS table defined only by a named collection - #120025
Conversation
…lection registerStorageNATS called NATSSettings::loadFromQuery unconditionally. With ENGINE = NATS(collection) and no SETTINGS clause, args.storage_def->settings is null, and loadFromQuery's else branch attaches an empty ASTSetQuery to the ASTStorage. ASTStorage::formatImpl emits the keyword for any non-null settings member, so the definition serialized into the table's metadata file ends in a bare "SETTINGS ". Re-parsing that file fails with SYNTAX_ERROR, which makes the table unloadable and aborts the whole database load, so unrelated healthy tables in the same database become inaccessible too. Guard the call, exactly as the sibling registrars already do: StorageRabbitMQ.cpp has the same preceding "else if (!args.storage_def->settings) throw" together with the guard, and its RabbitMQSettings::loadFromQuery carries the identical empty-ASTSetQuery branch; StorageKafkaUtils.cpp and StorageDistributed.cpp guard the same way. Nothing after the call needs settings to be non-null: the later uses are already inside "if (args.storage_def->settings)". The empty-ASTSetQuery branch of NATSSettings::loadFromQuery becomes unreachable and is left in place so that NATS and RabbitMQ stay the same shape. The shape became reachable when named collections were added in b3ca976; the unguarded call dates from the original engine in 944a729. 05029_nats_tls_certificate_path_restriction already coded around this defect: its full-definition ATTACH carried SETTINGS nats_num_consumers = 1 purely so that the stored definition would parse on the DETACH/ATTACH replay that follows. Removing that crutch turns the existing block into the regression oracle. The value equalled the setting's own default and is read nowhere in the certificate provenance logic, so the block's assertions keep their meaning. Without this fix the short ATTACH fails with SYNTAX_ERROR (62) where the test expects BAD_ARGUMENTS (36). Closes ClickHouse#119120
04891_nats_credential_file_path_restriction carried the same SETTINGS nats_num_consumers = 1 crutch on the full-definition ATTACH whose metadata the block replays, and a comment stating that a collection-only definition is stored with an empty SETTINGS clause. The guard added in this branch makes that comment false, so remove the crutch there too: the block then covers the fixed shape on the credential-file path as well. The value equalled the setting's own default and is read nowhere in the credential provenance logic, so every assertion keeps its meaning. Without the guard the short ATTACH of that block fails with SYNTAX_ERROR (62) where the test expects BAD_ARGUMENTS (36). Both replay blocks now state what the stored definition must carry instead of describing what it happens to carry, so the property the block exists to check does not read as an incidental remark.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 rounds, 1 finding in round 1 and 0 in
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260914-154400 |
|
Workflow [PR], commit [c117d58] Summary: ✅
AI ReviewSummaryThis PR fixes the Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit c117d58.
Changed lines: Changed C/C++ lines covered: 4/5 (80.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
a0a74ce
|
@groeneai Just to check, do we need to backport this? |
|
Yes, I would backport it. All four active release branches are affected, and I reproduced it on the latest official build of each rather than reading it off the source (
Both halves of the mechanism are present on all four: the unguarded If you agree, One heads-up on the cherry-picks. Only the one-line guard applies everywhere; the two test hunks are deletions inside files the older branches do not have ( |
|
The four robot cherry-picks of this PR opened CONFLICTING, so here are the resolutions I said I would provide. Each one carries its own comment with the scope, the verification and a two-command fast-forward:
Nothing in any of them is hand-authored: every byte is git's own 3-way merge plus dropping a test file the release branch does not have. |
Cherry pick #120025 to 26.3: Fix unparseable metadata for a NATS table defined only by a named collection
…efined only by a named collection
Cherry pick #120025 to 26.6: Fix unparseable metadata for a NATS table defined only by a named collection
…efined only by a named collection
Cherry pick #120025 to 26.7: Fix unparseable metadata for a NATS table defined only by a named collection
…efined only by a named collection
Cherry pick #120025 to 26.8: Fix unparseable metadata for a NATS table defined only by a named collection
…efined only by a named collection
Backport #120025 to 26.3: Fix unparseable metadata for a NATS table defined only by a named collection
Backport #120025 to 26.7: Fix unparseable metadata for a NATS table defined only by a named collection
Backport #120025 to 26.8: Fix unparseable metadata for a NATS table defined only by a named collection
Backport #120025 to 26.6: Fix unparseable metadata for a NATS table defined only by a named collection
Closes: #119120
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
NATStable whose settings all come from a named collection (ENGINE = NATS(collection)with noSETTINGSclause) being written to its metadata file with a danglingSETTINGSkeyword. The stored definition could not be parsed again, so the table failed to load and aborted the load of its whole database, making unrelated tables in it inaccessible. Closes #119120Description
registerStorageNATScalledNATSSettings::loadFromQueryunconditionally. When the engine definition is only a named collection,args.storage_def->settingsis null, and that function'selsebranch attaches an emptyASTSetQuery;ASTStorage::formatImplthen emits the keyword for any non-nullsettingsmember, so the definition serialized into the metadata file ends in a bareSETTINGS.Reproduced on
master:The stored file ends
ENGINE = NATS(c)/SETTINGSand the reload fails:The fix guards the call, as the sibling registrars already do:
StorageRabbitMQ.cpphas the same precedingelse if (!args.storage_def->settings) throwplus the guard, and itsRabbitMQSettings::loadFromQuerycarries the identical empty-ASTSetQuerybranch;StorageKafkaUtils.cppandStorageDistributed.cpplikewise. That branch becomes unreachable; I left it so NATS and RabbitMQ stay the same shape.Test:
05029_nats_tls_certificate_path_restrictionand04891_nats_credential_file_path_restrictionboth coded around this defect, carryingSETTINGS nats_num_consumers = 1on a full-definitionATTACHonly so the stored definition would parse on theDETACH/ATTACHreplay that follows. Removing both crutches turns those blocks into the regression oracles: without this fix each shortATTACHfailsSYNTAX_ERROR(62) where the test expectsBAD_ARGUMENTS(36). The removed value equalled the setting's own default and reaches neither provenance path, so every assertion keeps its meaning.Scope: this stops new corruption. A file an older server already wrote this way still needs the dangling keyword removed by hand, because the parse failure aborts the database load before the table can be dropped.
Workflow [PR]
Sync PR [sync-upstream/pr/120025]
Version info
26.9.1.1525(included in26.9and later)26.8.7.9,26.7.11.5,26.6.9.5,26.3.33.94