You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/06/20 08:05:21 UTC

[GitHub] [pulsar] HQebupt opened a new pull request, #16141: [improve][broker][PIP-149]make getInternalStats method async

HQebupt opened a new pull request, #16141:
URL: https://github.com/apache/pulsar/pull/16141

   Master Issue: #14013 
   ### Motivation
   
   See #14365 
   
   ### Verifying this change
   
   Make sure that the change passes the CI checks.
   
   ### Does this pull request potentially affect one of the following parts:
   
   If `yes` was chosen, please highlight the changes
   
   - Dependencies (does it add or upgrade a dependency): (no)
   - The public API: (no)
   - The schema: (no)
   - The default values of configurations: (no)
   - The wire protocol: (no)
   - The rest endpoints: (no)
   - The admin cli options: (no)
   - Anything that affects deployment: (no)
   
   ### Documentation
   Check the box below and label this PR (if you have committer privilege).
   
   Need to update docs? 
   - [x] `doc-not-needed` 
   


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] AnonHxy commented on a diff in pull request #16141: [improve][broker][PIP-149]make getInternalStats method async

Posted by GitBox <gi...@apache.org>.
AnonHxy commented on code in PR #16141:
URL: https://github.com/apache/pulsar/pull/16141#discussion_r902408489


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/NonPersistentTopics.java:
##########
@@ -93,25 +92,32 @@ public void getPartitionedMetadata(
             @ApiResponse(code = 307, message = "Current broker doesn't serve the namespace of this topic"),
             @ApiResponse(code = 403, message = "Don't have admin permission"),
             @ApiResponse(code = 404, message = "Topic does not exist")})
-    public PersistentTopicInternalStats getInternalStats(@PathParam("property") String property,
-                                                         @PathParam("cluster") String cluster, @PathParam("namespace")
-                                                                     String namespace,
-                                                         @PathParam("topic") @Encoded String encodedTopic,
-                                                         @QueryParam("authoritative") @DefaultValue("false")
-                                                                     boolean authoritative,
-                                                         @QueryParam("metadata") @DefaultValue("false")
-                                                                     boolean metadata) {
+    public void getInternalStats(
+            @Suspended final AsyncResponse asyncResponse,
+            @PathParam("property") String property,
+            @PathParam("cluster") String cluster, @PathParam("namespace")
+                    String namespace,
+            @PathParam("topic") @Encoded String encodedTopic,
+            @QueryParam("authoritative") @DefaultValue("false")
+                    boolean authoritative,
+            @QueryParam("metadata") @DefaultValue("false")
+                    boolean metadata) {
         validateTopicName(property, cluster, namespace, encodedTopic);

Review Comment:
   Better to invoke `validateTopicName` like this. Otherwise if validate topic name failure, `resumeAsyncResponseExceptionally` will not be invoked.
   ```
    CompletableFuture.completedFuture(null)
               .thenRun(() -> validateTopicName(tenant, namespace, encodedTopic))
               .thenCompose(() -> validateTopicOwnershipAsync(topicName, authoritative))
               ....
   ```



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/NonPersistentTopics.java:
##########
@@ -93,25 +93,32 @@ public void getPartitionedMetadata(
             @ApiResponse(code = 307, message = "Current broker doesn't serve the namespace of this topic"),
             @ApiResponse(code = 403, message = "Don't have admin permission"),
             @ApiResponse(code = 404, message = "Topic does not exist")})
-    public PersistentTopicInternalStats getInternalStats(@PathParam("property") String property,
-                                                         @PathParam("cluster") String cluster, @PathParam("namespace")
-                                                                     String namespace,
-                                                         @PathParam("topic") @Encoded String encodedTopic,
-                                                         @QueryParam("authoritative") @DefaultValue("false")
-                                                                     boolean authoritative,
-                                                         @QueryParam("metadata") @DefaultValue("false")
-                                                                     boolean metadata) {
+    public void getInternalStats(
+            @Suspended final AsyncResponse asyncResponse,
+            @PathParam("property") String property,
+            @PathParam("cluster") String cluster, @PathParam("namespace")
+                    String namespace,
+            @PathParam("topic") @Encoded String encodedTopic,
+            @QueryParam("authoritative") @DefaultValue("false")
+                    boolean authoritative,
+            @QueryParam("metadata") @DefaultValue("false")

Review Comment:
   I think it'better to remain line98-104  unchanged.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] Technoboy- merged pull request #16141: [improve][broker][PIP-149]make getInternalStats method async

Posted by GitBox <gi...@apache.org>.
Technoboy- merged PR #16141:
URL: https://github.com/apache/pulsar/pull/16141


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] Technoboy- commented on a diff in pull request #16141: [improve][broker][PIP-149]make getInternalStats method async

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on code in PR #16141:
URL: https://github.com/apache/pulsar/pull/16141#discussion_r902213429


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -1208,24 +1207,24 @@ protected CompletableFuture<? extends TopicStats> internalGetStatsAsync(boolean
                         getEarliestTimeInBacklog));
     }
 
