gaoran10 commented on a change in pull request #7552:
URL: https://github.com/apache/pulsar/pull/7552#discussion_r462457051
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -1674,40 +1687,134 @@ protected void
handleAddPartitionToTxn(PulsarApi.CommandAddPartitionToTxn comman
@Override
protected void handleEndTxn(PulsarApi.CommandEndTxn command) {
- TxnStatus newStatus = null;
+ TxnID txnID = new TxnID(command.getTxnidMostBits(),
command.getTxnidLeastBits());
+ final TxnStatus newStatus;
switch (command.getTxnAction()) {
case COMMIT:
newStatus = TxnStatus.COMMITTING;
break;
case ABORT:
newStatus = TxnStatus.ABORTING;
break;
+ default:
+ UnsupportedTxnActionException exception =
+ new UnsupportedTxnActionException(txnID,
command.getTxnAction());
+ log.error(exception.getMessage());
+
ctx.writeAndFlush(Commands.newEndTxnResponse(command.getRequestId(),
txnID.getMostSigBits(),
+ BrokerServiceException.getClientErrorCode(exception),
exception.getMessage()));
+ return;
}
- TxnID txnID = new TxnID(command.getTxnidMostBits(),
command.getTxnidLeastBits());
if (log.isDebugEnabled()) {
log.debug("Receive end txn by {} request {} from {} with txnId
{}", newStatus, command.getRequestId(), remoteAddress, txnID);
}
+ final long requestId = command.getRequestId();
service.pulsar().getTransactionMetadataStoreService().updateTxnStatus(txnID,
newStatus, TxnStatus.OPEN)
- .whenComplete((v, ex) -> {
- if (ex == null) {
- if (log.isDebugEnabled()) {
- log.debug("Send response success for end txn request
{}", command.getRequestId());
- }
-
ctx.writeAndFlush(Commands.newEndTxnResponse(command.getRequestId(),
+ .thenRun(() -> {
+ if (log.isDebugEnabled()) {
+ log.debug("Send response success for end txn request {}",
command.getRequestId());
+ }
+ updateTBStatus(txnID, newStatus).thenRun(() -> {
+ service.pulsar().getTransactionMetadataStoreService()
+ .updateTxnStatus(txnID, TxnStatus.COMMITTED,
TxnStatus.COMMITTING);
+ ctx.writeAndFlush(Commands.newEndTxnResponse(requestId,
txnID.getLeastSigBits(), txnID.getMostSigBits()));
+ }).exceptionally(throwable -> {
+ log.error("Failed to get txn `" + txnID + "` txnMeta.",
throwable);
+ ctx.writeAndFlush(Commands.newEndTxnResponse(requestId,
txnID.getMostSigBits(),
+
BrokerServiceException.getClientErrorCode(throwable), throwable.getMessage()));
+ return null;
+ });
+ }).exceptionally(throwable -> {
+ if (log.isDebugEnabled()) {
+ log.debug("Send response error for end txn request {}",
command.getRequestId());
+ }
+
ctx.writeAndFlush(Commands.newEndTxnResponse(command.getRequestId(),
txnID.getMostSigBits(),
+ BrokerServiceException.getClientErrorCode(throwable),
throwable.getMessage()));
+ return null;
+ });
Review comment:
Yes, I'll fix this.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]