Search in sources :

Example 6 with WriteTxnMarkersResponse

use of org.apache.kafka.common.requests.WriteTxnMarkersResponse in project kafka by apache.

the class AbortTransactionHandler method handleResponse.

@Override
public ApiResult<TopicPartition, Void> handleResponse(Node broker, Set<TopicPartition> topicPartitions, AbstractResponse abstractResponse) {
    validateTopicPartitions(topicPartitions);
    WriteTxnMarkersResponse response = (WriteTxnMarkersResponse) abstractResponse;
    List<WriteTxnMarkersResponseData.WritableTxnMarkerResult> markerResponses = response.data().markers();
    if (markerResponses.size() != 1 || markerResponses.get(0).producerId() != abortSpec.producerId()) {
        return ApiResult.failed(abortSpec.topicPartition(), new KafkaException("WriteTxnMarkers response " + "included unexpected marker entries: " + markerResponses + "(expected to find exactly one " + "entry with producerId " + abortSpec.producerId() + ")"));
    }
    WriteTxnMarkersResponseData.WritableTxnMarkerResult markerResponse = markerResponses.get(0);
    List<WriteTxnMarkersResponseData.WritableTxnMarkerTopicResult> topicResponses = markerResponse.topics();
    if (topicResponses.size() != 1 || !topicResponses.get(0).name().equals(abortSpec.topicPartition().topic())) {
        return ApiResult.failed(abortSpec.topicPartition(), new KafkaException("WriteTxnMarkers response " + "included unexpected topic entries: " + markerResponses + "(expected to find exactly one " + "entry with topic partition " + abortSpec.topicPartition() + ")"));
    }
    WriteTxnMarkersResponseData.WritableTxnMarkerTopicResult topicResponse = topicResponses.get(0);
    List<WriteTxnMarkersResponseData.WritableTxnMarkerPartitionResult> partitionResponses = topicResponse.partitions();
    if (partitionResponses.size() != 1 || partitionResponses.get(0).partitionIndex() != abortSpec.topicPartition().partition()) {
        return ApiResult.failed(abortSpec.topicPartition(), new KafkaException("WriteTxnMarkers response " + "included unexpected partition entries for topic " + abortSpec.topicPartition().topic() + ": " + markerResponses + "(expected to find exactly one entry with partition " + abortSpec.topicPartition().partition() + ")"));
    }
    WriteTxnMarkersResponseData.WritableTxnMarkerPartitionResult partitionResponse = partitionResponses.get(0);
    Errors error = Errors.forCode(partitionResponse.errorCode());
    if (error != Errors.NONE) {
        return handleError(error);
    } else {
        return ApiResult.completed(abortSpec.topicPartition(), null);
    }
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) WriteTxnMarkersResponse(org.apache.kafka.common.requests.WriteTxnMarkersResponse) KafkaException(org.apache.kafka.common.KafkaException) WriteTxnMarkersResponseData(org.apache.kafka.common.message.WriteTxnMarkersResponseData)

Aggregations

WriteTxnMarkersResponse (org.apache.kafka.common.requests.WriteTxnMarkersResponse)6 WriteTxnMarkersResponseData (org.apache.kafka.common.message.WriteTxnMarkersResponseData)5 Test (org.junit.jupiter.api.Test)3 TopicPartition (org.apache.kafka.common.TopicPartition)2 Cluster (org.apache.kafka.common.Cluster)1 KafkaException (org.apache.kafka.common.KafkaException)1 Node (org.apache.kafka.common.Node)1 Errors (org.apache.kafka.common.protocol.Errors)1 WriteTxnMarkersRequest (org.apache.kafka.common.requests.WriteTxnMarkersRequest)1 MockTime (org.apache.kafka.common.utils.MockTime)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1