Search in sources :

Example 1 with NotControllerException

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

the class QuorumController method scheduleDeferredWriteEvent.

private <T> void scheduleDeferredWriteEvent(String name, long deadlineNs, ControllerWriteOperation<T> op) {
    ControllerWriteEvent<T> event = new ControllerWriteEvent<>(name, op);
    queue.scheduleDeferred(name, new EarliestDeadlineFunction(deadlineNs), event);
    event.future.exceptionally(e -> {
        if (e instanceof UnknownServerException && e.getCause() != null && e.getCause() instanceof RejectedExecutionException) {
            log.error("Cancelling deferred write event {} because the event queue " + "is now closed.", name);
            return null;
        } else if (e instanceof NotControllerException) {
            log.debug("Cancelling deferred write event {} because this controller " + "is no longer active.", name);
            return null;
        }
        log.error("Unexpected exception while executing deferred write event {}. " + "Rescheduling for a minute from now.", name, e);
        scheduleDeferredWriteEvent(name, deadlineNs + NANOSECONDS.convert(1, TimeUnit.MINUTES), op);
        return null;
    });
}
Also used : EarliestDeadlineFunction(org.apache.kafka.queue.EventQueue.EarliestDeadlineFunction) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) NotControllerException(org.apache.kafka.common.errors.NotControllerException)

Example 2 with NotControllerException

use of org.apache.kafka.common.errors.NotControllerException in project ksql by confluentinc.

the class KafkaTopicClientImplTest method listTopicResultWithNotControllerException.

@SuppressWarnings("unchecked")
private ListTopicsResult listTopicResultWithNotControllerException() {
    ListTopicsResult listTopicsResult = mock(ListTopicsResult.class);
    expect(listTopicsResult.names()).andReturn(failedFuture(new NotControllerException("Not Controller")));
    replay(listTopicsResult);
    return listTopicsResult;
}
Also used : ListTopicsResult(org.apache.kafka.clients.admin.ListTopicsResult) NotControllerException(org.apache.kafka.common.errors.NotControllerException)

Example 3 with NotControllerException

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

the class ApiErrorTest method parameters.

private static Collection<Arguments> parameters() {
    List<Arguments> arguments = new ArrayList<>();
    arguments.add(Arguments.of(new UnknownServerException("Don't leak sensitive information "), Errors.UNKNOWN_SERVER_ERROR, null));
    arguments.add(Arguments.of(new NotEnoughReplicasException(), Errors.NOT_ENOUGH_REPLICAS, null));
    // avoid populating the error message if it's a generic one
    arguments.add(Arguments.of(new UnknownTopicOrPartitionException(Errors.UNKNOWN_TOPIC_OR_PARTITION.message()), Errors.UNKNOWN_TOPIC_OR_PARTITION, null));
    String notCoordinatorErrorMsg = "Not coordinator";
    arguments.add(Arguments.of(new NotCoordinatorException(notCoordinatorErrorMsg), Errors.NOT_COORDINATOR, notCoordinatorErrorMsg));
    String notControllerErrorMsg = "Not controller";
    // test the NotControllerException is wrapped in the CompletionException, should return correct error
    arguments.add(Arguments.of(new CompletionException(new NotControllerException(notControllerErrorMsg)), Errors.NOT_CONTROLLER, notControllerErrorMsg));
    String requestTimeoutErrorMsg = "request time out";
    // test the TimeoutException is wrapped in the ExecutionException, should return correct error
    arguments.add(Arguments.of(new ExecutionException(new TimeoutException(requestTimeoutErrorMsg)), Errors.REQUEST_TIMED_OUT, requestTimeoutErrorMsg));
    // test the exception not in the Errors list, should return UNKNOWN_SERVER_ERROR
    arguments.add(Arguments.of(new IOException(), Errors.UNKNOWN_SERVER_ERROR, null));
    return arguments;
}
Also used : NotCoordinatorException(org.apache.kafka.common.errors.NotCoordinatorException) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) Arguments(org.junit.jupiter.params.provider.Arguments) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) CompletionException(java.util.concurrent.CompletionException) NotEnoughReplicasException(org.apache.kafka.common.errors.NotEnoughReplicasException) ExecutionException(java.util.concurrent.ExecutionException) NotControllerException(org.apache.kafka.common.errors.NotControllerException) TimeoutException(org.apache.kafka.common.errors.TimeoutException)

Aggregations

NotControllerException (org.apache.kafka.common.errors.NotControllerException)3 UnknownServerException (org.apache.kafka.common.errors.UnknownServerException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CompletionException (java.util.concurrent.CompletionException)1 ExecutionException (java.util.concurrent.ExecutionException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ListTopicsResult (org.apache.kafka.clients.admin.ListTopicsResult)1 NotCoordinatorException (org.apache.kafka.common.errors.NotCoordinatorException)1 NotEnoughReplicasException (org.apache.kafka.common.errors.NotEnoughReplicasException)1 TimeoutException (org.apache.kafka.common.errors.TimeoutException)1 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)1 EarliestDeadlineFunction (org.apache.kafka.queue.EventQueue.EarliestDeadlineFunction)1 Arguments (org.junit.jupiter.params.provider.Arguments)1