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/09/08 07:48:12 UTC

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

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


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TransactionsBase.java:
##########
@@ -69,6 +71,37 @@
 @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;
+        }
+        admin.lookups()
+                .lookupPartitionedTopicAsync(SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN.getPartitionedTopicName())
+                .thenAccept(map -> {
+                    if (map.isEmpty()) {
+                        asyncResponse.resume(new RestException(Response.Status.NOT_FOUND,
+                                "Transaction coordinator not found"));

Review Comment:
   This is not actually a "problem" to be reported as 404.
   we can simply return an empty result.
   
   how can we get to this situation ? when the partitions are not loaded by any broker ?



##########
pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/Transactions.java:
##########
@@ -34,6 +35,21 @@
 
 public interface Transactions {
 
+    /**
+     * List transaction coordinators.
+     *
+     * @return the transaction coordinators list.
+     */
+    Map<Integer, TransactionCoordinatorInfo> listTransactionCoordinators() throws PulsarAdminException;

Review Comment:
   question (not a request for a change):
   why returning a Map and not a List ?
   I don't think that returning a Map has a particular advantage over returning a List



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionTest.java:
##########
@@ -102,6 +103,18 @@ protected void cleanup() throws Exception {
         super.internalCleanup();
     }
 
+    @Test(timeOut = 20000)
+    public void testListTransactionCoordinators() throws Exception {
+        initTransaction(4);
+        final Map<Integer, TransactionCoordinatorInfo> result = admin
+                .transactions().listTransactionCoordinatorsAsync().get();

Review Comment:
   should we use Awaitility here ?
   are we guaranteed that when we reach this point all the partitions are loaded ?



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TransactionsBase.java:
##########
@@ -69,6 +71,37 @@
 @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;
+        }
+        admin.lookups()
+                .lookupPartitionedTopicAsync(SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN.getPartitionedTopicName())
+                .thenAccept(map -> {
+                    if (map.isEmpty()) {
+                        asyncResponse.resume(new RestException(Response.Status.NOT_FOUND,
+                                "Transaction coordinator not found"));
+                        return;
+                    }
+                    Map<Integer, TransactionCoordinatorInfo> result = new HashMap<>();
+                    map.forEach((topicPartition, brokerServiceUrl) -> {

Review Comment:
   I think that we should return something also for the partitions that are not currently "loaded"



##########
pulsar-client-admin-api/src/main/java/org/apache/pulsar/common/policies/data/TransactionCoordinatorInfo.java:
##########
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.common.policies.data;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+/**
+ * Transaction coordinator information.
+ */
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+public class TransactionCoordinatorInfo {
+    private String brokerServiceUrl;

Review Comment:
   I would add the id as well, it would make it easier further processing downstream



-- 
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