eolivelli commented on a change in pull request #10322:
URL: https://github.com/apache/pulsar/pull/10322#discussion_r618360367



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -1859,26 +1860,39 @@ protected void 
handleEndTxnOnPartition(CommandEndTxnOnPartition command) {
         final int txnAction = command.getTxnAction().getValue();
         TxnID txnID = new TxnID(command.getTxnidMostBits(), 
command.getTxnidLeastBits());
 
-        
service.getTopics().get(TopicName.get(topic).toString()).whenComplete((optionalTopic,
 t) -> {
-            if (!optionalTopic.isPresent()) {
-                ctx.writeAndFlush(Commands.newEndTxnOnPartitionResponse(
-                        requestId, ServerError.TopicNotFound,
-                        "Topic " + topic + " is not found."));
-                return;
-            }
-            optionalTopic.get().endTxn(txnID, txnAction, 
command.getTxnidLeastBitsOfLowWatermark())
-                .whenComplete((ignored, throwable) -> {
-                    if (throwable != null) {
-                        log.error("Handle endTxnOnPartition {} failed.", 
topic, throwable);
-                        
ctx.writeAndFlush(Commands.newEndTxnOnPartitionResponse(
-                                requestId, 
BrokerServiceException.getClientErrorCode(throwable),
-                                throwable.getMessage()));
-                        return;
-                    }
-                    
ctx.writeAndFlush(Commands.newEndTxnOnPartitionResponse(requestId,
-                            txnID.getLeastSigBits(), txnID.getMostSigBits()));
-                });
-        });
+        if (log.isDebugEnabled()) {
+            log.debug("[{}] handleEndTxnOnPartition txnId: [{}], txnAction: 
[{}]", topic,
+                    txnID, txnAction);
+        }
+        CompletableFuture<Optional<Topic>> topicFuture = 
service.getTopics().get(TopicName.get(topic).toString());
+        if (topicFuture != null) {
+            topicFuture.whenComplete((optionalTopic, t) -> {
+                if (!optionalTopic.isPresent()) {
+                    ctx.writeAndFlush(Commands.newEndTxnOnPartitionResponse(
+                            requestId, ServerError.ServiceNotReady,
+                            "Topic " + topic + " is not found."));
+                    return;
+                }
+                optionalTopic.get().endTxn(txnID, txnAction, 
command.getTxnidLeastBitsOfLowWatermark())
+                        .whenComplete((ignored, throwable) -> {
+                            if (throwable != null) {
+                                log.error("Handle endTxnOnPartition {} 
failed.", topic, throwable);
+                                
ctx.writeAndFlush(Commands.newEndTxnOnPartitionResponse(
+                                        requestId, 
BrokerServiceException.getClientErrorCode(throwable),
+                                        throwable.getMessage()));
+                                return;
+                            }
+                            
ctx.writeAndFlush(Commands.newEndTxnOnPartitionResponse(requestId,
+                                    txnID.getLeastSigBits(), 
txnID.getMostSigBits()));
+                        });
+            });
+        } else {
+            log.error("The topic {} is not exist in broker.", topic);

Review comment:
       _The topic {} is not exist in broker."_ -> _The topic {} does not exist 
in broker."_
   
   (here and below)




-- 
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]


Reply via email to