Search in sources :

Example 21 with UnknownServerException

use of org.apache.kafka.common.errors.UnknownServerException in project kafka by apache.

the class AllBrokersStrategyIntegrationTest method testFatalFulfillmentError.

@Test
public void testFatalFulfillmentError() throws Exception {
    AllBrokersStrategy.AllBrokersFuture<Integer> result = new AllBrokersStrategy.AllBrokersFuture<>();
    AdminApiDriver<AllBrokersStrategy.BrokerKey, Integer> driver = buildDriver(result);
    List<AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey>> lookupSpecs = driver.poll();
    assertEquals(1, lookupSpecs.size());
    AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey> lookupSpec = lookupSpecs.get(0);
    int brokerId = 1;
    driver.onResponse(time.milliseconds(), lookupSpec, responseWithBrokers(Collections.singleton(brokerId)), Node.noNode());
    assertTrue(result.all().isDone());
    Map<Integer, KafkaFutureImpl<Integer>> brokerFutures = result.all().get();
    KafkaFutureImpl<Integer> future = brokerFutures.get(brokerId);
    assertFalse(future.isDone());
    List<AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey>> requestSpecs = driver.poll();
    assertEquals(1, requestSpecs.size());
    AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey> requestSpec = requestSpecs.get(0);
    driver.onFailure(time.milliseconds(), requestSpec, new UnknownServerException());
    assertTrue(future.isDone());
    TestUtils.assertFutureThrows(future, UnknownServerException.class);
    assertEquals(Collections.emptyList(), driver.poll());
}
Also used : KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) Test(org.junit.jupiter.api.Test)

Example 22 with UnknownServerException

use of org.apache.kafka.common.errors.UnknownServerException in project kafka by apache.

the class DescribeProducersHandlerTest method testUnexpectedError.

@Test
public void testUnexpectedError() {
    TopicPartition topicPartition = new TopicPartition("foo", 5);
    Throwable exception = assertFatalError(topicPartition, Errors.UNKNOWN_SERVER_ERROR);
    assertTrue(exception instanceof UnknownServerException);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) Test(org.junit.jupiter.api.Test)

Example 23 with UnknownServerException

use of org.apache.kafka.common.errors.UnknownServerException in project kafka by apache.

the class PartitionLeaderStrategyTest method testUnexpectedTopicErrror.

@Test
public void testUnexpectedTopicErrror() {
    TopicPartition topicPartition = new TopicPartition("foo", 0);
    Throwable exception = assertFatalTopicError(topicPartition, Errors.UNKNOWN_SERVER_ERROR);
    assertTrue(exception instanceof UnknownServerException);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) Test(org.junit.jupiter.api.Test)

Example 24 with UnknownServerException

use of org.apache.kafka.common.errors.UnknownServerException in project kafka by apache.

the class UpdateFeaturesRequestTest method testGetErrorResponse.

@Test
public void testGetErrorResponse() {
    UpdateFeaturesRequestData.FeatureUpdateKeyCollection features = new UpdateFeaturesRequestData.FeatureUpdateKeyCollection();
    features.add(new UpdateFeaturesRequestData.FeatureUpdateKey().setFeature("foo").setMaxVersionLevel((short) 2));
    features.add(new UpdateFeaturesRequestData.FeatureUpdateKey().setFeature("bar").setMaxVersionLevel((short) 3));
    UpdateFeaturesRequest request = new UpdateFeaturesRequest(new UpdateFeaturesRequestData().setFeatureUpdates(features), UpdateFeaturesRequestData.HIGHEST_SUPPORTED_VERSION);
    UpdateFeaturesResponse response = request.getErrorResponse(0, new UnknownServerException());
    assertEquals(Errors.UNKNOWN_SERVER_ERROR, response.topLevelError().error());
    assertEquals(0, response.data().results().size());
    assertEquals(Collections.singletonMap(Errors.UNKNOWN_SERVER_ERROR, 1), response.errorCounts());
}
Also used : UpdateFeaturesRequestData(org.apache.kafka.common.message.UpdateFeaturesRequestData) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) Test(org.junit.jupiter.api.Test)

Example 25 with UnknownServerException

use of org.apache.kafka.common.errors.UnknownServerException in project kafka by apache.

the class ReplicationControlManager method createPartitions.

