void fail(RuntimeException e) { result.setError(e); result.done(); }
void fatalError(RuntimeException e) { result.setError(e); transitionToFatalError(e); result.done(); }
void abortableError(RuntimeException e) { result.setError(e); transitionToAbortableError(e); result.done(); }
synchronized TxnRequestHandler nextRequestHandler(boolean hasIncompleteBatches) { if (!newPartitionsInTransaction.isEmpty()) enqueueRequest(addPartitionsToTransactionHandler()); TxnRequestHandler nextRequestHandler = pendingRequests.peek(); if (nextRequestHandler == null) return null; // Do not send the EndTxn until all batches have been flushed if (nextRequestHandler.isEndTxn() && hasIncompleteBatches) return null; pendingRequests.poll(); if (maybeTerminateRequestWithError(nextRequestHandler)) { log.trace("Not sending transactional request {} because we are in an error state", nextRequestHandler.requestBuilder()); return null; } if (nextRequestHandler.isEndTxn() && !transactionStarted) { nextRequestHandler.result.done(); if (currentState != State.FATAL_ERROR) { log.debug("Not sending EndTxn for completed transaction since no partitions " + "or offsets were successfully added"); completeTransaction(); } nextRequestHandler = pendingRequests.poll(); } if (nextRequestHandler != null) log.trace("Request {} dequeued for sending", nextRequestHandler.requestBuilder()); return nextRequestHandler; }
partitionsInTransaction.addAll(partitions); transactionStarted = true; result.done();
pendingTxnOffsetCommits.clear(); } else if (pendingTxnOffsetCommits.isEmpty()) { result.done(); } else {
@Override public void handleResponse(AbstractResponse response) { FindCoordinatorResponse findCoordinatorResponse = (FindCoordinatorResponse) response; Errors error = findCoordinatorResponse.error(); if (error == Errors.NONE) { Node node = findCoordinatorResponse.node(); switch (builder.coordinatorType()) { case GROUP: consumerGroupCoordinator = node; break; case TRANSACTION: transactionCoordinator = node; } result.done(); } else if (error == Errors.COORDINATOR_NOT_AVAILABLE) { reenqueue(); } else if (error == Errors.TRANSACTIONAL_ID_AUTHORIZATION_FAILED) { fatalError(error.exception()); } else if (findCoordinatorResponse.error() == Errors.GROUP_AUTHORIZATION_FAILED) { abortableError(new GroupAuthorizationException(builder.coordinatorKey())); } else { fatalError(new KafkaException(String.format("Could not find a coordinator with type %s with key %s due to" + "unexpected error: %s", builder.coordinatorType(), builder.coordinatorKey(), findCoordinatorResponse.error().message()))); } } }
@Override public void handleResponse(AbstractResponse response) { InitProducerIdResponse initProducerIdResponse = (InitProducerIdResponse) response; Errors error = initProducerIdResponse.error(); if (error == Errors.NONE) { ProducerIdAndEpoch producerIdAndEpoch = new ProducerIdAndEpoch(initProducerIdResponse.producerId(), initProducerIdResponse.epoch()); setProducerIdAndEpoch(producerIdAndEpoch); transitionTo(State.READY); lastError = null; result.done(); } else if (error == Errors.NOT_COORDINATOR || error == Errors.COORDINATOR_NOT_AVAILABLE) { lookupCoordinator(FindCoordinatorRequest.CoordinatorType.TRANSACTION, transactionalId); reenqueue(); } else if (error == Errors.COORDINATOR_LOAD_IN_PROGRESS || error == Errors.CONCURRENT_TRANSACTIONS) { reenqueue(); } else if (error == Errors.TRANSACTIONAL_ID_AUTHORIZATION_FAILED) { fatalError(error.exception()); } else { fatalError(new KafkaException("Unexpected error in InitProducerIdResponse; " + error.message())); } } }
@Override public void handleResponse(AbstractResponse response) { EndTxnResponse endTxnResponse = (EndTxnResponse) response; Errors error = endTxnResponse.error(); if (error == Errors.NONE) { completeTransaction(); result.done(); } else if (error == Errors.COORDINATOR_NOT_AVAILABLE || error == Errors.NOT_COORDINATOR) { lookupCoordinator(FindCoordinatorRequest.CoordinatorType.TRANSACTION, transactionalId); reenqueue(); } else if (error == Errors.COORDINATOR_LOAD_IN_PROGRESS || error == Errors.CONCURRENT_TRANSACTIONS) { reenqueue(); } else if (error == Errors.INVALID_PRODUCER_EPOCH) { fatalError(error.exception()); } else if (error == Errors.TRANSACTIONAL_ID_AUTHORIZATION_FAILED) { fatalError(error.exception()); } else if (error == Errors.INVALID_TXN_STATE) { fatalError(error.exception()); } else { fatalError(new KafkaException("Unhandled error in EndTxnResponse: " + error.message())); } } }