Skip to content

Commit

Permalink
[Issue 13854][broker] Fix call sync method in async rest api for inte…
Browse files Browse the repository at this point in the history
…rnalGetPartitionedStats (apache#13886)

Master Issue: apache#13854

### Motivation


Avoid call sync method in async rest API for PersistentTopicsBase#internalGetPartitionedStats.
  • Loading branch information
gaozhangmin authored Jan 26, 2022
1 parent 35f0e13 commit 67caae7
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1338,17 +1338,14 @@ public void getInfoFailed(ManagedLedgerException exception, Object ctx) {
protected void internalGetPartitionedStats(AsyncResponse asyncResponse, boolean authoritative, boolean perPartition,
boolean getPreciseBacklog, boolean subscriptionBacklogSize,
boolean getEarliestTimeInBacklog) {
CompletableFuture<Void> future;
if (topicName.isGlobal()) {
try {
validateGlobalNamespaceOwnership(namespaceName);
} catch (Exception e) {
log.error("[{}] Failed to get partitioned stats for {}", clientAppId(), topicName, e);
resumeAsyncResponseExceptionally(asyncResponse, e);
return;
}
future = validateGlobalNamespaceOwnershipAsync(namespaceName);
} else {
future = CompletableFuture.completedFuture(null);
}
getPartitionedTopicMetadataAsync(topicName,
authoritative, false).thenAccept(partitionMetadata -> {
future.thenCompose(__ -> getPartitionedTopicMetadataAsync(topicName,
authoritative, false)).thenAccept(partitionMetadata -> {
if (partitionMetadata.partitions == 0) {
asyncResponse.resume(new RestException(Status.NOT_FOUND, "Partitioned Topic not found"));
return;
Expand Down Expand Up @@ -1405,8 +1402,9 @@ protected void internalGetPartitionedStats(AsyncResponse asyncResponse, boolean
return null;
});
}).exceptionally(ex -> {
log.error("[{}] Failed to get partitioned stats for {}", clientAppId(), topicName, ex);
resumeAsyncResponseExceptionally(asyncResponse, ex);
Throwable cause = FutureUtil.unwrapCompletionException(ex);
log.error("[{}] Failed to get partitioned internal stats for {}", clientAppId(), topicName, cause);
resumeAsyncResponseExceptionally(asyncResponse, cause);
return null;
});
}
Expand Down

0 comments on commit 67caae7

Please sign in to comment.