showuon commented on code in PR #24034:
URL: https://github.com/apache/kafka/pull/24034#discussion_r4536924756
##########
server-common/src/main/java/org/apache/kafka/server/common/MetadataVersion.java:
##########
@@ -269,7 +279,10 @@ public short shareGroupStateRequestHeaderVersion() {
}
public short partitionChangeRecordVersion() {
- if (isElrSupported()) {
+ if (isClusterMirrorSupported()) {
+ // new leaderEpoch field
Review Comment:
This is not needed.
##########
metadata/src/test/java/org/apache/kafka/metadata/PartitionRegistrationTest.java:
##########
@@ -113,6 +117,72 @@ public void
testMergePartitionChangeRecordWithReassignmentData() {
setIsr(new int[] {1, 2,
4}).setLeader(1).setLeaderRecoveryState(LeaderRecoveryState.RECOVERED).setLeaderEpoch(100).setPartitionEpoch(202).build(),
partition2);
}
+ private static PartitionRegistration leaderEpochTestPartition() {
+ return new PartitionRegistration.Builder().setReplicas(new int[] {1,
2, 3}).
+ setDirectories(DirectoryId.migratingArray(3)).
+ setIsr(new int[] {1, 2,
3}).setLeader(1).setLeaderRecoveryState(LeaderRecoveryState.RECOVERED).
+ setLeaderEpoch(100).setPartitionEpoch(200).build();
+ }
+
+ @Test
+ public void testMergeDerivesLeaderEpochWhenRecordDoesNotSetIt() {
+ PartitionRegistration partition = leaderEpochTestPartition();
+
+ PartitionRegistration leaderChanged = partition.merge(new
PartitionChangeRecord().setLeader(2));
+ assertEquals(2, leaderChanged.leader);
+ assertEquals(101, leaderChanged.leaderEpoch);
+
+ PartitionRegistration leaderUnchanged = partition.merge(new
PartitionChangeRecord().setIsr(List.of(1, 2)));
+ assertEquals(1, leaderUnchanged.leader);
+ assertEquals(100, leaderUnchanged.leaderEpoch);
+ }
+
+ @Test
+ public void testMergeUsesLeaderEpochFromRecord() {
+ PartitionRegistration partition = leaderEpochTestPartition();
+
+ PartitionRegistration merged = partition.merge(new
PartitionChangeRecord().setLeader(2).setLeaderEpoch(150));
+ assertEquals(2, merged.leader);
+ assertEquals(150, merged.leaderEpoch);
+ assertEquals(201, merged.partitionEpoch);
+ }
+
+ @Test
+ public void testMergeLeaderEpochChangeWithoutLeaderChange() {
+ PartitionRegistration partition = leaderEpochTestPartition();
+
+ PartitionRegistration merged = partition.merge(new
PartitionChangeRecord().setLeaderEpoch(101));
+ assertEquals(1, merged.leader);
+ assertEquals(101, merged.leaderEpoch);
+ assertEquals(201, merged.partitionEpoch);
+ }
+
+ @Test
+ public void testPartitionChangeRecordLeaderEpochVersioning() {
+ PartitionChangeRecord withEpoch = new PartitionChangeRecord().
+
setTopicId(Uuid.fromString("FbRuu7CeQtq5YFreEzg16g")).setLeader(2).setLeaderEpoch(101);
+
+ // Version 3 carries the leader epoch.
+ assertEquals(101, roundTrip(withEpoch, (short) 3).leaderEpoch());
+
+ // Older versions cannot carry the leader epoch, so the controller
must not set it.
+ assertThrows(UnsupportedVersionException.class, () ->
roundTrip(withEpoch, (short) 2));
+
+ // A version 2 record read by a newer node has no leader epoch, so it
is derived from the leader change.
+ PartitionChangeRecord withoutEpoch = roundTrip(new
PartitionChangeRecord().
+ setTopicId(withEpoch.topicId()).setLeader(2), (short) 2);
+ assertEquals(-1, withoutEpoch.leaderEpoch());
+ assertEquals(101,
leaderEpochTestPartition().merge(withoutEpoch).leaderEpoch);
+ }
Review Comment:
Could we also add a test case to test that using version 2, with leader -2,
we can still keep the same leader without leader epoch bump. Also, one more
test case to make sure it can accept leader -1 with leader epoch bump.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]