Repository navigation
Fix replicated database log retention check overflow - #118103
Conversation
`logs_to_keep` setting sets how many log entries are retained in the replicated database DDL log. It was 64 bit wide and the straightforward check whether a log queue entry is in the retention window may result in overflow and unexpected removal of entries from the queue or replica being declared lost when it shouldn't. The head of the log pointer - `max_log_ptr` is 32-bit, and since it's derived from the Keeper node value we can't widen it to 64 bits. This commit adds `NonZeroUInt32` type for settings and uses it for the `logs_to_keep` setting. This way it's not possible to create a new database with `logs_to_keep` greater than `UInt32::max`. The retention check is rewritten in the overflow-safe way. To maintain backward compatibility any existing `logs_to_keep` value greater than `UInt32::max` is clamped to the `UInt32::max` on `ATTACH` or read from the Keeper. `UInt32::max` effectively means `retain all the logs`, which is arguably the intentional behavior of a large value, rather than wraparound checks.
|
Workflow [PR], commit [a7c3700] Summary: ✅
AI ReviewSummaryThis PR narrows Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit a7c3700.
Changed lines: Changed C/C++ lines covered: 148/149 (99.33%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes70 object files changed (+48.93 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 units1920 translation units recompiled, 11375 s compile time in total, 1920 of them have a recent master baseline. |
* Use distinct shard name. * Use metadata helpers to rewrite metadata file both with local and remote disk setup. * Reset metadata cache before `ATTACH` re-reads the edited file.
Add the case checking that during the replica initialization it's not declared lost due to an overflow error with too big `logs_to_keep` in Keeper.
`args.internal` is too broad flag for compatibility clamp check: it includes `PARALLEL WITH`/`EXECUTE AS` client queries. Instead a `is_metadata_load` flag is checked and a new `is_restore_from_backup` flag is introduced to cover the restore from the backup containing the old overflowing `logs_to_keep` values. A new integration test covering restore from the backup with overflowing `logs_to_keep` value is added.
* Make `05061_replicated_database_logs_to_keep_clamp` fail on probe timeouts. * Fix hardcoded UUID in `05223_replicated_database_logs_to_keep_internal_wrapper`
* Write clamped `logs_to_keep` value to the metadata on DB restore. * Clamped `logs_to_keep` value observed in `SHOW CREATE`, `engine_full` and `BACKUP`.
|
📊 Cloud Performance Report ✅ AI verdict: This PR only changes Replicated-database DDL-log retention plumbing: it narrows logs_to_keep to a range-checked 32-bit setting, clamps legacy over-range values on replay/restore/config, and adds an overflow-safe retention check. None of that touches the query-execution path a ClickBench SELECT exercises. Both flagged queries (Q16 +15.5%, Q18 +18.7%) sit inside master's current variance band and were already deterministically suppressed as within-envelope, so we downgrade them to not_sure — the deltas are run-to-run variance, not a real regression. Q16 is additionally marked noisy in its history, reinforcing that read. 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
|
logs_to_keepsetting sets how many log entries are retained in the replicated database DDL log.It was 64 bit wide and the straightforward check whether a log queue entry is in the retention window may result in overflow and unexpected removal of entries from the queue or replica being declared lost when it shouldn't.
The head of the log pointer -
max_log_ptris 32-bit, and since it's derived from the Keeper node value we can't widen it to 64 bits.This commit adds
NonZeroUInt32type for settings and uses it for thelogs_to_keepsetting. This way it's not possible to create a new database withlogs_to_keepgreater thanUInt32::max. The retention check is rewritten in the overflow-safe way.To maintain backward compatibility any existing
logs_to_keepvalue greater thanUInt32::maxis clamped to theUInt32::maxonATTACHor read from the Keeper.UInt32::maxeffectively meansretain all the logs, which is arguably the intentional behavior of a large value, rather than wraparound checks.Related: #117544
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix an integer overflow in the DDL log retention check of
Replicateddatabases that could cause premature removal of DDL log entries and replicas being incorrectly declared lost whenlogs_to_keepexceeded4294967295. Out-of-range values are now rejected onCREATEand clamped (with a warning) when replayed from existing metadata, server config, or Keeper.Workflow [PR]
Sync PR [sync-upstream/pr/118103]
Version info
26.10.1.715-master(included in26.10and later)