-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 create partition of an exist topic doesn't throw RestException #9342
Fix create partition of an exist topic doesn't throw RestException #9342
Conversation
@hangc0276 PTAL, this fix will expose the wrong repeated metadata initialization code of KoP. |
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
Outdated
Show resolved
Hide resolved
I've changed another way to fix the issue and the backward compatibility could be retained, PTAL again, @zymap |
I am curious about this, when will this behavior happen? As I know, the rest API is defined as
About this issue, I am using master code to test and it shows I can't create a non-partitioned topic with a name that contains the
So could you please give me more information about this case? |
@zymap You're right for the 1st issue. It only affects my tests code: final String partitionName = TopicName.get(topicName).getPartition(0).toString();
try {
persistentTopics.createNonPartitionedTopic(testTenant, testNamespace, partitionName, false); I should use the local name in tests instead of in the For the 2nd issue, the intention for creating non-partitioned topic with Here's an example: # 1. A partition was somehow deleted or not created successfully
$ ./bin/pulsar-admin topics create-partitioned-topic xyz -p 3
$ ./bin/pulsar-admin topics delete xyz-partition-0
$ ./bin/pulsar-admin topics list public/default
"persistent://public/default/xyz-partition-2"
"persistent://public/default/xyz-partition-1"
# 2. Then we can create a non-partitioned topic to create missed partitions
$ ./bin/pulsar-admin topics create xyz-partition-0
$ ./bin/pulsar-admin topics list public/default
"persistent://public/default/xyz-partition-2"
"persistent://public/default/xyz-partition-0"
"persistent://public/default/xyz-partition-1"
# 3. However, if you create a existed partition, there's no error, this is what I want to fix
$ ./bin/pulsar-admin topics create xyz-partition-2 The rule is from #5148. |
The test is now broken, I'll fix it first. |
/pulsarbot run-failure-checks |
1 similar comment
/pulsarbot run-failure-checks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Thanks for your explanation!
Left a minor comment.
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
Show resolved
Hide resolved
d61cc34
to
0603fe8
Compare
/pulsarbot run-failure-checks |
2 similar comments
/pulsarbot run-failure-checks |
/pulsarbot run-failure-checks |
/pulsarbot run-failure-checks |
0603fe8
to
14727c1
Compare
/pulsarbot run-failure-checks |
/pulsarbot run-failure-checks |
It looks like the |
14727c1
to
4f0f350
Compare
/pulsarbot run-failure-checks |
2 similar comments
/pulsarbot run-failure-checks |
/pulsarbot run-failure-checks |
The failed tests may be caused by this PR, I'm trying to fix them. |
I ran the functions integration tests in my local environment and got the similar error:
It looks like the functions worker container tries to create existed |
4f0f350
to
7e91eb2
Compare
There're still 3 tests that failed.
These tests may be flaky. I've rerun the tests and
Take try (PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(pulsarCluster.getHttpServiceUrl()).build()) {
admin.topics().createNonPartitionedTopic(inputTopicName);
admin.topics().createNonPartitionedTopic(outputTopicName);
} |
b2c3751
to
00e65bb
Compare
/pulsarbot run-failure-checks |
1 similar comment
/pulsarbot run-failure-checks |
Now all tests passed, PTAL again, @jiazhai @sijie @zymap @codelipenghui |
Currently KoP created `__consumer_offsets` repeatedly, the `ConflictException` will be thrown after apache/pulsar#9342. Though it doesn't affect the usage because the `ConflictException` is treated as the concurrent issue and will be swallowed, it could cause some unnecessary logs. So this PR remove the redundant partition creation code. Another issue is that when `__consumer_offsets` already exists, the existed partition will be created because the partition returned by broker contains `persistent://` prefix but the topics in `offsetPartitionSet` don't. This PR use `KopTopic` to avoid the topic name dismatch.
Motivation
Currently creating a partition of an existed partitioned topic was created doesn't throw any exception. However it should be an invalid behavior. The reason is that when a non partitioned topic was created, it only checks whether the number of partitions is positive. However, no matter the topic doesn't exist or the topic is an existed partition, the number of partitions is 0. This PR is to distinguish these two cases and throw a
RestException
when the non-partitioned topic is an existed partition.Modifications
RestException
and add a test to verify it.public/functions/assignment
no matter if it exists. Here we ignore theConflictException
.Verifying this change
This change added tests and can be verified as follows:
AdminApiTeststestPersistentTopicCreation
.