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 2019/01/13 01:26:38 UTC

[GitHub] sijie closed pull request #3339: issues #3264 fix partitioned-stats reporting errors not match

sijie closed pull request #3339: issues #3264 fix partitioned-stats reporting errors not match
URL: https://github.com/apache/pulsar/pull/3339
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
index 6dc2e40792..b47fda8308 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
@@ -70,6 +70,7 @@
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper.States;
+import org.apache.zookeeper.data.Stat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -109,6 +110,14 @@ protected void zkCreateOptimistic(String path, byte[] content) throws Exception
         ZkUtils.createFullPathOptimistic(globalZk(), path, content, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
     }
 
+    protected boolean zkPathExists(String path) throws KeeperException, InterruptedException {
+        Stat stat = globalZk().exists(path, false);
+        if (null != stat) {
+            return true;
+        }
+        return false;
+    }
+
     /**
      * Get the domain of the topic (whether it's persistent or non-persistent)
      */
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
index aea5a169bf..e6df76df60 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
@@ -643,7 +643,19 @@ protected PartitionedTopicStats internalGetPartitionedStats(boolean authoritativ
             }
         } catch (PulsarAdminException e) {
             if (e.getStatusCode() == Status.NOT_FOUND.getStatusCode()) {
-                throw new RestException(Status.NOT_FOUND, "Internal topics have not been generated yet");
+
+                String path = ZkAdminPaths.partitionedTopicPath(topicName);
+                try {
+                    boolean zkPathExists = zkPathExists(path);
+                    if (zkPathExists) {
+                        stats.partitions.put(topicName.toString(), new TopicStats());
+                    } else {
+                        throw new RestException(Status.NOT_FOUND, "Internal topics have not been generated yet");
+                    }
+                } catch (KeeperException | InterruptedException exception) {
+                    throw new RestException(e);
+                }
+
             } else {
                 throw new RestException(e);
             }
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
index 7a650897cc..837db22100 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
@@ -796,15 +796,12 @@ public void partitionedTopics(String topicName) throws Exception {
         assertEquals(admin.topics().getPartitionedTopicMetadata("persistent://prop-xyz/ns1/ds2").partitions,
                 0);
 
-        try {
-            admin.topics().getPartitionedStats(partitionedTopicName, false);
-            fail("should have failed");
-        } catch (PulsarAdminException e) {
-            // ok
-            assertEquals(e.getStatusCode(), Status.NOT_FOUND.getStatusCode());
-        } catch (Exception e) {
-            fail(e.getMessage());
-        }
+        // check the getPartitionedStats for PartitionedTopic returns only partitions metadata, and no partitions info
+        assertEquals(admin.topics().getPartitionedTopicMetadata(partitionedTopicName).partitions,
+                admin.topics().getPartitionedStats(partitionedTopicName,false).metadata.partitions);
+
+        assertEquals(admin.topics().getPartitionedStats(partitionedTopicName, false).partitions.size(),
+                0);
 
         try {
             admin.topics().getSubscriptions(partitionedTopicName);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services