Skip to content

KAFKA-19301: Move and rewrite partition state classes to Java in org.apache.kafka.storage.internals.log #20083

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

Open
wants to merge 31 commits into
base: trunk
Choose a base branch
from

Conversation

joshua2519
Copy link
Contributor

@joshua2519 joshua2519 commented Jul 2, 2025

move following interface/class to
org.apache.kafka.storage.internals.log and rewrtie to java

PartitionListener‎ AlterPartitionListener AssignmentState
OngoingReassignmentState SimpleAssignmentState PartitionState
PendingPartitionChange PendingExpandIsr PendingShrinkIsr
CommittedPartitionState

@github-actions github-actions bot added triage PRs from the community core Kafka Broker performance storage Pull requests that target the storage module KIP-932 Queues for Kafka labels Jul 2, 2025
@joshua2519 joshua2519 changed the title MINOR: Move and rewrite partition state classes to Java in org.apache.kafka.storage.internals.log KAFKA-19301: Move and rewrite partition state classes to Java in org.apache.kafka.storage.internals.log Jul 2, 2025
Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshua2519 thanks for this patch.

Copy link
Contributor

@frankvicky frankvicky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshua2519: Thanks for the patch.

@github-actions github-actions bot added tiered-storage Related to the Tiered Storage feature clients group-coordinator and removed triage PRs from the community labels Jul 4, 2025
@joshua2519 joshua2519 force-pushed the move-partial-Partition-scala-to-storage-internals-log branch from 197889a to 238ed5f Compare July 4, 2025 05:06
Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshua2519 Thanks for this patch. The migration introduces some extra overhead in deep copying. Please try to eliminate the copying as much as possible.

@@ -1949,9 +1799,9 @@ class Partition(val topicPartition: TopicPartition,
// 2) leaderAndIsr.partitionEpoch == partitionEpoch: No update was performed since proposed and actual state are the same.
// In both cases, we want to move from Pending to Committed state to ensure new updates are processed.

partitionState = CommittedPartitionState(leaderAndIsr.isr.asScala.map(_.toInt).toSet, leaderAndIsr.leaderRecoveryState)
partitionState = new CommittedPartitionState(util.Set.copyOf(leaderAndIsr.isr), leaderAndIsr.leaderRecoveryState)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change leaderAndIsr.isr to return immutable set?

Copy link
Contributor Author

@joshua2519 joshua2519 Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change leaderAndIsr.isr to return immutable set?

Thanks for that.
I changed it to immutable set and patched related test.

@@ -1298,7 +1148,7 @@ class Partition(val topicPartition: TopicPartition,
def getOutOfSyncReplicas(maxLagMs: Long): Set[Int] = {
val current = partitionState
if (!current.isInflight) {
val candidateReplicaIds = current.isr - localBrokerId
val candidateReplicaIds = current.isr.asScala.map(_.toInt).toSet - localBrokerId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@chia7712
To reduce collection copies, we could use an iterator like this:
current.isr.asScala.iterator.map(_.toInt).filter(_ != localBrokerId)).to(Set)
However, this approach is less concise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

current.isr.stream().filter(isr => isr != localBrokerId).collect(Collectors.toUnmodifiableSet).asScala

@@ -1098,7 +948,7 @@ class Partition(val topicPartition: TopicPartition,
case (brokerId, logEndOffset) => s"broker $brokerId: $logEndOffset"
}

val curInSyncReplicaObjects = (curMaximalIsr - localBrokerId).flatMap(getReplica)
val curInSyncReplicaObjects = (curMaximalIsr.asScala.map(_.toInt) - localBrokerId).flatMap(getReplica)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

@joshua2519 joshua2519 Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #20083 (comment)

curMaximalIsr.asScala.iterator.filter(_.intValue() != localBrokerId).map(_.toInt).flatMap(getReplica).to(Set)

@github-actions github-actions bot added the kraft label Jul 8, 2025
Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshua2519 thanks for updates. some comments are left. PTAL

* This set may include un-committed ISR members following an expansion. This "effective" ISR is used for advancing
* the high watermark as well as determining which replicas are required for acks=all produce requests.
*
* Only applicable as of IBP 2.7-IV2, for older versions this will return the committed ISR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is out-of-date, shouldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the minimum versions is 3.3-IV3 now.
I removed this part.

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshua2519 thanks for your patch. it is almost there. two small comments left.

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshua2519 thanks for your patch. overall LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-approved clients core Kafka Broker group-coordinator KIP-932 Queues for Kafka kraft performance storage Pull requests that target the storage module tiered-storage Related to the Tiered Storage feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants