Search in sources :

Example 1 with OffsetForLeaderTopicCollection

use of org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection 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 OffsetForLeaderTopicCollection

use of org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection 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)

Example 3 with OffsetForLeaderTopicCollection

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

the class OffsetsForLeaderEpochRequestTest method testForConsumerRequiresVersion3.

@Test
public void testForConsumerRequiresVersion3() {
    OffsetsForLeaderEpochRequest.Builder builder = OffsetsForLeaderEpochRequest.Builder.forConsumer(new OffsetForLeaderTopicCollection());
    for (short version = 0; version < 3; version++) {
        final short v = version;
        assertThrows(UnsupportedVersionException.class, () -> builder.build(v));
    }
    for (short version = 3; version <= ApiKeys.OFFSET_FOR_LEADER_EPOCH.latestVersion(); version++) {
        OffsetsForLeaderEpochRequest request = builder.build(version);
        assertEquals(OffsetsForLeaderEpochRequest.CONSUMER_REPLICA_ID, request.replicaId());
    }
}
Also used : OffsetForLeaderTopicCollection(org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection) Test(org.junit.jupiter.api.Test)

Example 4 with OffsetForLeaderTopicCollection

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

the class OffsetsForLeaderEpochRequestTest method testDefaultReplicaId.

@Test
public void testDefaultReplicaId() {
    for (short version : ApiKeys.OFFSET_FOR_LEADER_EPOCH.allVersions()) {
        int replicaId = 1;
        OffsetsForLeaderEpochRequest.Builder builder = OffsetsForLeaderEpochRequest.Builder.forFollower(version, new OffsetForLeaderTopicCollection(), replicaId);
        OffsetsForLeaderEpochRequest request = builder.build();
        OffsetsForLeaderEpochRequest parsed = OffsetsForLeaderEpochRequest.parse(request.serialize(), version);
        if (version < 3)
            assertEquals(OffsetsForLeaderEpochRequest.DEBUGGING_REPLICA_ID, parsed.replicaId());
        else
            assertEquals(replicaId, parsed.replicaId());
    }
}
Also used : OffsetForLeaderTopicCollection(org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection) Test(org.junit.jupiter.api.Test)

Aggregations

OffsetForLeaderTopicCollection (org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection)4 OffsetForLeaderPartition (org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderPartition)2 OffsetForLeaderTopic (org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopic)2 Test (org.junit.jupiter.api.Test)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