Repository navigation
Fix logical error on TRUNCATE of a TimeSeries table in a Replicated database - #117902
nikitamikhaylov merged 3 commits into
Conversation
…atabase `StorageTimeSeries::truncate` truncates every inner table with a separate nested query, and all of them were given the same `ZooKeeperMetadataTransaction`. A transaction can be consumed only once, so the second inner table threw `Cannot add ZooKeeper operation because query is executed`. Do not hand the transaction to the nested truncates. `DDLWorker` commits it after the whole query instead, so the entry is marked finished once every inner table is truncated. If the server dies in between, the entry is executed again, which is safe because `TRUNCATE` is idempotent.
|
Workflow [PR], commit [bf5bfeb] Summary: ✅
AI ReviewSummaryThis PR fixes the reused Findings
Final Verdict
LLVM Coverage ReportMeasured on commit bf5bfeb.
Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code |
A DDL query on a `Replicated` database returns a per-replica status, so the test printed an extra line under the default `distributed_ddl_output_mode`.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units11 translation units recompiled, 54 s compile time in total, 11 of them have a recent master baseline. |
`SharedEngineReplacer` only rewrote engines named in an `ENGINE =` clause, so inner tables generated from `default_table_engine` stayed replicated and the test failed on SMT disks with `ReplicatedMergeTree doesn't work with 's3_with_keeper' disk type`. Rewrite the setting value as well and accept both engine families in the assertion.
| line = line.replace(engine_from, engine_to) | ||
| break | ||
|
|
||
| line = self._replace_default_table_engine(line) |
There was a problem hiding this comment.
_replace_default_table_engine only runs inside the self.replace_replicated branch, but the --cloud setup clears args.replace_replicated_with_shared before switch_to_smt() constructs this replacer. That means cloud-mode transforms still leave implicit Replicated*MergeTree selections untouched. For example, running the current logic on 01166_truncate_multiple_partitions.sql still produces set default_table_engine='ReplicatedMergeTree';, so a cloud-eligible test can keep generating ReplicatedMergeTree tables even though the SMT rewrite path is supposed to move those tests onto Shared*MergeTree.
Can we apply this rewrite in the cloud path too (or gate it on self.replace_replicated or self.cloud) so default_table_engine behaves consistently across all SMT rewrites?
PromQL Compliance ReportBaseline: S3 master
Note: score is unchanged vs baseline. |
bcaec2e
Closes: #117900
Related: #115965
TRUNCATE TABLEon aTimeSeriestable inside aReplicateddatabase failed withLOGICAL_ERROR: Cannot add ZooKeeper operation because query is executed. It's a bug.:A distributed DDL entry carries one
ZooKeeperMetadataTransaction, and it can be consumed only once:moveOpsTodrains the ops and marks the transaction executed.StorageTimeSeries::truncatetruncates each inner table with a separate nested query and handed the same transaction to every one of them, so the first innerReplicatedMergeTreeconsumed it indropAllPartsInPartitionsand the second one threw. It fired even on empty tables, because the ops always carry thealter_partition_versionandlogset requests.The nested truncates no longer receive the transaction.
DDLWorker::tryExecuteQueryalready commits a transaction that the query left unexecuted, so the entry is now marked finished after every inner table is truncated instead of after the first one. If the server dies in between, the entry is executed again, which is safe becauseTRUNCATEis idempotent. Callers that touch a single owned table, such asStorageMaterializedView::truncate, keep propagating the transaction and are unchanged.Not addressed here: the inner tables are still truncated in separate ZooKeeper transactions, so a concurrent reader can observe a partially truncated series. That window is not new, and closing it needs a single multi spanning all the inner tables.
In CI this showed up in stress tests, where
ignore_drop_queries_probabilityrewrote theDROP TABLEof05028_time_series_default_table_engineinto aTRUNCATE. It hit six unrelated pull requests within a day.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the logical error
Cannot add ZooKeeper operation because query is executedwhen runningTRUNCATE TABLEon aTimeSeriestable in aReplicateddatabase.Workflow [PR]
Sync PR [sync-upstream/pr/117902]
Version info
26.9.1.801(included in26.9and later)