Search in sources :

Example 21 with WakeupException

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

the class ConsumerCoordinator method invokePartitionsRevoked.

private Exception invokePartitionsRevoked(final SortedSet<TopicPartition> revokedPartitions) {
    log.info("Revoke previously assigned partitions {}", Utils.join(revokedPartitions, ", "));
    Set<TopicPartition> revokePausedPartitions = subscriptions.pausedPartitions();
    revokePausedPartitions.retainAll(revokedPartitions);
    if (!revokePausedPartitions.isEmpty())
        log.info("The pause flag in partitions [{}] will be removed due to revocation.", Utils.join(revokePausedPartitions, ", "));
    ConsumerRebalanceListener listener = subscriptions.rebalanceListener();
    try {
        final long startMs = time.milliseconds();
        listener.onPartitionsRevoked(revokedPartitions);
        sensors.revokeCallbackSensor.record(time.milliseconds() - startMs);
    } catch (WakeupException | InterruptException e) {
        throw e;
    } catch (Exception e) {
        log.error("User provided listener {} failed on invocation of onPartitionsRevoked for partitions {}", listener.getClass().getName(), revokedPartitions, e);
        return e;
    }
    return null;
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) InterruptException(org.apache.kafka.common.errors.InterruptException) ConsumerRebalanceListener(org.apache.kafka.clients.consumer.ConsumerRebalanceListener) WakeupException(org.apache.kafka.common.errors.WakeupException) GroupAuthorizationException(org.apache.kafka.common.errors.GroupAuthorizationException) UnstableOffsetCommitException(org.apache.kafka.common.errors.UnstableOffsetCommitException) KafkaException(org.apache.kafka.common.KafkaException) WakeupException(org.apache.kafka.common.errors.WakeupException) RebalanceInProgressException(org.apache.kafka.common.errors.RebalanceInProgressException) RetriableCommitFailedException(org.apache.kafka.clients.consumer.RetriableCommitFailedException) RetriableException(org.apache.kafka.common.errors.RetriableException) InterruptException(org.apache.kafka.common.errors.InterruptException) TimeoutException(org.apache.kafka.common.errors.TimeoutException) FencedInstanceIdException(org.apache.kafka.common.errors.FencedInstanceIdException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) CommitFailedException(org.apache.kafka.clients.consumer.CommitFailedException)

Example 22 with WakeupException

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

the class ConsumerCoordinator method invokePartitionsLost.

private Exception invokePartitionsLost(final SortedSet<TopicPartition> lostPartitions) {
    log.info("Lost previously assigned partitions {}", Utils.join(lostPartitions, ", "));
    Set<TopicPartition> lostPausedPartitions = subscriptions.pausedPartitions();
    lostPausedPartitions.retainAll(lostPartitions);
    if (!lostPausedPartitions.isEmpty())
        log.info("The pause flag in partitions [{}] will be removed due to partition lost.", Utils.join(lostPausedPartitions, ", "));
    ConsumerRebalanceListener listener = subscriptions.rebalanceListener();
    try {
        final long startMs = time.milliseconds();
        listener.onPartitionsLost(lostPartitions);
        sensors.loseCallbackSensor.record(time.milliseconds() - startMs);
    } catch (WakeupException | InterruptException e) {
        throw e;
    } catch (Exception e) {
        log.error("User provided listener {} failed on invocation of onPartitionsLost for partitions {}", listener.getClass().getName(), lostPartitions, e);
        return e;
    }
    return null;
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) InterruptException(org.apache.kafka.common.errors.InterruptException) ConsumerRebalanceListener(org.apache.kafka.clients.consumer.ConsumerRebalanceListener) WakeupException(org.apache.kafka.common.errors.WakeupException) GroupAuthorizationException(org.apache.kafka.common.errors.GroupAuthorizationException) UnstableOffsetCommitException(org.apache.kafka.common.errors.UnstableOffsetCommitException) KafkaException(org.apache.kafka.common.KafkaException) WakeupException(org.apache.kafka.common.errors.WakeupException) RebalanceInProgressException(org.apache.kafka.common.errors.RebalanceInProgressException) RetriableCommitFailedException(org.apache.kafka.clients.consumer.RetriableCommitFailedException) RetriableException(org.apache.kafka.common.errors.RetriableException) InterruptException(org.apache.kafka.common.errors.InterruptException) TimeoutException(org.apache.kafka.common.errors.TimeoutException) FencedInstanceIdException(org.apache.kafka.common.errors.FencedInstanceIdException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) CommitFailedException(org.apache.kafka.clients.consumer.CommitFailedException)

Example 23 with WakeupException

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

the class AbstractCoordinatorTest method testWakeupInOnJoinComplete.

