You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/10/25 08:56:34 UTC

[GitHub] [pulsar] congbobo184 commented on a diff in pull request #17522: [improve][transactions] Add command to list transaction coordinators

congbobo184 commented on code in PR #17522:
URL: https://github.com/apache/pulsar/pull/17522#discussion_r1004166381


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionTest.java:
##########
@@ -109,6 +110,19 @@ protected void cleanup() throws Exception {
         super.internalCleanup();
     }
 
+    @Test(timeOut = 20000)
+    public void testListTransactionCoordinators() throws Exception {
+        initTransaction(4);
+        final List<TransactionCoordinatorInfo> result = admin
+                .transactions().listTransactionCoordinatorsAsync().get();
+        System.out.println("result" + result);

Review Comment:
   delete



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TransactionsBase.java:
##########
@@ -68,6 +70,49 @@
 @Slf4j
 public abstract class TransactionsBase extends AdminResource {
 
+    protected void internalListCoordinators(AsyncResponse asyncResponse) {
+        final PulsarAdmin admin;
+        try {
+            admin = pulsar().getAdminClient();
+        } catch (PulsarServerException ex) {
+            asyncResponse.resume(new RestException(ex));
+            return;
+        }
+        Map<Integer, TransactionCoordinatorInfo> result = new HashMap<>();
+        admin.lookups()
+                .lookupPartitionedTopicAsync(SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN.getPartitionedTopicName())
+                .thenCompose(map -> {
+                    map.forEach((topicPartition, brokerServiceUrl) -> {
+                        final int coordinatorId = TopicName.getPartitionIndex(topicPartition);
+                        result.put(coordinatorId, new TransactionCoordinatorInfo(coordinatorId, brokerServiceUrl));
+                    });
+
+                    return getPulsarResources()
+                            .getTopicResources()
+                            .getExistingPartitions(SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN);
+                })
+                .thenAccept(allPartitions -> {
+                    allPartitions
+                            .stream()
+                            .filter(partition -> SystemTopicNames
+                                    .isTransactionCoordinatorAssign(TopicName.get(partition)))
+                            .forEach(partition -> {
+                                final int coordinatorId = TopicName.getPartitionIndex(partition);
+                                if (!result.containsKey(coordinatorId)) {
+                                    result.put(coordinatorId,
+                                            new TransactionCoordinatorInfo(coordinatorId, null));
+                                }
+                            });
+                    asyncResponse.resume(result.values());

Review Comment:
   why do we need to check again?



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org