Repository navigation
Validate EmbeddedRocksDB setting values before persisting metadata - #103417
alexey-milovidov merged 6 commits into
Conversation
`ALTER TABLE ... ENGINE = EmbeddedRocksDB MODIFY SETTING` with an invalid value (e.g. a non-boolean string for a `Bool` setting) was being persisted to the table metadata on disk before the value was validated. The validation happens afterwards in `StorageEmbeddedRocksDB::alter` when `applyChanges` is called on a fresh `RocksDBSettings` object, but the corruption is already on disk. On the next server restart the bad metadata cannot be parsed and the table fails to attach with `CANNOT_PARSE_BOOL` (or similar errors such as `Field value ... is out of range of long type`). In an `Atomic` database this affects only the failing table, but for databases where load failures are fatal it prevents the server from starting altogether. Master stress test `serverfuzz amd_msan` hit exactly this on a BuzzHouse-generated workload (https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=ad5ffb299775af545f5b7d3ccc5239feb08ed25a&name_0=MasterCI&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20amd_msan%29). Move the validation into `StorageEmbeddedRocksDB::checkAlterIsPossible` via `RocksDBSettings::checkCanSet`, so invalid setting values are rejected before `IStorage::alter` writes anything to disk. Follows the same pattern as `MergeTreeData::checkAlterIsPossible` which calls `MergeTreeSettings::checkCanSet`. Adds `tests/queries/0_stateless/04111_rocksdb_alter_setting_validation.sql` which verifies that a failed `MODIFY SETTING` leaves the table metadata unchanged and that subsequent valid alters continue to work. Related: ClickHouse#88443
|
cc @GrigoryPervakov @rschu1ze — could you review this? |
|
Pre-PR validation gate (session a) Deterministic repro? Yes. b) Root cause explained? c) Fix matches root cause? Yes — move the value validation to d) Test intent preserved? / New tests added? Existing RocksDB tests ( e) Both directions demonstrated? Yes. Before fix: reproduction confirmed the stale metadata path. After fix: metadata is unchanged after failed ALTER, new test passes 20/20 runs with randomization enabled, existing tests still green. f) Fix is general, not a narrow patch? Yes — |
|
Workflow [PR], commit [2c595e1] Summary: ✅
AI ReviewSummaryThis PR validates Final VerdictStatus: ✅ Approve |
…lidation Per reviewer feedback on PR ClickHouse#103417 (inline review on the test file at commit 235ae89 by clickhouse-gh[bot]), extend the regression test to cover `UInt64` setting validation in addition to the `Bool` cases. Two new assertions on `bulk_insert_block_size`: 1. `bulk_insert_block_size = 'not-a-number'` — non-numeric string, expected `CANNOT_PARSE_INPUT_ASSERTION_FAILED`. 2. `bulk_insert_block_size = -5` — negative value, expected `CANNOT_CONVERT_TYPE`. This directly reproduces the failure mode from issue ClickHouse#88443 ("Field value ... is out of range of ... type"), which was the motivating case for this PR. Each failing `ALTER` is followed by a `SELECT create_table_query` assertion to prove that the on-disk metadata is unchanged. Without the `RocksDBSettings::checkCanSet` call added in the preceding commit, the persisted metadata would be corrupted the same way as for the `Bool` cases, causing `ATTACH TABLE` to fail on the next server restart. Verified locally: 20/20 passes with randomized settings.
|
Thanks for the review. Added UInt64 invalid-value assertions in commit 41a323d. Two new cases on
Each failing Verified locally: 20/20 passes with randomized settings. Session: cron:clickhouse-ci-task-worker:20260423-051500 |
Collapse the 6-line rationale for pre-validation into a concise 2-line comment that still references issue ClickHouse#88443. Per review by @evillique on PR ClickHouse#103417.
…etting-validation-20260423
|
Merged master ( PR code itself is unchanged by the merge — the 3 original commits (fix + UInt64 tests + shortened comment) are preserved as-is. cc @evillique — would you mind re-approving once CI goes green? Approval went stale after the push. |
|
Dear @evillique, 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. |
|
@groeneai Investigate the CI failure and link to the PR that fixes it (if there is one) |
…-setting-validation-20260423
|
@evillique The only failing job on the previous HEAD (
This was a chronic trunk bug, not caused by this PR (CIDB: 13 PRs / 36 hits over 90 days, 0 master hits, the JOIN code path is unrelated to the ALTER-setting validation here). It is already fixed by merged PR #103928 ("Fix LOGICAL_ERROR The branch was 6 weeks behind master, so CI was still running the stale failing build. I have merged current master ( |
|
@evillique investigated — the failing check is
This is unrelated to this PR (which only touches The test deliberately injects unreliable S3 SDK behaviour (broken-pipe / retry simulation), so it is timing-sensitive and flakes under ASan + ThreadFuzzer load. There is no open issue or dedicated fix PR for it yet — it is endemic infra noise rather than a regression. It clears on rerun. The PR itself is green apart from this flake. Could you re-approve / merge when convenient? Approval was already given; only the flaky integration shard is red. |
|
@groeneai As per our policy, we unfortunately can't merge the PRs with any red checks on them. Could you please fix the test in question in a separate PR? |
|
@evillique Done. Opened a separate PR to fix the red Root cause was two-fold: the INSERT ran through the async queue (async_insert defaults to true) so a background flush kept retry-storming the always-failing S3 proxy and raced the cleanup DROP; and the disk's bare Once #106400 merges this check should go green. Could you re-approve/merge this PR after that? |
…-setting-validation-20260423
|
@evillique Done. Merged latest master into the branch (new HEAD |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 7/8 (87.50%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 5 line(s) · Uncovered code |
|
CI is now fully finished and green on HEAD CI ledger for
@evillique the master-merge push invalidated your prior approval. Could you re-approve and merge? All checks apart from the non-blocking Session: cron:our-pr-ci-monitor:20260603-230000 |
Refresh the branch (was 440 commits behind). This pulls in #103417 (`Validate EmbeddedRocksDB setting values before persisting metadata`), which fixes the sole CI red on the previous run: `Stress test (amd_tsan)` failed with `Cannot start clickhouse-server` because a fuzzed `ALTER TABLE rocksdb_worm MODIFY SETTING optimize_for_bulk_insert = NULL` (from `02956_rocksdb_bulk_sink`) persisted an invalid `Bool` value to the metadata, so the table could not be re-attached on restart (`Invalid value NULL of the setting, which needs bool`, CANNOT_CONVERT_TYPE). That failure is master-side and unrelated to this test-only PR; the fix is absent from the old merge-base and is brought in by this merge. The diff stays test-only (`03518_alter_logical_race.{sh,reference}`).
ALTER TABLE ... ENGINE = EmbeddedRocksDB MODIFY SETTINGwith an invalid value (e.g. a non-boolean string for aBoolsetting) was being persisted to the table metadata on disk before the value was validated. The validation happens afterwards inStorageEmbeddedRocksDB::alterwhenapplyChangesis called on a freshRocksDBSettingsobject, but the corruption is already on disk.On the next server restart the bad metadata cannot be parsed and the table fails to attach with
CANNOT_PARSE_BOOL(or similar errors such asField value ... is out of range of long type). In anAtomicdatabase only the failing table is lost, but for databases where load failures are fatal it prevents the server from starting altogether. Master stress testserverfuzz amd_msanhit exactly this on a BuzzHouse-generated workload.Reproduction (without this change):
Fix: Move the validation into
StorageEmbeddedRocksDB::checkAlterIsPossiblevia a newRocksDBSettings::checkCanSethelper, so invalid setting values are rejected beforeIStorage::alterwrites anything to disk. Follows the same pattern asMergeTreeData::checkAlterIsPossiblewhich callsMergeTreeSettings::checkCanSet. After the fix the failedALTERleaves the table metadata unchanged and the table is still usable on restart.Adds
tests/queries/0_stateless/04111_rocksdb_alter_setting_validation.sqlwhich covers the above scenario plus validMODIFY SETTING,RESET SETTING, and invalidUInt64values.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=ad5ffb299775af545f5b7d3ccc5239feb08ed25a&name_0=MasterCI&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20amd_msan%29
Related: #88443 (same class of bug reported a year earlier with a different setting:
zstd_window_log_max = 18446744073709551516gets persisted when the server rejects another setting in the same ALTER).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a bug where
ALTER TABLE ... MODIFY SETTINGon anEmbeddedRocksDBtable could persist an invalid setting value to the table metadata file even when the server rejected the query. On the next server restart the table would fail to attach withCANNOT_PARSE_BOOL(or a similar parsing error), and in databases where load failures are fatal the server would refuse to start. Invalid setting values are now rejected before any metadata is written.Documentation entry for user-facing changes
Version info
26.6.1.901