Skip to content

Commit

Permalink
issues apache#3264 fix partitioned-stats reporting errors not match (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
ambition119 authored and sijie committed Jan 13, 2019
1 parent 272725a commit 221e5c7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 221e5c7

Please sign in to comment.