You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2021/05/17 21:04:40 UTC
[pulsar] branch branch-2.7 updated: Fixed missed ZK caching when
fetching list of namespaces for a tenant (#10594)
This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.7 by this push:
new 883e0d4 Fixed missed ZK caching when fetching list of namespaces for a tenant (#10594)
883e0d4 is described below
commit 883e0d4c3af9dca749093a47c44899635517206b
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Mon May 17 14:03:07 2021 -0700
Fixed missed ZK caching when fetching list of namespaces for a tenant (#10594)
* Fixed missed ZK caching when fetching list of namespaces for a tenant
* Fixed generic object type
---
.../org/apache/pulsar/broker/admin/AdminResource.java | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
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 e1fdea1..5c87776 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
@@ -23,6 +23,7 @@ import static org.apache.pulsar.common.util.Codec.decode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.ArrayList;
@@ -239,15 +240,23 @@ public abstract class AdminResource extends PulsarWebResource {
List<String> namespaces = Lists.newArrayList();
// this will return a cluster in v1 and a namespace in v2
- for (String clusterOrNamespace : globalZk().getChildren(path(POLICIES, property), false)) {
+ for (String clusterOrNamespace : globalZkCache().getChildren(path(POLICIES, property))) {
// Then get the list of namespaces
try {
- final List<String> children = globalZk().getChildren(path(POLICIES, property, clusterOrNamespace), false);
+ final Set<String> children = globalZkCache().getChildren(path(POLICIES, property, clusterOrNamespace));
if (children == null || children.isEmpty()) {
String namespace = NamespaceName.get(property, clusterOrNamespace).toString();
- // if the length is 0 then this is probably a leftover cluster from namespace created
- // with the v1 admin format (prop/cluster/ns) and then deleted, so no need to add it to the list
- if (globalZk().getData(path(POLICIES, namespace), false, null).length != 0) {
+ Optional<Policies> znodeContent = globalZkCache().getData(path(POLICIES, namespace),
+ (key, content) -> {
+ try {
+ return ObjectMapperFactory.getThreadLocal().readValue(content, Policies.class);
+ } catch (IOException e) {
+ return null;
+ }
+ });
+ if (znodeContent.map(x -> x != null).orElse(false)) {
+ // if the length is 0 then this is probably a leftover cluster from namespace created
+ // with the v1 admin format (prop/cluster/ns) and then deleted, so no need to add it to the list
namespaces.add(namespace);
}
} else {