use of org.apache.pulsar.common.api.proto.CommandNewTxn in project pulsar by apache.
the class ServerCnx method handleNewTxn.
@Override
protected void handleNewTxn(CommandNewTxn command) {
final long requestId = command.getRequestId();
final TransactionCoordinatorID tcId = TransactionCoordinatorID.get(command.getTcId());
if (log.isDebugEnabled()) {
log.debug("Receive new txn request {} to transaction meta store {} from {}.", requestId, tcId, remoteAddress);
}
if (!checkTransactionEnableAndSendError(requestId)) {
return;
}
TransactionMetadataStoreService transactionMetadataStoreService = service.pulsar().getTransactionMetadataStoreService();
transactionMetadataStoreService.newTransaction(tcId, command.getTxnTtlSeconds()).whenComplete(((txnID, ex) -> {
if (ex == null) {
if (log.isDebugEnabled()) {
log.debug("Send response {} for new txn request {}", tcId.getId(), requestId);
}
ctx.writeAndFlush(Commands.newTxnResponse(requestId, txnID.getLeastSigBits(), txnID.getMostSigBits()));
} else {
ex = handleTxnException(ex, BaseCommand.Type.NEW_TXN.name(), requestId);
ctx.writeAndFlush(Commands.newTxnResponse(requestId, tcId.getId(), BrokerServiceException.getClientErrorCode(ex), ex.getMessage()));
transactionMetadataStoreService.handleOpFail(ex, tcId);
}
}));
}
Aggregations