Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -153,13 +153,16 @@ public CompletableFuture<Void> setPoliciesAsync(NamespaceName ns, Function<Polic
}

public static boolean pathIsFromNamespace(String path) {
return path.startsWith(BASE_POLICIES_PATH + "/")
&& path.substring(BASE_POLICIES_PATH.length() + 1).contains("/");
return pathHasNestedSegmentUnderRoot(path, BASE_POLICIES_PATH);
}

public static boolean pathIsNamespaceLocalPolicies(String path) {
return path.startsWith(LOCAL_POLICIES_ROOT + "/")
&& path.substring(LOCAL_POLICIES_ROOT.length() + 1).contains("/");
return pathHasNestedSegmentUnderRoot(path, LOCAL_POLICIES_ROOT);
}

private static boolean pathHasNestedSegmentUnderRoot(String path, String rootPath) {
return path.startsWith(rootPath + "/")
&& path.substring(rootPath.length() + 1).contains("/");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,18 @@ public CompletableFuture<Boolean> persistentTopicExists(TopicName topic) {
}

public CompletableFuture<Void> clearNamespacePersistence(NamespaceName ns) {
String path = MANAGED_LEDGER_PATH + "/" + ns;
log.info().attr("namespace", ns).attr("path", path).log("Clearing namespace persistence for namespace: , path");
return store.deleteIfExists(path, Optional.empty());
return clearManagedLedgerPathIfExistsAsync(ns, MANAGED_LEDGER_PATH + "/" + ns,
"Clearing namespace persistence for namespace: , path");
}

public CompletableFuture<Void> clearDomainPersistence(NamespaceName ns) {
String path = MANAGED_LEDGER_PATH + "/" + ns + "/persistent";
log.info().attr("namespace", ns).attr("path", path).log("Clearing domain persistence for namespace: , path");
return clearManagedLedgerPathIfExistsAsync(ns, MANAGED_LEDGER_PATH + "/" + ns + "/persistent",
"Clearing domain persistence for namespace: , path");
}

private CompletableFuture<Void> clearManagedLedgerPathIfExistsAsync(
NamespaceName ns, String path, String logMessage) {
log.info().attr("namespace", ns).attr("path", path).log(logMessage);
Comment on lines -93 to +104
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactoring isn't that useful since the method name clearManagedLedgerPathIfExistsAsync isn't accurate. The path is a MetadataStore path, exactly what store.deleteIfExists already handles.
Eliminating duplication for the log message isn't useful since it just results in harder readability.

return store.deleteIfExists(path, Optional.empty());
}

Expand Down