Skip to content

Commit cf7b4a9

Browse files
authored
MINOR: Improve documentation to clarify preferred replica (#20890)
Improve documentation to clarify preferred replica Reviewers: Chia-Ping Tsai <[email protected]>
1 parent ea8babe commit cf7b4a9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

clients/src/main/java/org/apache/kafka/common/PartitionInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public Node leader() {
7070
}
7171

7272
/**
73-
* The complete set of replicas for this partition regardless of whether they are alive or up-to-date
73+
* The complete set of replicas for this partition regardless of whether they are alive or up-to-date. The preferred replica
74+
* is the head of the list.
7475
*/
7576
public Node[] replicas() {
7677
return replicas;

core/src/test/scala/unit/kafka/server/MetadataRequestTest.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,22 @@ class MetadataRequestTest extends AbstractMetadataRequestTest {
204204
}
205205
}
206206

207+
@Test
208+
def testPartitionInfoPreferredReplica(): Unit = {
209+
val replicaAssignment = Map(0 -> Seq(1, 2, 0))
210+
val topic = "testPartitionInfoPreferredReplicaTopic"
211+
createTopicWithAssignment(topic, replicaAssignment)
212+
213+
val response = sendMetadataRequest(new MetadataRequest.Builder(Seq(topic).asJava, true).build())
214+
val cluster = response.buildCluster()
215+
val partitionInfos = cluster.partitionsForTopic(topic).asScala
216+
assertEquals(1, partitionInfos.size)
217+
218+
val partitionInfo = partitionInfos.head
219+
val preferredReplicaId = replicaAssignment(partitionInfo.partition()).head
220+
assertEquals(preferredReplicaId, partitionInfo.replicas().head.id())
221+
}
222+
207223
@Test
208224
def testReplicaDownResponse(): Unit = {
209225
val replicaDownTopic = "replicaDown"

0 commit comments

Comments
 (0)