-    protected PersistentTopicInternalStats internalGetInternalStats(boolean authoritative, boolean metadata) {
+    protected CompletableFuture<PersistentTopicInternalStats> internalGetInternalStatsAsync(boolean authoritative,
+                                                                                            boolean metadata) {
+        CompletableFuture<Void> ret;
         if (topicName.isGlobal()) {
-            validateGlobalNamespaceOwnership(namespaceName);
-        }
-        validateTopicOwnership(topicName, authoritative);
-        validateTopicOperation(topicName, TopicOperation.GET_STATS);
-
-        Topic topic = getTopicReference(topicName);
-        try {
-            if (metadata) {
-                validateTopicOperation(topicName, TopicOperation.GET_METADATA);
-            }
-            return topic.getInternalStats(metadata).get();
-        } catch (Exception e) {
-            log.error("[{}] Failed to get internal stats for {}", clientAppId(), topicName, e);
-            throw new RestException(Status.INTERNAL_SERVER_ERROR,
-                    (e instanceof ExecutionException) ? e.getCause().getMessage() : e.getMessage());
+            ret = validateGlobalNamespaceOwnershipAsync(namespaceName);
+        } else {
+            ret = CompletableFuture.completedFuture(null);
         }
+        return ret.thenCompose(__ -> validateTopicOwnershipAsync(topicName, authoritative))
+                .thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.GET_STATS))
+                .thenCompose(__ -> {
+                    if (metadata) {
+                        return validateTopicOperationAsync(topicName, TopicOperation.GET_METADATA);
+                    }
+                    return null;

Review Comment:
   return `CompletableFuture.completedFuture(null)`;



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] HQebupt commented on a diff in pull request #16141: [improve][broker][PIP-149]make getInternalStats method async

Posted by GitBox <gi...@apache.org>.
HQebupt commented on code in PR #16141:
URL: https://github.com/apache/pulsar/pull/16141#discussion_r902417914


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/NonPersistentTopics.java:
##########
@@ -93,25 +92,32 @@ public void getPartitionedMetadata(
             @ApiResponse(code = 307, message = "Current broker doesn't serve the namespace of this topic"),
             @ApiResponse(code = 403, message = "Don't have admin permission"),
             @ApiResponse(code = 404, message = "Topic does not exist")})
-    public PersistentTopicInternalStats getInternalStats(@PathParam("property") String property,
-                                                         @PathParam("cluster") String cluster, @PathParam("namespace")
-                                                                     String namespace,
-                                                         @PathParam("topic") @Encoded String encodedTopic,
-                                                         @QueryParam("authoritative") @DefaultValue("false")
-                                                                     boolean authoritative,
-                                                         @QueryParam("metadata") @DefaultValue("false")
-                                                                     boolean metadata) {
+    public void getInternalStats(
+            @Suspended final AsyncResponse asyncResponse,
+            @PathParam("property") String property,
+            @PathParam("cluster") String cluster, @PathParam("namespace")
+                    String namespace,
+            @PathParam("topic") @Encoded String encodedTopic,
+            @QueryParam("authoritative") @DefaultValue("false")
+                    boolean authoritative,
+            @QueryParam("metadata") @DefaultValue("false")
+                    boolean metadata) {
         validateTopicName(property, cluster, namespace, encodedTopic);

Review Comment:
   If the `validateTopicName` throws RestException, the method can throw it out.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] HQebupt commented on pull request #16141: [improve][broker][PIP-149]make getInternalStats method async

Posted by GitBox <gi...@apache.org>.
HQebupt commented on PR #16141:
URL: https://github.com/apache/pulsar/pull/16141#issuecomment-1160420755

   /pulsarbot rerun-failure-checks


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] HQebupt commented on pull request #16141: [improve][broker][PIP-149]make getInternalStats method async

Posted by GitBox <gi...@apache.org>.
HQebupt commented on PR #16141:
URL: https://github.com/apache/pulsar/pull/16141#issuecomment-1161703813

   /pulsarbot rerun-failure-checks


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] HQebupt commented on pull request #16141: [improve][broker][PIP-149]make getInternalStats method async

Posted by GitBox <gi...@apache.org>.
HQebupt commented on PR #16141:
URL: https://github.com/apache/pulsar/pull/16141#issuecomment-1162520661

   > Do we have tests to verify this change?
   
   Many test cases already test this method, such as `AdminApi2Test.java` `AdminApiTest.java` `ReaderTest`. @mattisonchao 


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org