chia7712 commented on a change in pull request #10206: URL: https://github.com/apache/kafka/pull/10206#discussion_r582592473
########## File path: core/src/main/scala/kafka/server/KafkaApis.scala ########## @@ -3303,6 +3304,28 @@ class KafkaApis(val requestChannel: RequestChannel, new DescribeTransactionsResponse(response.setThrottleTimeMs(requestThrottleMs))) } + def handleListTransactionsRequest(request: RequestChannel.Request): Unit = { + val listTransactionsRequest = request.body[ListTransactionsRequest] + val response = new ListTransactionsResponseData() + + val filteredProducerIds = listTransactionsRequest.data.producerIdFilter.asScala.map(Long.unbox).toSet + val filteredStates = listTransactionsRequest.data.statesFilter.asScala.toSet + + txnCoordinator.handleListTransactions(filteredProducerIds, filteredStates) match { + case Left(error) => + response.setErrorCode(error.code) + case Right(transactions) => + val authorizedTransactions = transactions.filter { state => + authHelper.authorize(request.context, DESCRIBE, TRANSACTIONAL_ID, state.transactionalId) Review comment: Why `TransactionState` does not include error field (similar to `DescribeTransactionsResponseData.TransactionState`)? ########## File path: core/src/main/scala/kafka/coordinator/transaction/TransactionStateManager.scala ########## @@ -223,6 +224,49 @@ class TransactionStateManager(brokerId: Int, throw new IllegalStateException(s"Unexpected empty transaction metadata returned while putting $txnMetadata"))) } + def listTransactionStates( + filterProducerIds: Set[Long], + filterStateNames: Set[String] + ): Either[Errors, List[ListTransactionsResponseData.TransactionState]] = { + inReadLock(stateLock) { + if (loadingPartitions.nonEmpty) { + Left(Errors.COORDINATOR_LOAD_IN_PROGRESS) + } else { + val filterStates = filterStateNames.flatMap(TransactionState.fromName) + val states = mutable.ListBuffer.empty[ListTransactionsResponseData.TransactionState] + + def shouldInclude(txnMetadata: TransactionMetadata): Boolean = { + if (txnMetadata.state == Dead) { + // We filter the `Dead` state since it is a transient state which + // indicates that the transactionalId and its metadata are in the Review comment: redundant "space" ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org