@Test
public void testWakeupInOnJoinComplete() throws Exception {
    setupCoordinator();
    coordinator.wakeupOnJoinComplete = true;
    mockClient.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
    mockClient.prepareResponse(joinGroupFollowerResponse(1, memberId, leaderId, Errors.NONE));
    mockClient.prepareResponse(syncGroupResponse(Errors.NONE));
    AtomicBoolean heartbeatReceived = prepareFirstHeartbeat();
    try {
        coordinator.ensureActiveGroup();
        fail("Should have woken up from ensureActiveGroup()");
    } catch (WakeupException ignored) {
    }
    assertEquals(1, coordinator.onJoinPrepareInvokes);
    assertEquals(0, coordinator.onJoinCompleteInvokes);
    assertFalse(heartbeatReceived.get());
    // the join group completes in this poll()
    coordinator.wakeupOnJoinComplete = false;
    consumerClient.poll(mockTime.timer(0));
    coordinator.ensureActiveGroup();
    assertEquals(1, coordinator.onJoinPrepareInvokes);
    assertEquals(1, coordinator.onJoinCompleteInvokes);
    awaitFirstHeartbeat(heartbeatReceived);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WakeupException(org.apache.kafka.common.errors.WakeupException) Test(org.junit.jupiter.api.Test)

Example 24 with WakeupException

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

the class AbstractCoordinatorTest method testWakeupAfterJoinGroupReceivedExternalCompletion.

@Test
public void testWakeupAfterJoinGroupReceivedExternalCompletion() throws Exception {
    setupCoordinator();
    mockClient.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
    mockClient.prepareResponse(body -> {
        boolean isJoinGroupRequest = body instanceof JoinGroupRequest;
        if (isJoinGroupRequest)
            // wakeup after the request returns
            consumerClient.wakeup();
        return isJoinGroupRequest;
    }, joinGroupFollowerResponse(1, memberId, leaderId, Errors.NONE));
    mockClient.prepareResponse(syncGroupResponse(Errors.NONE));
    AtomicBoolean heartbeatReceived = prepareFirstHeartbeat();
    try {
        coordinator.ensureActiveGroup();
        fail("Should have woken up from ensureActiveGroup()");
    } catch (WakeupException e) {
    }
    assertEquals(1, coordinator.onJoinPrepareInvokes);
    assertEquals(0, coordinator.onJoinCompleteInvokes);
    assertFalse(heartbeatReceived.get());
    // the join group completes in this poll()
    consumerClient.poll(mockTime.timer(0));
    coordinator.ensureActiveGroup();
    assertEquals(1, coordinator.onJoinPrepareInvokes);
    assertEquals(1, coordinator.onJoinCompleteInvokes);
    awaitFirstHeartbeat(heartbeatReceived);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JoinGroupRequest(org.apache.kafka.common.requests.JoinGroupRequest) WakeupException(org.apache.kafka.common.errors.WakeupException) Test(org.junit.jupiter.api.Test)

Example 25 with WakeupException

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

the class AbstractCoordinatorTest method testWakeupAfterSyncGroupReceivedExternalCompletion.

@Test
public void testWakeupAfterSyncGroupReceivedExternalCompletion() throws Exception {
    setupCoordinator();
    mockClient.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
    mockClient.prepareResponse(joinGroupFollowerResponse(1, memberId, leaderId, Errors.NONE));
    mockClient.prepareResponse(body -> {
        boolean isSyncGroupRequest = body instanceof SyncGroupRequest;
        if (isSyncGroupRequest)
            // wakeup after the request returns
            consumerClient.wakeup();
        return isSyncGroupRequest;
    }, syncGroupResponse(Errors.NONE));
    AtomicBoolean heartbeatReceived = prepareFirstHeartbeat();
    try {
        coordinator.ensureActiveGroup();
        fail("Should have woken up from ensureActiveGroup()");
    } catch (WakeupException e) {
    }
    assertEquals(1, coordinator.onJoinPrepareInvokes);
    assertEquals(0, coordinator.onJoinCompleteInvokes);
    assertFalse(heartbeatReceived.get());
    coordinator.ensureActiveGroup();
    assertEquals(1, coordinator.onJoinPrepareInvokes);
    assertEquals(1, coordinator.onJoinCompleteInvokes);
    awaitFirstHeartbeat(heartbeatReceived);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SyncGroupRequest(org.apache.kafka.common.requests.SyncGroupRequest) WakeupException(org.apache.kafka.common.errors.WakeupException) Test(org.junit.jupiter.api.Test)

Aggregations

WakeupException (org.apache.kafka.common.errors.WakeupException)51 TopicPartition (org.apache.kafka.common.TopicPartition)22 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)20 Test (org.junit.Test)18 MockClient (org.apache.kafka.clients.MockClient)13 HashMap (java.util.HashMap)12 AbstractRequest (org.apache.kafka.common.requests.AbstractRequest)12 KafkaException (org.apache.kafka.common.KafkaException)10 Test (org.junit.jupiter.api.Test)9 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)8 JoinGroupRequest (org.apache.kafka.common.requests.JoinGroupRequest)8 SyncGroupRequest (org.apache.kafka.common.requests.SyncGroupRequest)8 Map (java.util.Map)7 ArrayList (java.util.ArrayList)6 ConsumerRebalanceListener (org.apache.kafka.clients.consumer.ConsumerRebalanceListener)6 InterruptException (org.apache.kafka.common.errors.InterruptException)6 CommitFailedException (org.apache.kafka.clients.consumer.CommitFailedException)5 RetriableCommitFailedException (org.apache.kafka.clients.consumer.RetriableCommitFailedException)5 GroupAuthorizationException (org.apache.kafka.common.errors.GroupAuthorizationException)5 RetriableException (org.apache.kafka.common.errors.RetriableException)5