void createPartitions(CreatePartitionsTopic topic, List<ApiMessageAndVersion> records) {
    Uuid topicId = topicsByName.get(topic.name());
    if (topicId == null) {
        throw new UnknownTopicOrPartitionException();
    }
    TopicControlInfo topicInfo = topics.get(topicId);
    if (topicInfo == null) {
        throw new UnknownTopicOrPartitionException();
    }
    if (topic.count() == topicInfo.parts.size()) {
        throw new InvalidPartitionsException("Topic already has " + topicInfo.parts.size() + " partition(s).");
    } else if (topic.count() < topicInfo.parts.size()) {
        throw new InvalidPartitionsException("The topic " + topic.name() + " currently " + "has " + topicInfo.parts.size() + " partition(s); " + topic.count() + " would not be an increase.");
    }
    int additional = topic.count() - topicInfo.parts.size();
    if (topic.assignments() != null) {
        if (topic.assignments().size() != additional) {
            throw new InvalidReplicaAssignmentException("Attempted to add " + additional + " additional partition(s), but only " + topic.assignments().size() + " assignment(s) were specified.");
        }
    }
    Iterator<PartitionRegistration> iterator = topicInfo.parts.values().iterator();
    if (!iterator.hasNext()) {
        throw new UnknownServerException("Invalid state: topic " + topic.name() + " appears to have no partitions.");
    }
    PartitionRegistration partitionInfo = iterator.next();
    if (partitionInfo.replicas.length > Short.MAX_VALUE) {
        throw new UnknownServerException("Invalid replication factor " + partitionInfo.replicas.length + ": expected a number equal to less than " + Short.MAX_VALUE);
    }
    short replicationFactor = (short) partitionInfo.replicas.length;
    int startPartitionId = topicInfo.parts.size();
    List<List<Integer>> placements;
    List<List<Integer>> isrs;
    if (topic.assignments() != null) {
        placements = new ArrayList<>();
        isrs = new ArrayList<>();
        for (int i = 0; i < topic.assignments().size(); i++) {
            CreatePartitionsAssignment assignment = topic.assignments().get(i);
            validateManualPartitionAssignment(assignment.brokerIds(), OptionalInt.of(replicationFactor));
            placements.add(assignment.brokerIds());
            List<Integer> isr = assignment.brokerIds().stream().filter(clusterControl::unfenced).collect(Collectors.toList());
            if (isr.isEmpty()) {
                throw new InvalidReplicaAssignmentException("All brokers specified in the manual partition assignment for " + "partition " + (startPartitionId + i) + " are fenced.");
            }
            isrs.add(isr);
        }
    } else {
        placements = clusterControl.placeReplicas(startPartitionId, additional, replicationFactor);
        isrs = placements;
    }
    int partitionId = startPartitionId;
    for (int i = 0; i < placements.size(); i++) {
        List<Integer> placement = placements.get(i);
        List<Integer> isr = isrs.get(i);
        records.add(new ApiMessageAndVersion(new PartitionRecord().setPartitionId(partitionId).setTopicId(topicId).setReplicas(placement).setIsr(isr).setRemovingReplicas(Collections.emptyList()).setAddingReplicas(Collections.emptyList()).setLeader(isr.get(0)).setLeaderEpoch(0).setPartitionEpoch(0), PARTITION_RECORD.highestSupportedVersion()));
        partitionId++;
    }
}
Also used : PartitionRegistration(org.apache.kafka.metadata.PartitionRegistration) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) PartitionRecord(org.apache.kafka.common.metadata.PartitionRecord) InvalidPartitionsException(org.apache.kafka.common.errors.InvalidPartitionsException) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) TimelineInteger(org.apache.kafka.timeline.TimelineInteger) Uuid(org.apache.kafka.common.Uuid) CreatePartitionsAssignment(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsAssignment) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) List(java.util.List) InvalidReplicaAssignmentException(org.apache.kafka.common.errors.InvalidReplicaAssignmentException)

Aggregations

UnknownServerException (org.apache.kafka.common.errors.UnknownServerException)28 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)7 List (java.util.List)7 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)7 Test (org.junit.jupiter.api.Test)7 LinkedList (java.util.LinkedList)6 TopicPartition (org.apache.kafka.common.TopicPartition)6 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)5 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)5 Iterator (java.util.Iterator)4 KafkaFuture (org.apache.kafka.common.KafkaFuture)4 AclBinding (org.apache.kafka.common.acl.AclBinding)4 ApiException (org.apache.kafka.common.errors.ApiException)4 Test (org.junit.Test)4 Map (java.util.Map)3 Callback (org.apache.kafka.clients.producer.Callback)3 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2