Skip to content

Commit 7248e6a

Browse files
poorbarcodeTechnoboy-
authored andcommitted
[fix][broker] Fast fix infinite HTTP call getSubscriptions caused by wrong topicName (apache#22357)
Co-authored-by: Jiwe Guo <[email protected]>
1 parent db6327d commit 7248e6a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Diff for: pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2334,7 +2334,7 @@ protected void internalCreateSubscription(AsyncResponse asyncResponse, String su
23342334
getPartitionedTopicMetadataAsync(topicName, authoritative, allowAutoTopicCreation))
23352335
.thenAccept(partitionMetadata -> {
23362336
final int numPartitions = partitionMetadata.partitions;
2337-
if (numPartitions > 0) {
2337+
if (partitionMetadata.partitions > 0 && !isUnexpectedTopicName(partitionMetadata)) {
23382338
final CompletableFuture<Void> future = new CompletableFuture<>();
23392339
final AtomicInteger count = new AtomicInteger(numPartitions);
23402340
final AtomicInteger failureCount = new AtomicInteger(0);

Diff for: pulsar-broker/src/test/java/org/apache/pulsar/client/api/TopicNameForInfiniteHttpCallGetSubscriptionsTest.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected void cleanup() throws Exception {
5252
}
5353

5454
@Test
55-
public void testInfiniteHttpCallGetSubscriptions() throws Exception {
55+
public void testInfiniteHttpCallGetOrCreateSubscriptions() throws Exception {
5656
final String randomStr = UUID.randomUUID().toString().replaceAll("-", "");
5757
final String partitionedTopicName = "persistent://my-property/my-ns/tp1_" + randomStr;
5858
final String topic_p0 = partitionedTopicName + TopicName.PARTITIONED_TOPIC_SUFFIX + "0";
@@ -64,6 +64,7 @@ public void testInfiniteHttpCallGetSubscriptions() throws Exception {
6464
// Do test.
6565
ProducerAndConsumerEntry pcEntry = triggerDLQCreated(topic_p0, topicDLQ, subscriptionName);
6666
admin.topics().getSubscriptions(topicDLQ);
67+
admin.topics().createSubscription(topicDLQ, "s1", MessageId.earliest);
6768

6869
// cleanup.
6970
pcEntry.consumer.close();
@@ -72,7 +73,7 @@ public void testInfiniteHttpCallGetSubscriptions() throws Exception {
7273
}
7374

7475
@Test
75-
public void testInfiniteHttpCallGetSubscriptions2() throws Exception {
76+
public void testInfiniteHttpCallGetOrCreateSubscriptions2() throws Exception {
7677
final String randomStr = UUID.randomUUID().toString().replaceAll("-", "");
7778
final String topicName = "persistent://my-property/my-ns/tp1_" + randomStr + "-partition-0-abc";
7879
Producer<String> producer = pulsarClient.newProducer(Schema.STRING)
@@ -81,13 +82,14 @@ public void testInfiniteHttpCallGetSubscriptions2() throws Exception {
8182

8283
// Do test.
8384
admin.topics().getSubscriptions(topicName);
85+
admin.topics().createSubscription(topicName, "s1", MessageId.earliest);
8486

8587
// cleanup.
8688
producer.close();
8789
}
8890

8991
@Test
90-
public void testInfiniteHttpCallGetSubscriptions3() throws Exception {
92+
public void testInfiniteHttpCallGetOrCreateSubscriptions3() throws Exception {
9193
final String randomStr = UUID.randomUUID().toString().replaceAll("-", "");
9294
final String topicName = "persistent://my-property/my-ns/tp1_" + randomStr + "-partition-0";
9395
Producer<String> producer = pulsarClient.newProducer(Schema.STRING)
@@ -96,6 +98,7 @@ public void testInfiniteHttpCallGetSubscriptions3() throws Exception {
9698

9799
// Do test.
98100
admin.topics().getSubscriptions(topicName);
101+
admin.topics().createSubscription(topicName, "s1", MessageId.earliest);
99102

100103
// cleanup.
101104
producer.close();

0 commit comments

Comments
 (0)