-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-10842; Use InterBrokerSendThread for raft's outbound network channel
#9732
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
9ac6bb0
065514e
6eb4ef2
d0fd77f
53cf918
2999fc7
67633d5
e113993
e9574f3
c31ba33
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 |
|---|---|---|
|
|
@@ -24,8 +24,8 @@ import kafka.api.KAFKA_2_8_IV0 | |
| import kafka.common.{InterBrokerSendThread, RequestAndCompletionHandler} | ||
| import kafka.metrics.KafkaMetricsGroup | ||
| import kafka.server.{KafkaConfig, MetadataCache} | ||
| import kafka.utils.{CoreUtils, Logging} | ||
| import kafka.utils.Implicits._ | ||
| import kafka.utils.{CoreUtils, Logging} | ||
| import org.apache.kafka.clients._ | ||
| import org.apache.kafka.common.metrics.Metrics | ||
| import org.apache.kafka.common.network._ | ||
|
|
@@ -36,8 +36,8 @@ import org.apache.kafka.common.security.JaasContext | |
| import org.apache.kafka.common.utils.{LogContext, Time} | ||
| import org.apache.kafka.common.{Node, Reconfigurable, TopicPartition} | ||
|
|
||
| import scala.jdk.CollectionConverters._ | ||
| import scala.collection.{concurrent, immutable} | ||
| import scala.jdk.CollectionConverters._ | ||
|
|
||
| object TransactionMarkerChannelManager { | ||
| def apply(config: KafkaConfig, | ||
|
|
@@ -127,11 +127,14 @@ class TxnMarkerQueue(@volatile var destination: Node) { | |
| def totalNumMarkers(txnTopicPartition: Int): Int = markersPerTxnTopicPartition.get(txnTopicPartition).fold(0)(_.size) | ||
| } | ||
|
|
||
| class TransactionMarkerChannelManager(config: KafkaConfig, | ||
| metadataCache: MetadataCache, | ||
| networkClient: NetworkClient, | ||
| txnStateManager: TransactionStateManager, | ||
| time: Time) extends InterBrokerSendThread("TxnMarkerSenderThread-" + config.brokerId, networkClient, time) with Logging with KafkaMetricsGroup { | ||
| class TransactionMarkerChannelManager( | ||
|
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. nit: (related to style question elsewhere) if we want to change the style of these class definitions, can we do it as a separate PR? I always find it difficult when style changes are conflated with logical changes
Contributor
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. That's fair. I actually held myself back. I tried to only touch the cases that I was modifying anyway, but let me know if there are others. This one was especially obnoxious because of the long parameter list to |
||
| config: KafkaConfig, | ||
| metadataCache: MetadataCache, | ||
| networkClient: NetworkClient, | ||
| txnStateManager: TransactionStateManager, | ||
| time: Time | ||
| ) extends InterBrokerSendThread("TxnMarkerSenderThread-" + config.brokerId, networkClient, config.requestTimeoutMs, time) | ||
| with Logging with KafkaMetricsGroup { | ||
|
|
||
| this.logIdent = "[Transaction Marker Channel Manager " + config.brokerId + "]: " | ||
|
|
||
|
|
@@ -145,17 +148,13 @@ class TransactionMarkerChannelManager(config: KafkaConfig, | |
|
|
||
| private val transactionsWithPendingMarkers = new ConcurrentHashMap[String, PendingCompleteTxn] | ||
|
|
||
| override val requestTimeoutMs: Int = config.requestTimeoutMs | ||
|
|
||
| val writeTxnMarkersRequestVersion: Short = | ||
| if (config.interBrokerProtocolVersion >= KAFKA_2_8_IV0) 1 | ||
| else 0 | ||
|
|
||
| newGauge("UnknownDestinationQueueSize", () => markersQueueForUnknownBroker.totalNumMarkers) | ||
| newGauge("LogAppendRetryQueueSize", () => txnLogAppendRetryQueue.size) | ||
|
|
||
| override def generateRequests() = drainQueuedTransactionMarkers() | ||
|
|
||
| override def shutdown(): Unit = { | ||
| super.shutdown() | ||
| markersQueuePerBroker.clear() | ||
|
|
@@ -191,7 +190,7 @@ class TransactionMarkerChannelManager(config: KafkaConfig, | |
| } | ||
| } | ||
|
|
||
| private[transaction] def drainQueuedTransactionMarkers(): Iterable[RequestAndCompletionHandler] = { | ||
| override def generateRequests(): Iterable[RequestAndCompletionHandler] = { | ||
| retryLogAppends() | ||
| val txnIdAndMarkerEntries: java.util.List[TxnIdAndMarkerEntry] = new util.ArrayList[TxnIdAndMarkerEntry]() | ||
| markersQueueForUnknownBroker.forEachTxnTopicPartition { case (_, queue) => | ||
|
|
@@ -209,6 +208,7 @@ class TransactionMarkerChannelManager(config: KafkaConfig, | |
| addTxnMarkersToBrokerQueue(transactionalId, producerId, producerEpoch, txnResult, coordinatorEpoch, topicPartitions) | ||
| } | ||
|
|
||
| val currentTimeMs = time.milliseconds() | ||
| markersQueuePerBroker.values.map { brokerRequestQueue => | ||
| val txnIdAndMarkerEntries = new util.ArrayList[TxnIdAndMarkerEntry]() | ||
| brokerRequestQueue.forEachTxnTopicPartition { case (_, queue) => | ||
|
|
@@ -218,7 +218,14 @@ class TransactionMarkerChannelManager(config: KafkaConfig, | |
| }.filter { case (_, entries) => !entries.isEmpty }.map { case (node, entries) => | ||
| val markersToSend = entries.asScala.map(_.txnMarkerEntry).asJava | ||
| val requestCompletionHandler = new TransactionMarkerRequestCompletionHandler(node.id, txnStateManager, this, entries) | ||
| RequestAndCompletionHandler(node, new WriteTxnMarkersRequest.Builder(writeTxnMarkersRequestVersion, markersToSend), requestCompletionHandler) | ||
| val request = new WriteTxnMarkersRequest.Builder(writeTxnMarkersRequestVersion, markersToSend) | ||
|
|
||
| RequestAndCompletionHandler( | ||
| currentTimeMs, | ||
| node, | ||
| request, | ||
| requestCompletionHandler | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
Is it worth adding a
sizeorisEmptytoUnsentRequests?