Skip to content

Commit

Permalink
Fixed missed ZK caching when fetching list of namespaces for a tenant (
Browse files Browse the repository at this point in the history
…apache#10594)

* Fixed missed ZK caching when fetching list of namespaces for a tenant

* Fixed generic object type

(cherry picked from commit 883e0d4)
  • Loading branch information
merlimat authored and eolivelli committed May 18, 2021
1 parent d001672 commit bcb849e
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

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;
Expand Down Expand Up @@ -239,15 +240,23 @@ protected List<String> getListOfNamespaces(String property) throws Exception {
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 {
Expand Down

0 comments on commit bcb849e

Please sign in to comment.