dajac commented on code in PR #14378: URL: https://github.com/apache/kafka/pull/14378#discussion_r1324869297
########## core/src/main/scala/kafka/server/ReplicaManager.scala: ########## @@ -753,39 +753,56 @@ class ReplicaManager(val config: KafkaConfig, val localProduceResults = appendToLocalLog(internalTopicsAllowed = internalTopicsAllowed, origin, verifiedEntries, requiredAcks, requestLocal, verificationGuards.toMap) debug("Produce to local log in %d ms".format(time.milliseconds - sTime)) - - val unverifiedResults = unverifiedEntries.map { case (topicPartition, error) => - val message = if (error == Errors.INVALID_TXN_STATE) "Partition was not added to the transaction" else error.message() - topicPartition -> LogAppendResult( - LogAppendInfo.UNKNOWN_LOG_APPEND_INFO, - Some(error.exception(message)) - ) - } - val errorResults = errorsPerPartition.map { case (topicPartition, error) => - topicPartition -> LogAppendResult( - LogAppendInfo.UNKNOWN_LOG_APPEND_INFO, - Some(error.exception()) - ) + def produceStatusResult(appendResult: Map[TopicPartition, LogAppendResult], + useCustomMessage: Boolean): Map[TopicPartition, ProducePartitionStatus] = { + appendResult.map { case (topicPartition, result) => + topicPartition -> ProducePartitionStatus( + result.info.lastOffset + 1, // required offset + new PartitionResponse( + result.error, + result.info.firstOffset.map[Long](_.messageOffset).orElse(-1L), + result.info.lastOffset, + result.info.logAppendTime, + result.info.logStartOffset, + result.info.recordErrors, + if (useCustomMessage) result.exception.get.getMessage else result.info.errorMessage + ) + ) // response status + } } - val allResults = localProduceResults ++ unverifiedResults ++ errorResults + val unverifiedResults = unverifiedEntries.map { + case (topicPartition, error) => + val finalException = + error match { + case Errors.INVALID_TXN_STATE => error.exception("Partition was not added to the transaction") + case Errors.CONCURRENT_TRANSACTIONS | + Errors.COORDINATOR_LOAD_IN_PROGRESS | + Errors.COORDINATOR_NOT_AVAILABLE | + Errors.NOT_COORDINATOR => new NotEnoughReplicasException( + s"Unable to verify the partition has been added to the transaction. Underlying error: ${error.toString}") Review Comment: nit: Indentation. -- 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. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org