KAFKA-16517 Do not decode metadata records in the internal kraft partition listener#22805
Open
0xffff-zhiyan wants to merge 2 commits into
Open
KAFKA-16517 Do not decode metadata records in the internal kraft partition listener#228050xffff-zhiyan wants to merge 2 commits into
0xffff-zhiyan wants to merge 2 commits into
Conversation
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.
Summary
The internal kraft partition listener
KRaftControlRecordStateMachineonly tracks control records. When it reads the log and the snapshot it also decodes every data record through RecordsIterator, allocating a buffer and running the serde for each record even though the decoded records are never used. This change lets the listener skip decoding data records on both its log and snapshot read paths.Changes
Introduce
DecodingStrategyto decide which recordsRecordsIteratordecodes. It has three implementations:ControlAndDataDecodingStrategydecodes both control and data records and preserves the existing behavior.ControlOnlyDecodingStrategydecodes only the control records and skips the data records, and needs no serde.DataOnlyDecodingStrategydecodes only the data records and skips the control records, added for completeness with no caller yet.RecordsIteratornow takes aDecodingStrategyinstead of aRecordSerde, and the shared record and batch decoding logic is moved into static helpers onDecodingStrategy.RecordsSnapshotReader.ofalso takes aDecodingStrategyinstead of aRecordSerdeso each snapshot reader can choose. Callers that consume data records passControlAndDataDecodingStrategy.Batch.notDecodedwhich builds a batch that carries only the offset information for records that were skipped.KRaftControlRecordStateMachineusesControlOnlyDecodingStrategyfor both its log and snapshot reads, so its serde field and constructor parameter are removed.Testing
Existing
RecordsIteratorTest, KRaftControlRecordStateMachineTest, snapshot reader tests, KafkaRaftClientReconfigTest, RaftEventSimulationTest, RaftClusterSnapshotTest, DynamicBrokerConfigTest and QuorumControllerTestpass with the change.