This is an automated email from the ASF dual-hosted git repository.

bogong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 74df9478945 [fix][Transaction] Fix transaction admin redirect get 500 
due to getCause (#14965)
74df9478945 is described below

commit 74df947894548ba6e610a71ec03a9d87bce59f35
Author: Xiangying Meng <[email protected]>
AuthorDate: Fri Apr 8 15:59:50 2022 +0800

    [fix][Transaction] Fix transaction admin redirect get 500 due to getCause 
(#14965)
    
    ### Motivation
    Transaction admin `getCoordinatorInternalStats`  add a getCause when try 
catch.
    Which make redirect fail.
    
    * Exception is thrown by `validateTopicOwnership`, sync() call get() in
      `sync(()-> validateTopicOwnershipAsync(topicName, authoritative));`
    * Exception already got cause by in `validateTopicOwnershipAsync`
    ### Modifications
    Delete get cause if not ExecutionException
---
 .../pulsar/broker/admin/impl/TransactionsBase.java |  2 +-
 .../v3/AdminApiTransactionMultiBrokerTest.java     | 67 ++++++++++++++++++++++
 .../broker/admin/v3/AdminApiTransactionTest.java   |  1 +
 3 files changed, 69 insertions(+), 1 deletion(-)

diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TransactionsBase.java
 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TransactionsBase.java
index b225cd2e266..8eff6815404 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TransactionsBase.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TransactionsBase.java
@@ -373,7 +373,7 @@ public abstract class TransactionsBase extends 
AdminResource {
                         "Broker don't use MLTransactionMetadataStore!"));
             }
         } catch (Exception e) {
-            asyncResponse.resume(new RestException(e.getCause()));
+            resumeAsyncResponseExceptionally(asyncResponse, e);
         }
     }
 
diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionMultiBrokerTest.java
 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionMultiBrokerTest.java
new file mode 100644
index 00000000000..add277fc524
--- /dev/null
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionMultiBrokerTest.java
@@ -0,0 +1,67 @@
+/**
+ * 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.broker.admin.v3;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.broker.transaction.TransactionTestBase;
+import org.apache.pulsar.client.api.PulsarClient;
+import org.apache.pulsar.common.naming.TopicName;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+@Slf4j
+@Test(groups = "broker-admin")
+public class AdminApiTransactionMultiBrokerTest extends TransactionTestBase {
+
+    private static final int NUM_BROKERS = 16;
+    private static final int NUM_PARTITIONS = 3;
+
+    @BeforeMethod
+    protected void setup() throws Exception {
+        setUpBase(NUM_BROKERS, NUM_PARTITIONS, NAMESPACE1 + "/test", 0);
+    }
+
+    @AfterMethod(alwaysRun = true)
+    protected void cleanup() throws Exception {
+        super.internalCleanup();
+    }
+
+    @Test
+    public void testRedirectOfGetCoordinatorInternalStats() throws Exception {
+        Map<String, String> map = admin.lookups()
+                
.lookupPartitionedTopic(TopicName.TRANSACTION_COORDINATOR_ASSIGN.toString());
+        while 
(map.containsValue(getPulsarServiceList().get(0).getBrokerServiceUrl())) {
+            
admin.topics().deletePartitionedTopic(TopicName.TRANSACTION_COORDINATOR_ASSIGN.toString());
+            
admin.topics().createPartitionedTopic(TopicName.TRANSACTION_COORDINATOR_ASSIGN.toString(),
 NUM_PARTITIONS);
+            map = 
admin.lookups().lookupPartitionedTopic(TopicName.TRANSACTION_COORDINATOR_ASSIGN.toString());
+        }
+        //init tc stores
+        pulsarClient = PulsarClient.builder()
+                
.serviceUrl(getPulsarServiceList().get(0).getBrokerServiceUrl())
+                .statsInterval(0, TimeUnit.SECONDS)
+                .enableTransaction(true)
+                .build();
+        for (int i = 0; i < NUM_PARTITIONS; i++) {
+            admin.transactions().getCoordinatorInternalStats(i, false);
+        }
+    }
+}
diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionTest.java
 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionTest.java
index fa6e56724fe..aff09f2d7f1 100644
--- 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionTest.java
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionTest.java
@@ -66,6 +66,7 @@ import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
+@Test(groups = "broker-admin")
 public class AdminApiTransactionTest extends MockedPulsarServiceBaseTest {
 
     @BeforeMethod

Reply via email to