Repository navigation
Do not bound the parse of a table's metadata in a Replicated database by the reader's parser limits - #119220
Do not bound the parse of a table's metadata in a Replicated database by the reader's parser limits#119220alexey-milovidov wants to merge 5 commits into
Conversation
`recoverLostReplica` re-parses the metadata of every replicated table it finds in ZooKeeper, and it did so with the recovering replica's own `max_query_size`. A table whose metadata is longer than that - a wide schema, long expressions, a large comment - was therefore out of reach: the parse threw `Max query size exceeded` before the table was created and the recovery retried forever, while the replicas that had loaded the very same text from their disk kept serving it. Every other place that re-parses this metadata passes no limit, because the text is generated by a server and is as long as the definition needs, while `max_query_size` bounds what a client may send - and a recovering replica cannot learn the value the creating session raised it to. Closes: #117695
|
Workflow [PR], commit [46549fb] Summary: ✅
AI ReviewSummaryThis PR removes the recovering replica's Findings
Final VerdictStatus: Minimum required action: close the remaining local-metadata reread hole for LLVM Coverage ReportMeasured on commit 46549fb.
Changed lines: Changed C/C++ lines covered: 28/28 (100.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, 15 s compile time in total, 7 of them have a recent master baseline. |
…ery-metadata-size-117695
…'s parser limits Address review: the recovery of a `Replicated` database still re-parsed the table metadata stored in ZooKeeper with the recovering server's `max_parser_depth` and `max_parser_backtracks`, so a table created on a server whose default profile raises them (the `Replicated` DDL worker re-parses every entry with the default profile, so a session-level raise is not enough) left a new or lost replica retrying forever with `AST is too deep`, exactly as the `max_query_size` case did. All three parses of the stored metadata in `DatabaseReplicated` (`getTableUUIDIfReplicated`, `parseQueryFromMetadata`, `getTablesForBackup`) now go through one `parseStoredMetadata` helper that passes `0` for the size, depth and backtracks limits, as `SQLDefinedHandlersMetadataStorage` and `StorageSystemHandlers` already do for the statements they store: the text is the server's own canonical output, already validated when the table was created, and `parseQuery` still guards the stack via `checkStackSize`. The regression is covered by an integration test with two nodes whose default profiles differ in the parser limits, which is the only way such metadata comes to be. The stateless test for the size case is renumbered after the merge of master. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes only how a Replicated database re-parses stored CREATE metadata: it drops the parser size, depth and backtrack limits during replica recovery, backup and metadata loading, and adds tests. None of that runs during SELECT execution in clickbench or tpch_adapted_1_official. Only Q33 (+8.7%) and Q34 (+5.3%) on clickbench were flagged. Both are heavy GROUP BY URL aggregations, and the automated checks already marked them inconclusive because their medians (1237.5 ms and 1208 ms) fall inside master's current run-to-run range. That call is consistent with the diff, so no performance impact is attributed to this PR. clickbenchFlagged queries (2 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
…ery-metadata-size-117695
…tizer builds The table definition nested 600 levels deep made the analyzer throw `Stack size too large` (`TOO_DEEP_RECURSION`) on `CREATE TABLE` in the ASan, MSan and TSan integration jobs (TSan allows only 5% of the stack in `checkStackSize`). Nest the default expression 30 levels deep instead and lower `max_parser_depth` / `max_ast_depth` of the recovering node to 50, so the stored metadata still exceeds its limits (about two levels of parser depth per nesting). https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=119220&sha=7ac909d4a46756ef541d4cf2f3af6cbced2bf2d6&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%203%2F6%29 PR: #119220 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
I don't like the change. |
A
Replicateddatabase whose table metadata in ZooKeeper is longer thanmax_query_size, or nested deeper thanmax_parser_depth, could not be recovered by a new or lost replica:recoverLostReplicare-parses that metadata for every table it finds, and the parses inDatabaseReplicatedused the recovering server's own limits (getTableUUIDIfReplicatedeven itsmax_query_size, 262144 by default). The parse threwMax query size exceededorAST is too deepbefore the table was created, the recovery retried forever, and the database stayed one replica short - while the replicas that had loaded the very same text from their disk kept serving it.The metadata is the server's own canonical
CREATEtext, already parsed and validated when the table was created, and it is as long and as deep as the table's definition needs, whilemax_query_size,max_parser_depthandmax_parser_backtracksbound what a client may send. A recovering replica has no way to learn the values the creating server used, so all three parses of the stored metadata inDatabaseReplicated(getTableUUIDIfReplicated,parseQueryFromMetadata,getTablesForBackup) now go through oneparseStoredMetadatahelper that passes0for every limit, asSQLDefinedHandlersMetadataStorageandStorageSystemHandlersalready do for the statements they store.parseQuerystill guards the stack viacheckStackSize.Metadata over 256 KiB is reachable with a wide schema, long
DEFAULT/CODEC/TTLexpressions or a largeCOMMENT, from any session that raisedmax_query_sizefor itsCREATE. Metadata deeper than 1000 levels needs the creating server's default profile to raise the parser limits, because theReplicatedDDL worker re-parses every entry with that profile; the integration test models exactly that with two differently configured nodes.Closes: #117695
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed a new or recovering replica of a
Replicateddatabase being unable to recover a table whose metadata in ZooKeeper is longer thanmax_query_sizeor nested deeper thanmax_parser_depth: the recovery refused the server-generated metadata for its size or depth and retried forever.Workflow [PR]
Sync PR [sync-upstream/pr/119220]