hachikuji commented on code in PR #14378:
URL: https://github.com/apache/kafka/pull/14378#discussion_r1323804315
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -753,39 +753,59 @@ 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 finalError =
+ error match {
+ case Errors.CONCURRENT_TRANSACTIONS |
+ Errors.COORDINATOR_LOAD_IN_PROGRESS |
+ Errors.COORDINATOR_NOT_AVAILABLE |
+ Errors.NOT_COORDINATOR => Errors.NOT_ENOUGH_REPLICAS
+ case _ => error
+ }
+ val message =
+ error match {
+ case Errors.INVALID_TXN_STATE => "Partition was not added to
the transaction"
+ case _ => error.message() // the above modified errors will
have their original error message to clarify the error.
Review Comment:
Perhaps we could add some context in the error message instead of using the
default error message. For example:
> Unable to verify the partition has been added to the transaction
(underlying error = XX)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]