Search in sources :

Example 1 with TransactionalIdNotFoundException

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

the class DescribeTransactionsHandler method handleError.

private void handleError(CoordinatorKey transactionalIdKey, Errors error, Map<CoordinatorKey, Throwable> failed, List<CoordinatorKey> unmapped) {
    switch(error) {
        case TRANSACTIONAL_ID_AUTHORIZATION_FAILED:
            failed.put(transactionalIdKey, new TransactionalIdAuthorizationException("DescribeTransactions request for transactionalId `" + transactionalIdKey.idValue + "` " + "failed due to authorization failure"));
            break;
        case TRANSACTIONAL_ID_NOT_FOUND:
            failed.put(transactionalIdKey, new TransactionalIdNotFoundException("DescribeTransactions request for transactionalId `" + transactionalIdKey.idValue + "` " + "failed because the ID could not be found"));
            break;
        case COORDINATOR_LOAD_IN_PROGRESS:
            // If the coordinator is in the middle of loading, then we just need to retry
            log.debug("DescribeTransactions request for transactionalId `{}` failed because the " + "coordinator is still in the process of loading state. Will retry", transactionalIdKey.idValue);
            break;
        case NOT_COORDINATOR:
        case COORDINATOR_NOT_AVAILABLE:
            // If the coordinator is unavailable or there was a coordinator change, then we unmap
            // the key so that we retry the `FindCoordinator` request
            unmapped.add(transactionalIdKey);
            log.debug("DescribeTransactions request for transactionalId `{}` returned error {}. Will attempt " + "to find the coordinator again and retry", transactionalIdKey.idValue, error);
            break;
        default:
            failed.put(transactionalIdKey, error.exception("DescribeTransactions request for " + "transactionalId `" + transactionalIdKey.idValue + "` failed due to unexpected error"));
    }
}
Also used : TransactionalIdNotFoundException(org.apache.kafka.common.errors.TransactionalIdNotFoundException) TransactionalIdAuthorizationException(org.apache.kafka.common.errors.TransactionalIdAuthorizationException)

Example 2 with TransactionalIdNotFoundException

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

the class TransactionsCommandTest method testFindHangingWithNoTransactionDescription.

@Test
public void testFindHangingWithNoTransactionDescription() throws Exception {
    TopicPartition topicPartition = new TopicPartition("foo", 5);
    String[] args = new String[] { "--bootstrap-server", "localhost:9092", "find-hanging", "--topic", topicPartition.topic(), "--partition", String.valueOf(topicPartition.partition()) };
    long producerId = 132L;
    short producerEpoch = 5;
    long lastTimestamp = time.milliseconds() - TimeUnit.MINUTES.toMillis(60);
    int coordinatorEpoch = 19;
    long txnStartOffset = 29384L;
    expectDescribeProducers(topicPartition, producerId, producerEpoch, lastTimestamp, OptionalInt.of(coordinatorEpoch), OptionalLong.of(txnStartOffset));
    String transactionalId = "bar";
    TransactionListing listing = new TransactionListing(transactionalId, producerId, TransactionState.ONGOING);
    expectListTransactions(new ListTransactionsOptions().filterProducerIds(singleton(producerId)), singletonMap(1, Collections.singletonList(listing)));
    DescribeTransactionsResult result = Mockito.mock(DescribeTransactionsResult.class);
    Mockito.when(result.description(transactionalId)).thenReturn(failedFuture(new TransactionalIdNotFoundException(transactionalId + " not found")));
    Mockito.when(admin.describeTransactions(singleton(transactionalId))).thenReturn(result);
    execute(args);
    assertNormalExit();
    assertHangingTransaction(topicPartition, producerId, producerEpoch, coordinatorEpoch, txnStartOffset, lastTimestamp);
}
Also used : TransactionalIdNotFoundException(org.apache.kafka.common.errors.TransactionalIdNotFoundException) ListTransactionsOptions(org.apache.kafka.clients.admin.ListTransactionsOptions) TopicPartition(org.apache.kafka.common.TopicPartition) DescribeTransactionsResult(org.apache.kafka.clients.admin.DescribeTransactionsResult) TransactionListing(org.apache.kafka.clients.admin.TransactionListing) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TransactionalIdNotFoundException (org.apache.kafka.common.errors.TransactionalIdNotFoundException)2 DescribeTransactionsResult (org.apache.kafka.clients.admin.DescribeTransactionsResult)1 ListTransactionsOptions (org.apache.kafka.clients.admin.ListTransactionsOptions)1 TransactionListing (org.apache.kafka.clients.admin.TransactionListing)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 TransactionalIdAuthorizationException (org.apache.kafka.common.errors.TransactionalIdAuthorizationException)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1