Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] [broker] fix replicated namespaces filter in filterAndUnloadMatchedNamespaceAsync #23100

Merged
merged 15 commits into from
Jul 31, 2024
Merged
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,8 @@ public void setNamespaceIsolationPolicy(
).thenCompose(nsIsolationPolicies -> {
nsIsolationPolicies.setPolicy(policyName, policyData);
return namespaceIsolationPolicies()
.setIsolationDataAsync(cluster, old -> nsIsolationPolicies.getPolicies());
}).thenCompose(__ -> filterAndUnloadMatchedNamespaceAsync(policyData))
.setIsolationDataAsync(cluster, old -> nsIsolationPolicies.getPolicies());
}).thenCompose(__ -> filterAndUnloadMatchedNamespaceAsync(cluster, policyData))
.thenAccept(__ -> {
log.info("[{}] Successful to update clusters/{}/namespaceIsolationPolicies/{}.",
clientAppId(), cluster, policyName);
Expand Down Expand Up @@ -758,7 +758,8 @@ public void setNamespaceIsolationPolicy(
/**
* Get matched namespaces; call unload for each namespaces.
*/
private CompletableFuture<Void> filterAndUnloadMatchedNamespaceAsync(NamespaceIsolationDataImpl policyData) {
private CompletableFuture<Void> filterAndUnloadMatchedNamespaceAsync(String cluster,
NamespaceIsolationDataImpl policyData) {
PulsarAdmin adminClient;
try {
adminClient = pulsar().getAdminClient();
Expand All @@ -771,10 +772,15 @@ private CompletableFuture<Void> filterAndUnloadMatchedNamespaceAsync(NamespaceIs
.map(tenant -> adminClient.namespaces().getNamespacesAsync(tenant));
return FutureUtil.waitForAll(completableFutureStream)
.thenApply(namespaces -> {
// if namespace match any policy regex, add it to ns list to be unload.
// Filter namespaces that have current cluster in their replication_clusters
// if namespace match any policy regex, add it to ns list to be unloaded.
return namespaces.stream()
.filter(namespaceName ->
policyData.getNamespaces().stream().anyMatch(namespaceName::matches))
.filter(namespaceName -> adminClient.namespaces()
.getPoliciesAsync(namespaceName)
.thenApply(policies -> policies.replication_clusters.contains(cluster))
.join())
lhotari marked this conversation as resolved.
Show resolved Hide resolved
.collect(Collectors.toList());
});
}).thenCompose(shouldUnloadNamespaces -> {
Expand Down
Loading