mattisonchao commented on code in PR #15017:
URL: https://github.com/apache/pulsar/pull/15017#discussion_r843877969
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TransactionsBase.java:
##########
@@ -67,216 +67,97 @@
protected void internalGetCoordinatorStats(AsyncResponse asyncResponse,
boolean authoritative,
Integer coordinatorId) {
- if (pulsar().getConfig().isTransactionCoordinatorEnabled()) {
- if (coordinatorId != null) {
-
validateTopicOwnership(TopicName.TRANSACTION_COORDINATOR_ASSIGN.getPartition(coordinatorId),
- authoritative);
- TransactionMetadataStore transactionMetadataStore =
-
pulsar().getTransactionMetadataStoreService().getStores()
-
.get(TransactionCoordinatorID.get(coordinatorId));
- if (transactionMetadataStore == null) {
- asyncResponse.resume(new RestException(NOT_FOUND,
- "Transaction coordinator not found! coordinator id
: " + coordinatorId));
+ if (coordinatorId != null) {
+
validateTopicOwnership(TopicName.TRANSACTION_COORDINATOR_ASSIGN.getPartition(coordinatorId),
+ authoritative);
+ TransactionMetadataStore transactionMetadataStore =
+ pulsar().getTransactionMetadataStoreService().getStores()
+ .get(TransactionCoordinatorID.get(coordinatorId));
+ if (transactionMetadataStore == null) {
+ asyncResponse.resume(new RestException(NOT_FOUND,
+ "Transaction coordinator not found! coordinator id : "
+ coordinatorId));
+ return;
+ }
+
asyncResponse.resume(transactionMetadataStore.getCoordinatorStats());
+ } else {
+
getPartitionedTopicMetadataAsync(TopicName.TRANSACTION_COORDINATOR_ASSIGN,
+ false, false).thenAccept(partitionMetadata -> {
+ if (partitionMetadata.partitions == 0) {
+ asyncResponse.resume(new
RestException(Response.Status.NOT_FOUND,
+ "Transaction coordinator not found"));
return;
}
-
asyncResponse.resume(transactionMetadataStore.getCoordinatorStats());
- } else {
-
getPartitionedTopicMetadataAsync(TopicName.TRANSACTION_COORDINATOR_ASSIGN,
- false, false).thenAccept(partitionMetadata -> {
- if (partitionMetadata.partitions == 0) {
- asyncResponse.resume(new
RestException(Response.Status.NOT_FOUND,
- "Transaction coordinator not found"));
+ List<CompletableFuture<TransactionCoordinatorStats>>
transactionMetadataStoreInfoFutures =
+ Lists.newArrayList();
+ for (int i = 0; i < partitionMetadata.partitions; i++) {
+ try {
+ transactionMetadataStoreInfoFutures
+
.add(pulsar().getAdminClient().transactions().getCoordinatorStatsByIdAsync(i));
+ } catch (PulsarServerException e) {
+ asyncResponse.resume(new RestException(e));
return;
}
- List<CompletableFuture<TransactionCoordinatorStats>>
transactionMetadataStoreInfoFutures =
- Lists.newArrayList();
- for (int i = 0; i < partitionMetadata.partitions; i++) {
+ }
+ Map<Integer, TransactionCoordinatorStats> stats = new
HashMap<>();
+
FutureUtil.waitForAll(transactionMetadataStoreInfoFutures).whenComplete((result,
e) -> {
+ if (e != null) {
+ asyncResponse.resume(new RestException(e));
+ return;
+ }
+
+ for (int i = 0; i <
transactionMetadataStoreInfoFutures.size(); i++) {
try {
- transactionMetadataStoreInfoFutures
-
.add(pulsar().getAdminClient().transactions().getCoordinatorStatsByIdAsync(i));
- } catch (PulsarServerException e) {
- asyncResponse.resume(new RestException(e));
+ stats.put(i,
transactionMetadataStoreInfoFutures.get(i).get());
Review Comment:
use ``join`` to avoid catch checked exceptions?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]