Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] [broker] Fix wrong logic of method TopicName.getPartition(int index) #19841

Merged
merged 5 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.api.SubscriptionType;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.policies.data.AutoTopicCreationOverride;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
Expand Down Expand Up @@ -66,7 +67,7 @@ public void testAutoCreatePartitionTopicWithKeywordAndDeleteIt()
.subscribe();
List<String> topics = admin.topics().getList("public/default");
List<String> partitionedTopicList = admin.topics().getPartitionedTopicList("public/default");
Assert.assertTrue(topics.contains(topicName));
Assert.assertTrue(topics.contains(TopicName.get(topicName).getPartition(0).toString()));
Assert.assertTrue(partitionedTopicList.contains(topicName));
consumer.close();
admin.topics().deletePartitionedTopic(topicName);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public String getEncodedLocalName() {
}

public TopicName getPartition(int index) {
if (index == -1 || this.toString().contains(PARTITIONED_TOPIC_SUFFIX)) {
if (index == -1 || this.toString().endsWith(PARTITIONED_TOPIC_SUFFIX + index)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I thought was the PR intent to allow the partitioned name can contain -partition- keyword to resolve the issue. But it will introduce a new unreasonable rule to the partitioned topic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will not automatically create a partitioned topic for the DLQ topic even if users are enabled partitioned topic auto-creation.

Yes, PIP-263: Just auto-create no-partitioned DLQ And Prevent auto-create a DLQ for a DLQ try to do this.

Copy link
Contributor Author

@poorbarcode poorbarcode Apr 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I thought was the PR intent to allow the partitioned name can contain -partition- keyword to resolve the issue. But it will introduce a new unreasonable rule to the partitioned topic.

I think there are three separate things:

  • Our rule for a partition name and how to check which index it is: end with -partition-x or contain -partition-x
    • The current logic is incorrect, and the current PR can fix it.
  • Whether to allow to create a topic whose name contains -paritition-
    • the behavior is denied for Admin API
      -the behavior is allowed for client(such as create by a cmd-subscribe), you can see the tests testInfiniteHttpCallGetSubscriptions2, testInfiniteHttpCallGetSubscriptions3 in current PR
  • Whether only create non-partitioned topics for the Dead Letter or Retry Letter

return this;
}
String partitionName = this.toString() + PARTITIONED_TOPIC_SUFFIX + index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,12 @@ public void testShortTopicName() throws Exception {
// Ok
}
}

@Test
public void testTwoKeyWordPartition(){
TopicName tp1 = TopicName.get("tenant1/namespace1/tp1-partition-0-DLQ");
TopicName tp2 = tp1.getPartition(0);
assertNotEquals(tp2.toString(), tp1.toString());
assertEquals(tp2.toString(), "persistent://tenant1/namespace1/tp1-partition-0-DLQ-partition-0");
}
}