-
Notifications
You must be signed in to change notification settings - Fork 15.1k
MINOR: avoid unnecessary collection copies between java and scala in metadata cache #6397
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,9 +51,10 @@ class MetadataCache(brokerId: Int) extends Logging { | |
| private val stateChangeLogger = new StateChangeLogger(brokerId, inControllerContext = false, None) | ||
|
|
||
| // This method is the main hotspot when it comes to the performance of metadata requests, | ||
| // we should be careful about adding additional logic here. | ||
| // we should be careful about adding additional logic here. Relatedly, `brokers` is | ||
| // `Iterable[Integer]` instead of `Iterable[Int]` to avoid a collection copy. | ||
| // filterUnavailableEndpoints exists to support v0 MetadataResponses | ||
| private def getEndpoints(snapshot: MetadataSnapshot, brokers: Iterable[Int], listenerName: ListenerName, filterUnavailableEndpoints: Boolean): Seq[Node] = { | ||
| private def getEndpoints(snapshot: MetadataSnapshot, brokers: Iterable[java.lang.Integer], listenerName: ListenerName, filterUnavailableEndpoints: Boolean): Seq[Node] = { | ||
| val result = new mutable.ArrayBuffer[Node](math.min(snapshot.aliveBrokers.size, brokers.size)) | ||
| brokers.foreach { brokerId => | ||
| val endpoint = getAliveEndpoint(snapshot, brokerId, listenerName) match { | ||
|
|
@@ -76,9 +77,9 @@ class MetadataCache(brokerId: Int) extends Logging { | |
| val leaderBrokerId = partitionState.basePartitionState.leader | ||
| val leaderEpoch = partitionState.basePartitionState.leaderEpoch | ||
| val maybeLeader = getAliveEndpoint(snapshot, leaderBrokerId, listenerName) | ||
| val replicas = partitionState.basePartitionState.replicas.asScala.map(_.toInt) | ||
| val replicas = partitionState.basePartitionState.replicas.asScala | ||
|
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. basically, these fields are all originally
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. actually, nm - these aren't copying conversions except for the type conversion which your patch eliminates. So I think we are good.
Member
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. Yeah, none of the converters do copying. It's just unfortunate that there's no way to have |
||
| val replicaInfo = getEndpoints(snapshot, replicas, listenerName, errorUnavailableEndpoints) | ||
| val offlineReplicaInfo = getEndpoints(snapshot, partitionState.offlineReplicas.asScala.map(_.toInt), listenerName, errorUnavailableEndpoints) | ||
| val offlineReplicaInfo = getEndpoints(snapshot, partitionState.offlineReplicas.asScala, listenerName, errorUnavailableEndpoints) | ||
|
|
||
| maybeLeader match { | ||
| case None => | ||
|
|
@@ -94,7 +95,7 @@ class MetadataCache(brokerId: Int) extends Logging { | |
| offlineReplicaInfo.asJava) | ||
|
|
||
| case Some(leader) => | ||
| val isr = partitionState.basePartitionState.isr.asScala.map(_.toInt) | ||
| val isr = partitionState.basePartitionState.isr.asScala | ||
| val isrInfo = getEndpoints(snapshot, isr, listenerName, errorUnavailableEndpoints) | ||
|
|
||
| if (replicaInfo.size < replicas.size) { | ||
|
|
||
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.
Actually, do you think we can switch this to be a plain
j.u.List? See next comment as well.