Search in sources :

Example 1 with OffsetForLeaderTopic

use of org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopic in project kafka by apache.

the class OffsetsForLeaderEpochClient method prepareRequest.

@Override
protected AbstractRequest.Builder<OffsetsForLeaderEpochRequest> prepareRequest(Node node, Map<TopicPartition, SubscriptionState.FetchPosition> requestData) {
    OffsetForLeaderTopicCollection topics = new OffsetForLeaderTopicCollection(requestData.size());
    requestData.forEach((topicPartition, fetchPosition) -> fetchPosition.offsetEpoch.ifPresent(fetchEpoch -> {
        OffsetForLeaderTopic topic = topics.find(topicPartition.topic());
        if (topic == null) {
            topic = new OffsetForLeaderTopic().setTopic(topicPartition.topic());
            topics.add(topic);
        }
        topic.partitions().add(new OffsetForLeaderPartition().setPartition(topicPartition.partition()).setLeaderEpoch(fetchEpoch).setCurrentLeaderEpoch(fetchPosition.currentLeader.epoch.orElse(RecordBatch.NO_PARTITION_LEADER_EPOCH)));
    }));
    return OffsetsForLeaderEpochRequest.Builder.forConsumer(topics);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) OffsetForLeaderTopic(org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopic) OffsetForLeaderPartition(org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderPartition) EpochEndOffset(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.EpochEndOffset) Set(java.util.Set) HashMap(java.util.HashMap) AbstractRequest(org.apache.kafka.common.requests.AbstractRequest) HashSet(java.util.HashSet) OffsetForLeaderTopicCollection(org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection) RecordBatch(org.apache.kafka.common.record.RecordBatch) LogContext(org.apache.kafka.common.utils.LogContext) Map(java.util.Map) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) Errors(org.apache.kafka.common.protocol.Errors) Node(org.apache.kafka.common.Node) OffsetForLeaderTopicResult(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.OffsetForLeaderTopicResult) OffsetsForLeaderEpochResponse(org.apache.kafka.common.requests.OffsetsForLeaderEpochResponse) OffsetsForLeaderEpochRequest(org.apache.kafka.common.requests.OffsetsForLeaderEpochRequest) OffsetForLeaderTopic(org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopic) OffsetForLeaderTopicCollection(org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection) OffsetForLeaderPartition(org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderPartition)

Example 2 with OffsetForLeaderTopic

use of org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopic in project kafka by apache.

the class RequestResponseTest method createOffsetForLeaderTopicCollection.

private OffsetForLeaderTopicCollection createOffsetForLeaderTopicCollection() {
    OffsetForLeaderTopicCollection topics = new OffsetForLeaderTopicCollection();
    topics.add(new OffsetForLeaderTopic().setTopic("topic1").setPartitions(asList(new OffsetForLeaderPartition().setPartition(0).setLeaderEpoch(1).setCurrentLeaderEpoch(0), new OffsetForLeaderPartition().setPartition(1).setLeaderEpoch(1).setCurrentLeaderEpoch(0))));
    topics.add(new OffsetForLeaderTopic().setTopic("topic2").setPartitions(singletonList(new OffsetForLeaderPartition().setPartition(2).setLeaderEpoch(3).setCurrentLeaderEpoch(RecordBatch.NO_PARTITION_LEADER_EPOCH))));
    return topics;
}
Also used : OffsetForLeaderTopic(org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopic) OffsetForLeaderTopicCollection(org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection) OffsetForLeaderPartition(org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderPartition)

Aggregations

OffsetForLeaderPartition (org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderPartition)2 OffsetForLeaderTopic (org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopic)2 OffsetForLeaderTopicCollection (org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Node (org.apache.kafka.common.Node)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)1 EpochEndOffset (org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.EpochEndOffset)1 OffsetForLeaderTopicResult (org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.OffsetForLeaderTopicResult)1 Errors (org.apache.kafka.common.protocol.Errors)1 RecordBatch (org.apache.kafka.common.record.RecordBatch)1 AbstractRequest (org.apache.kafka.common.requests.AbstractRequest)1 OffsetsForLeaderEpochRequest (org.apache.kafka.common.requests.OffsetsForLeaderEpochRequest)1 OffsetsForLeaderEpochResponse (org.apache.kafka.common.requests.OffsetsForLeaderEpochResponse)1 LogContext (org.apache.kafka.common.utils.LogContext)1