persist: don't crash on undecodable rollup during usage scan#37017
Draft
DAlperin wants to merge 1 commit into
Draft
persist: don't crash on undecodable rollup during usage scan#37017DAlperin wants to merge 1 commit into
DAlperin wants to merge 1 commit into
Conversation
The periodic storage-usage collection (`storage_usage_fetch` ->
`shards_usage_referenced`) scans every live shard and decodes its
rollups. Rollup decoding `expect`s the encoded state to be valid, so a
single corrupt/undecodable rollup in any one shard panicked the task,
which the abort-on-panic handler turned into a full process crash (e.g.
`invalid encoded state: DecodeError { description: InvalidKey { .. } }`).
This is a best-effort billing scan, so a bad shard should be skipped,
not bring down the environment. Catch panics per shard, log the error,
bump a new `mz_persist_usage_referenced_shard_failures` counter, and
report that shard as zero usage while the rest are computed normally.
Generated with [Linear](https://linear.app/materializeinc/issue/PER-23/thread-tokiowork-9-panicked-at-srcpersist#agent-session-c16c7454)
Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The periodic storage-usage collection (
storage_usage_fetch→StorageUsageClient::shards_usage_referenced) scans every live shard and decodes its rollups for billing. Rollup decodingexpects the encoded state to be valid, so a single corrupt/undecodable rollup in any one shard panics the task — and since the scan runs in a spawned task under the abort-on-panic handler, that becomes a full process crash:This is a best-effort billing scan that touches every shard in the environment, so one bad shard should not be able to take down the whole process.
Description
Catch panics per shard inside
shards_usage_referencedviaore_catch_unwind. On a panic we log the error, bump a newmz_persist_usage_referenced_shard_failurescounter, and report that shard as zero usage while the remaining shards are computed normally. The "fail loudly" behavior on the actual data path is unchanged — only this periodic best-effort scan is made resilient.Verification
New test
usage_referenced_undecodable_rollupwrites a shard, overwrites its rollup blob(s) with undecodable bytes, and asserts thatshards_usage_referencedreturns cleanly (reporting the shard as 0 bytes) and increments the failure counter, rather than panicking.