-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-16207; KRaft's internal log listener to update voter set #15671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
dd84479
KAFKA-16207; Add KRaftVersionRecord and VotersRecord
jsancio 87a43c6
Some observation while reviewing the KIP and implementation
jsancio c9de8a1
Fix compilation errors
jsancio 54b164e
KAFKA-16207; Match KIP schema
jsancio 04fcf4c
KAFKA-16207; Implement VoterSet and VoterSetHistory
jsancio 702e739
KAFKA-16207; Add impl for internal log listener
jsancio fae8b84
KAFKA-16207; Add historical kraft version
jsancio 25d9dfd
KAFKA-16207; Import refactor to delay voter address evaluation
jsancio b3e65bd
Merge remote-tracking branch 'upstream/trunk' into kafka-16207-intern…
jsancio 9a6b4c2
KAFKA-16207; Fix core and metadata after raft changes
jsancio 24661b1
KAFKA-16207; More voter parsing clean ups
jsancio cd3277c
KAFKA-16207; User the voter set from the config or log
jsancio f3a0fcd
KAFKA-16207; Return node id before calling initialize
jsancio 08e1831
KAFKA-16207; Add a builder for record snaapshot writer
jsancio 89ac698
KAFKA-16207; Include kraft.version and voter set in the snapshots
jsancio 2889b42
KAFKA-16207; Use SupportedVersionRange
jsancio 1188b94
KAFKA-16207; Fix version range documentation
jsancio 92909fb
KAFKA-16207; Snapshots should return control records
jsancio dd28ef4
KAFKA-16207; Document internal listener invariant
jsancio deb7920
KAFKA-16207; Update some of the documentation
jsancio 0db1a06
KAFKA-16207; Fix cluster snapshot test
jsancio ab1886a
KAFKA-16207; Implement truncating and prefix trimming the internal li…
jsancio a962188
KAFKA-16207; Finish documenting all of the type and methods
jsancio 1829e06
KAFKA-16207; Implement some of the unittest
jsancio a108e9c
KAFKA-16207; Add 2 more test suites
jsancio 795858f
KAFKA-16207; Make the control batch buffer configurable
jsancio a79660e
KAFKA-16207; Add tests for snapshot builder
jsancio 625aabd
KAFKA-16207; Add test for internal partition listener
jsancio 855a13e
Merge remote-tracking branch 'upstream/trunk' into kafka-16207-intern…
jsancio 629c7da
Merge remote-tracking branch 'upstream/trunk' into kafka-16207-intern…
jsancio bc26f59
Merge remote-tracking branch 'upstream/trunk' into kafka-16207-intern…
jsancio b6fc7f6
KAFKA-16207; Use directory id instead of uuid
jsancio 742c969
Merge remote-tracking branch 'upstream/trunk' into kafka-16207-intern…
jsancio e55564d
KAFKA-16207; Many fixes and improvements
jsancio de19062
KAFKA-16207; Rename PartitionListener
jsancio 66c3793
Merge remote-tracking branch 'upstream/trunk' into kafka-16207-intern…
jsancio c821a83
KAFKA-16207; Review feedback changes
jsancio c2a7a9a
KAFKA-16207; Better validate the control records in the accumulator
jsancio d1c17e0
Merge remote-tracking branch 'upstream/trunk' into kafka-16207-intern…
jsancio bc80295
KAFKA-16207; Minor fix
jsancio c363bf1
KAFKA-16207; kraft version default of 1 for tests
jsancio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,11 @@ | |
|
|
||
| import org.apache.kafka.common.TopicPartition; | ||
| import org.apache.kafka.common.errors.CorruptRecordException; | ||
| import org.apache.kafka.common.message.KRaftVersionRecord; | ||
| import org.apache.kafka.common.message.LeaderChangeMessage; | ||
| import org.apache.kafka.common.message.SnapshotHeaderRecord; | ||
| import org.apache.kafka.common.message.SnapshotFooterRecord; | ||
| import org.apache.kafka.common.message.SnapshotHeaderRecord; | ||
| import org.apache.kafka.common.message.VotersRecord; | ||
| import org.apache.kafka.common.network.TransferableChannel; | ||
| import org.apache.kafka.common.record.MemoryRecords.RecordFilter.BatchRetention; | ||
| import org.apache.kafka.common.record.MemoryRecords.RecordFilter.BatchRetentionResult; | ||
|
|
@@ -154,7 +156,7 @@ public FilterResult filterTo(TopicPartition partition, RecordFilter filter, Byte | |
|
|
||
| /** | ||
| * Note: This method is also used to convert the first timestamp of the batch (which is usually the timestamp of the first record) | ||
| * to the delete horizon of the tombstones or txn markers which are present in the batch. | ||
| * to the delete horizon of the tombstones or txn markers which are present in the batch. | ||
| */ | ||
| private static FilterResult filterTo(TopicPartition partition, Iterable<MutableRecordBatch> batches, | ||
| RecordFilter filter, ByteBuffer destinationBuffer, int maxRecordBatchSize, | ||
|
|
@@ -728,83 +730,114 @@ public static MemoryRecords withLeaderChangeMessage( | |
| ByteBuffer buffer, | ||
| LeaderChangeMessage leaderChangeMessage | ||
| ) { | ||
| writeLeaderChangeMessage(buffer, initialOffset, timestamp, leaderEpoch, leaderChangeMessage); | ||
| buffer.flip(); | ||
| return MemoryRecords.readableRecords(buffer); | ||
| try (MemoryRecordsBuilder builder = createKraftControlReccordBuilder( | ||
| initialOffset, | ||
| timestamp, | ||
| leaderEpoch, | ||
| buffer | ||
| ) | ||
| ) { | ||
| builder.appendLeaderChangeMessage(timestamp, leaderChangeMessage); | ||
| return builder.build(); | ||
| } | ||
| } | ||
|
|
||
| private static void writeLeaderChangeMessage( | ||
| ByteBuffer buffer, | ||
| public static MemoryRecords withSnapshotHeaderRecord( | ||
| long initialOffset, | ||
| long timestamp, | ||
| int leaderEpoch, | ||
| LeaderChangeMessage leaderChangeMessage | ||
| ByteBuffer buffer, | ||
| SnapshotHeaderRecord snapshotHeaderRecord | ||
| ) { | ||
| try (MemoryRecordsBuilder builder = new MemoryRecordsBuilder( | ||
| buffer, RecordBatch.CURRENT_MAGIC_VALUE, CompressionType.NONE, | ||
| TimestampType.CREATE_TIME, initialOffset, timestamp, | ||
| RecordBatch.NO_PRODUCER_ID, RecordBatch.NO_PRODUCER_EPOCH, RecordBatch.NO_SEQUENCE, | ||
| false, true, leaderEpoch, buffer.capacity()) | ||
| try (MemoryRecordsBuilder builder = createKraftControlReccordBuilder( | ||
| initialOffset, | ||
| timestamp, | ||
| leaderEpoch, | ||
| buffer | ||
| ) | ||
| ) { | ||
| builder.appendLeaderChangeMessage(timestamp, leaderChangeMessage); | ||
| builder.appendSnapshotHeaderMessage(timestamp, snapshotHeaderRecord); | ||
| return builder.build(); | ||
| } | ||
| } | ||
|
|
||
| public static MemoryRecords withSnapshotHeaderRecord( | ||
| public static MemoryRecords withSnapshotFooterRecord( | ||
| long initialOffset, | ||
| long timestamp, | ||
| int leaderEpoch, | ||
| ByteBuffer buffer, | ||
| SnapshotHeaderRecord snapshotHeaderRecord | ||
| SnapshotFooterRecord snapshotFooterRecord | ||
| ) { | ||
| writeSnapshotHeaderRecord(buffer, initialOffset, timestamp, leaderEpoch, snapshotHeaderRecord); | ||
| buffer.flip(); | ||
| return MemoryRecords.readableRecords(buffer); | ||
| try (MemoryRecordsBuilder builder = createKraftControlReccordBuilder( | ||
| initialOffset, | ||
| timestamp, | ||
| leaderEpoch, | ||
| buffer | ||
| ) | ||
| ) { | ||
| builder.appendSnapshotFooterMessage(timestamp, snapshotFooterRecord); | ||
| return builder.build(); | ||
| } | ||
| } | ||
|
|
||
| private static void writeSnapshotHeaderRecord( | ||
| ByteBuffer buffer, | ||
| public static MemoryRecords withKRaftVersionRecord( | ||
| long initialOffset, | ||
| long timestamp, | ||
| int leaderEpoch, | ||
| SnapshotHeaderRecord snapshotHeaderRecord | ||
| ByteBuffer buffer, | ||
| KRaftVersionRecord kraftVersionRecord | ||
| ) { | ||
| try (MemoryRecordsBuilder builder = new MemoryRecordsBuilder( | ||
| buffer, RecordBatch.CURRENT_MAGIC_VALUE, CompressionType.NONE, | ||
| TimestampType.CREATE_TIME, initialOffset, timestamp, | ||
| RecordBatch.NO_PRODUCER_ID, RecordBatch.NO_PRODUCER_EPOCH, RecordBatch.NO_SEQUENCE, | ||
| false, true, leaderEpoch, buffer.capacity()) | ||
| try (MemoryRecordsBuilder builder = createKraftControlReccordBuilder( | ||
| initialOffset, | ||
| timestamp, | ||
| leaderEpoch, | ||
| buffer | ||
| ) | ||
| ) { | ||
| builder.appendSnapshotHeaderMessage(timestamp, snapshotHeaderRecord); | ||
| builder.appendKRaftVersionMessage(timestamp, kraftVersionRecord); | ||
| return builder.build(); | ||
| } | ||
| } | ||
|
|
||
| public static MemoryRecords withSnapshotFooterRecord( | ||
| public static MemoryRecords withVotersRecord( | ||
| long initialOffset, | ||
| long timestamp, | ||
| int leaderEpoch, | ||
| ByteBuffer buffer, | ||
| SnapshotFooterRecord snapshotFooterRecord | ||
| VotersRecord votersRecord | ||
| ) { | ||
| writeSnapshotFooterRecord(buffer, initialOffset, timestamp, leaderEpoch, snapshotFooterRecord); | ||
| buffer.flip(); | ||
| return MemoryRecords.readableRecords(buffer); | ||
| try (MemoryRecordsBuilder builder = createKraftControlReccordBuilder( | ||
| initialOffset, | ||
| timestamp, | ||
| leaderEpoch, | ||
| buffer | ||
| ) | ||
| ) { | ||
| builder.appendVotersMessage(timestamp, votersRecord); | ||
| return builder.build(); | ||
| } | ||
| } | ||
|
|
||
| private static void writeSnapshotFooterRecord( | ||
| ByteBuffer buffer, | ||
| private static MemoryRecordsBuilder createKraftControlReccordBuilder( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo Reccord
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I submitted this #15912 as a followup to these comments. |
||
| long initialOffset, | ||
| long timestamp, | ||
| int leaderEpoch, | ||
| SnapshotFooterRecord snapshotFooterRecord | ||
| ByteBuffer buffer | ||
| ) { | ||
| try (MemoryRecordsBuilder builder = new MemoryRecordsBuilder( | ||
| buffer, RecordBatch.CURRENT_MAGIC_VALUE, CompressionType.NONE, | ||
| TimestampType.CREATE_TIME, initialOffset, timestamp, | ||
| RecordBatch.NO_PRODUCER_ID, RecordBatch.NO_PRODUCER_EPOCH, RecordBatch.NO_SEQUENCE, | ||
| false, true, leaderEpoch, buffer.capacity()) | ||
| ) { | ||
| builder.appendSnapshotFooterMessage(timestamp, snapshotFooterRecord); | ||
| } | ||
| return new MemoryRecordsBuilder( | ||
| buffer, | ||
| RecordBatch.CURRENT_MAGIC_VALUE, | ||
| CompressionType.NONE, | ||
| TimestampType.CREATE_TIME, | ||
| initialOffset, | ||
| timestamp, | ||
| RecordBatch.NO_PRODUCER_ID, | ||
| RecordBatch.NO_PRODUCER_EPOCH, | ||
| RecordBatch.NO_SEQUENCE, | ||
| false, | ||
| true, | ||
| leaderEpoch, | ||
| buffer.capacity() | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it a bug that we only allowed version 1 and above? I'm wondering if we really need to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I think this was missed during the original implementation. The default value for any feature version is 0 but that cannot be expressed in the range of supported versions since it doesn't allow 0 as the min or max value.