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"));
}
}
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);
}
Aggregations