Skip to content

Commit

Permalink
[fix][Transaction] Fix transaction admin redirect get 500 due to getC…
Browse files Browse the repository at this point in the history
…ause (apache#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
  • Loading branch information
liangyepianzhou authored and aparajita-singh-flipkart committed Apr 18, 2022
1 parent c819576 commit 3861a7c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ protected void internalGetCoordinatorInternalStats(AsyncResponse asyncResponse,
"Broker don't use MLTransactionMetadataStore!"));
}
} catch (Exception e) {
asyncResponse.resume(new RestException(e.getCause()));
resumeAsyncResponseExceptionally(asyncResponse, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

@Test(groups = "broker-admin")
public class AdminApiTransactionTest extends MockedPulsarServiceBaseTest {

@BeforeMethod
Expand Down

0 comments on commit 3861a7c

Please sign in to comment.