Technoboy- commented on code in PR #19013:
URL: https://github.com/apache/pulsar/pull/19013#discussion_r1055385473


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -2763,18 +2763,31 @@ private PositionImpl calculatePositionAckSet(boolean 
isExcluded, int batchSize,
 
     protected void internalGetMessageById(AsyncResponse asyncResponse, long 
ledgerId, long entryId,
                                               boolean authoritative) {
-        // will redirect if the topic not owned by current broker
-        validateTopicOwnershipAsync(topicName, authoritative)
+        CompletableFuture<Void> ret;
+        // If the topic name is a partition name, no need to get partition 
topic metadata again
+        if (!topicName.isPartitioned()) {
+            ret = getPartitionedTopicMetadataAsync(topicName, authoritative, 
false)
+                    .thenCompose(topicMetadata -> {
+                        if (topicMetadata.partitions > 0) {
+                            log.warn("[{}] Not supported getMessageById 
operation on partitioned-topic {}",
+                                    clientAppId(), topicName);
+                            asyncResponse.resume(new 
RestException(Status.METHOD_NOT_ALLOWED,
+                                    "GetMessageById is not allowed on 
partitioned-topic"));
+                        }
+                        return CompletableFuture.completedFuture(null);
+                    });
+        } else {
+            ret = CompletableFuture.completedFuture(null);
+        }
+        CompletableFuture<Void> future;
+        if (topicName.isGlobal()) {
+            future = ret.thenCompose(__ -> 
validateGlobalNamespaceOwnershipAsync(namespaceName));
+        } else {
+            future = CompletableFuture.completedFuture(null);
+        }
+
+        future.thenCompose(ignore -> validateTopicOwnershipAsync(topicName, 
authoritative))

Review Comment:
   I think it's better to do `validateGlobalNamespaceOwnershipAsync` first and 
then check topic metadata. 
   Please see `internalGetMessageIdByTimestampAsync`



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to