KAFKA-21034: Wipe the global state directory when the store is corrupted - #23390
Open
sunm2n wants to merge 1 commit into
Open
KAFKA-21034: Wipe the global state directory when the store is corrupted#23390sunm2n wants to merge 1 commit into
sunm2n wants to merge 1 commit into
Conversation
GlobalStreamThread#initialize already wipes the global state directory when stateConsumer.initialize() throws InvalidOffsetException, but a corrupted state store is not handled the same way. RocksDBStore#openDB wraps the ProcessorStateException into a TaskCorruptedException, which is a sibling of ProcessorStateException rather than a subclass, so it falls through to the generic StreamsException handler and the directory is left on disk. Every restart then hits the same corrupted state, which turns into a crash loop under an automatic restart policy. This adds a TaskCorruptedException branch that closes the state consumer with wipeStateStore=true, so the next start rebuilds the store from the changelog. The new test fails without this change: the assertion reports the global directory still exists. verified with `./gradlew streams:test --tests GlobalStreamThreadTest`
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.
GlobalStreamThread#initialize already wipes the global state directory when stateConsumer.initialize() throws InvalidOffsetException, but a corrupted state store is not handled the same way.
RocksDBStore#openDB wraps the ProcessorStateException into a TaskCorruptedException, which is a sibling of ProcessorStateException rather than a subclass. It therefore falls through to the generic catch (StreamsException) in GlobalStreamThread#initialize, which calls closeStateConsumer(stateConsumer, false), and the corrupted directory is left on disk. Every restart hits the same state, which becomes a crash loop under an automatic restart policy such as a Kubernetes StatefulSet.
This adds a TaskCorruptedException branch that closes the state consumer with wipeStateStore=true, so the next start rebuilds the global store from the changelog. GlobalStateUpdateTask#close already logs "Deleting global task directory after detecting corruption" on that path, so the deletion itself was already implemented — it was just never reached for this exception.
Does this need a KIP?
I do not think so, but I would like this confirmed. The wipe on the InvalidOffsetException path was introduced in KAFKA-10306 (2020) and the wipeStateStore flag in KAFKA-8897 (2021), both without a KIP. This change makes a corrupted store follow the same existing path rather than introducing new behaviour, and it adds no new config or public API. If that reasoning is wrong, please let me know and I will open a KIP instead.
Verification