use of org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.OffsetForLeaderTopicResult in project kafka by apache.
the class OffsetsForLeaderEpochRequest method getErrorResponse.
@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
Errors error = Errors.forException(e);
OffsetForLeaderEpochResponseData responseData = new OffsetForLeaderEpochResponseData();
data.topics().forEach(topic -> {
OffsetForLeaderTopicResult topicData = new OffsetForLeaderTopicResult().setTopic(topic.topic());
topic.partitions().forEach(partition -> topicData.partitions().add(new EpochEndOffset().setPartition(partition.partition()).setErrorCode(error.code()).setLeaderEpoch(UNDEFINED_EPOCH).setEndOffset(UNDEFINED_EPOCH_OFFSET)));
responseData.topics().add(topicData);
});
return new OffsetsForLeaderEpochResponse(responseData);
}
use of org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.OffsetForLeaderTopicResult in project kafka by apache.
the class OffsetsForLeaderEpochClient method handleResponse.
@Override
protected OffsetForEpochResult handleResponse(Node node, Map<TopicPartition, SubscriptionState.FetchPosition> requestData, OffsetsForLeaderEpochResponse response) {
Set<TopicPartition> partitionsToRetry = new HashSet<>(requestData.keySet());
Set<String> unauthorizedTopics = new HashSet<>();
Map<TopicPartition, EpochEndOffset> endOffsets = new HashMap<>();
for (OffsetForLeaderTopicResult topic : response.data().topics()) {
for (EpochEndOffset partition : topic.partitions()) {
TopicPartition topicPartition = new TopicPartition(topic.topic(), partition.partition());
if (!requestData.containsKey(topicPartition)) {
logger().warn("Received unrequested topic or partition {} from response, ignoring.", topicPartition);
continue;
}
Errors error = Errors.forCode(partition.errorCode());
switch(error) {
case NONE:
logger().debug("Handling OffsetsForLeaderEpoch response for {}. Got offset {} for epoch {}.", topicPartition, partition.endOffset(), partition.leaderEpoch());
endOffsets.put(topicPartition, partition);
partitionsToRetry.remove(topicPartition);
break;
case NOT_LEADER_OR_FOLLOWER:
case REPLICA_NOT_AVAILABLE:
case KAFKA_STORAGE_ERROR:
case OFFSET_NOT_AVAILABLE:
case LEADER_NOT_AVAILABLE:
case FENCED_LEADER_EPOCH:
case UNKNOWN_LEADER_EPOCH:
logger().debug("Attempt to fetch offsets for partition {} failed due to {}, retrying.", topicPartition, error);
break;
case UNKNOWN_TOPIC_OR_PARTITION:
logger().warn("Received unknown topic or partition error in OffsetsForLeaderEpoch request for partition {}.", topicPartition);
break;
case TOPIC_AUTHORIZATION_FAILED:
unauthorizedTopics.add(topicPartition.topic());
partitionsToRetry.remove(topicPartition);
break;
default:
logger().warn("Attempt to fetch offsets for partition {} failed due to: {}, retrying.", topicPartition, error.message());
}
}
}
if (!unauthorizedTopics.isEmpty())
throw new TopicAuthorizationException(unauthorizedTopics);
else
return new OffsetForEpochResult(endOffsets, partitionsToRetry);
}
use of org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.OffsetForLeaderTopicResult in project kafka by apache.
the class RequestResponseTest method createLeaderEpochResponse.
private OffsetsForLeaderEpochResponse createLeaderEpochResponse() {
OffsetForLeaderEpochResponseData data = new OffsetForLeaderEpochResponseData();
data.topics().add(new OffsetForLeaderTopicResult().setTopic("topic1").setPartitions(asList(new EpochEndOffset().setPartition(0).setErrorCode(Errors.NONE.code()).setLeaderEpoch(1).setEndOffset(0), new EpochEndOffset().setPartition(1).setErrorCode(Errors.NONE.code()).setLeaderEpoch(1).setEndOffset(1))));
data.topics().add(new OffsetForLeaderTopicResult().setTopic("topic2").setPartitions(singletonList(new EpochEndOffset().setPartition(2).setErrorCode(Errors.NONE.code()).setLeaderEpoch(1).setEndOffset(1))));
return new OffsetsForLeaderEpochResponse(data);
}
use of org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.OffsetForLeaderTopicResult in project kafka by apache.
the class OffsetForLeaderEpochClientTest method prepareOffsetForLeaderEpochResponse.
private static OffsetsForLeaderEpochResponse prepareOffsetForLeaderEpochResponse(TopicPartition tp, Errors error, int leaderEpoch, long endOffset) {
OffsetForLeaderEpochResponseData data = new OffsetForLeaderEpochResponseData();
OffsetForLeaderTopicResult topic = new OffsetForLeaderTopicResult().setTopic(tp.topic());
data.topics().add(topic);
topic.partitions().add(new EpochEndOffset().setPartition(tp.partition()).setErrorCode(error.code()).setLeaderEpoch(leaderEpoch).setEndOffset(endOffset));
return new OffsetsForLeaderEpochResponse(data);
}
use of org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.OffsetForLeaderTopicResult in project kafka by apache.
the class FetcherTest method prepareOffsetsForLeaderEpochResponse.
private OffsetsForLeaderEpochResponse prepareOffsetsForLeaderEpochResponse(TopicPartition topicPartition, Errors error, int leaderEpoch, long endOffset) {
OffsetForLeaderEpochResponseData data = new OffsetForLeaderEpochResponseData();
data.topics().add(new OffsetForLeaderTopicResult().setTopic(topicPartition.topic()).setPartitions(Collections.singletonList(new EpochEndOffset().setPartition(topicPartition.partition()).setErrorCode(error.code()).setLeaderEpoch(leaderEpoch).setEndOffset(endOffset))));
return new OffsetsForLeaderEpochResponse(data);
}
Aggregations