Skip to content

Commit

Permalink
[improve][broker][PIP-149]make deletePersistence method async in Name…
Browse files Browse the repository at this point in the history
…spaces (#17206)

* make deletePersistence method async in Namespaces

* update comment

* remove irrelevant import

* reduce unnecessary exceptions

* remove redundant exception log printing logic

Co-authored-by: huangzegui <[email protected]>
  • Loading branch information
HuangZeGui and huangzegui authored Aug 30, 2022
1 parent 19aea2a commit 8140080
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1543,10 +1543,10 @@ protected void internalSetRetention(RetentionPolicies retention) {
}
}

protected void internalDeletePersistence() {
validateNamespacePolicyOperation(namespaceName, PolicyName.PERSISTENCE, PolicyOperation.WRITE);
validatePoliciesReadOnlyAccess();
doUpdatePersistence(null);
protected CompletableFuture<Void> internalDeletePersistenceAsync() {
return validateNamespacePolicyOperationAsync(namespaceName, PolicyName.PERSISTENCE, PolicyOperation.WRITE)
.thenCompose(__ -> validatePoliciesReadOnlyAccessAsync())
.thenCompose(__ -> doUpdatePersistenceAsync(null));
}

protected void internalSetPersistence(PersistencePolicies persistence) {
Expand All @@ -1572,6 +1572,15 @@ private void doUpdatePersistence(PersistencePolicies persistence) {
}
}

private CompletableFuture<Void> doUpdatePersistenceAsync(PersistencePolicies persistence) {
return updatePoliciesAsync(namespaceName, policies -> {
policies.persistence = persistence;
return policies;
}).thenAccept(__ -> log.info("[{}] Successfully updated persistence configuration: namespace={}, map={}",
clientAppId(), namespaceName, persistence)
);
}

protected void internalClearNamespaceBacklog(AsyncResponse asyncResponse, boolean authoritative) {
validateNamespaceOperation(namespaceName, NamespaceOperation.CLEAR_BACKLOG);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,10 +1255,17 @@ public void setPersistence(@PathParam("tenant") String tenant, @PathParam("names
@Path("/{tenant}/{namespace}/persistence")
@ApiOperation(value = "Delete the persistence configuration for all topics on a namespace")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") })
public void deletePersistence(@PathParam("tenant") String tenant,
@PathParam("namespace") String namespace) {
public void deletePersistence(@Suspended final AsyncResponse asyncResponse, @PathParam("tenant") String tenant,
@PathParam("namespace") String namespace) {
validateNamespaceName(tenant, namespace);
internalDeletePersistence();
internalDeletePersistenceAsync()
.thenAccept(__ -> asyncResponse.resume(Response.noContent().build()))
.exceptionally(ex -> {
log.error("[{}] Failed to delete the persistence for a namespace {}", clientAppId(), namespaceName,
ex);
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}

@POST
Expand Down

0 comments on commit 8140080

Please sign in to comment.