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] Support getStats/update partitioned topic with -partition-
#19235
Conversation
Codecov Report
@@ Coverage Diff @@
## master #19235 +/- ##
=============================================
+ Coverage 32.45% 62.04% +29.58%
- Complexity 6348 25705 +19357
=============================================
Files 1644 1844 +200
Lines 123737 135285 +11548
Branches 13494 14878 +1384
=============================================
+ Hits 40162 83934 +43772
+ Misses 77654 43599 -34055
- Partials 5921 7752 +1831
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
LGTM
46cc314
to
2db9596
Compare
It's better to discuss this on the dev mail list. |
@@ -810,6 +810,11 @@ public void updatePartitionedTopic( | |||
@ApiParam(value = "The number of partitions for the topic", | |||
required = true, type = "int", defaultValue = "0") | |||
int numPartitions) { | |||
validateTopicName(tenant, namespace, encodedTopic); |
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'm actually not following here.
You add a call to validateTopicName
, but in line 818, you have a call to validatePartitionedTopicName
which is:
// first, it has to be a validate topic name
validateTopicName(tenant, namespace, encodedTopic);
// second, "-partition-" is not allowed
if (encodedTopic.contains(TopicName.PARTITIONED_TOPIC_SUFFIX)) {
throw new RestException(Status.PRECONDITION_FAILED,
"Partitioned Topic Name should not contain '-partition-'");
}
This seems to contain exactly the code you've added. So wham I missing here?
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.
Sorry, I forget to delete line818(validatePartitionedTopicName
) and has been fixed it.
@@ -1284,7 +1289,11 @@ public void getPartitionedStats( | |||
@ApiParam(value = "If return the earliest time in backlog") | |||
@QueryParam("getEarliestTimeInBacklog") @DefaultValue("false") boolean getEarliestTimeInBacklog) { | |||
try { | |||
validatePartitionedTopicName(tenant, namespace, encodedTopic); | |||
validateTopicName(tenant, namespace, encodedTopic); |
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.
Same question. Seems like you inlined that method. Don't understand.
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.
The validatePartitionedTopicName
method has been deleted, so the above problem does not exist.
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.
So now I can ask: What's the motivation for essentially copying the code from within validatePartitionedTopicName
(which still exists in the code, as the method itself wasn't deleted) and pasting it in mutliple places?
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.
The code I added is not exactly the same as the code you mentioned, mainly in topicName.isPartitioned()
and encodedTopic.contains(TopicName.PARTITIONED_TOPIC_SUFFIX)
, the purpose is to improve the verification, details see #19234
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.
Got it.
1st, you need to change PR description. What you're basically doing here is changing the validation.
Before: -partition
couldn't appear anywhere in the partitioned topic name.
Now: 'partition-
can appear, but it is now allowed to be of suffix -partition-{num}
.
You're basically you're loosening up the validation.
2nd, you already have a method called validatePartitionedTopicName
which is supposed to validate the name of a partitioned topic. I believe you should just modify the validation code in it, instead of keeping it as is and creating another logic block containing that validation.
So take
protected void validatePartitionedTopicName(String tenant, String namespace, String encodedTopic) {
// first, it has to be a validate topic name
validateTopicName(tenant, namespace, encodedTopic);
// second, "-partition-" is not allowed
if (encodedTopic.contains(TopicName.PARTITIONED_TOPIC_SUFFIX)) {
throw new RestException(Status.PRECONDITION_FAILED,
"Partitioned Topic Name should not contain '-partition-'");
}
}
And change last validation of partition to be topicName
based as you did.
3rd, your exception is wrong. You say "Partitioned Topic Name should not contain '-partition-", but that was true *prior* to your change. It should say, something like - "Only base topic name is allowed. Specify the same name without
'-partition-{num}for this to work" Why? Because you know for a fact that if
isPartitioned()is true, it means it ends with
-partition-{num}`.
@eolivelli Shouldn't be lenient and actually fix the topic name to be without the partition, since we actually know for sure it's a partition, so we can fix it for the user?
2db9596
to
1bf2492
Compare
@@ -1284,7 +1289,11 @@ public void getPartitionedStats( | |||
@ApiParam(value = "If return the earliest time in backlog") | |||
@QueryParam("getEarliestTimeInBacklog") @DefaultValue("false") boolean getEarliestTimeInBacklog) { | |||
try { | |||
validatePartitionedTopicName(tenant, namespace, encodedTopic); | |||
validateTopicName(tenant, namespace, encodedTopic); |
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.
Got it.
1st, you need to change PR description. What you're basically doing here is changing the validation.
Before: -partition
couldn't appear anywhere in the partitioned topic name.
Now: 'partition-
can appear, but it is now allowed to be of suffix -partition-{num}
.
You're basically you're loosening up the validation.
2nd, you already have a method called validatePartitionedTopicName
which is supposed to validate the name of a partitioned topic. I believe you should just modify the validation code in it, instead of keeping it as is and creating another logic block containing that validation.
So take
protected void validatePartitionedTopicName(String tenant, String namespace, String encodedTopic) {
// first, it has to be a validate topic name
validateTopicName(tenant, namespace, encodedTopic);
// second, "-partition-" is not allowed
if (encodedTopic.contains(TopicName.PARTITIONED_TOPIC_SUFFIX)) {
throw new RestException(Status.PRECONDITION_FAILED,
"Partitioned Topic Name should not contain '-partition-'");
}
}
And change last validation of partition to be topicName
based as you did.
3rd, your exception is wrong. You say "Partitioned Topic Name should not contain '-partition-", but that was true *prior* to your change. It should say, something like - "Only base topic name is allowed. Specify the same name without
'-partition-{num}for this to work" Why? Because you know for a fact that if
isPartitioned()is true, it means it ends with
-partition-{num}`.
@eolivelli Shouldn't be lenient and actually fix the topic name to be without the partition, since we actually know for sure it's a partition, so we can fix it for the user?
The pr had no activity for 30 days, mark with Stale label. |
Motivation
Same as #19230, We allow users to use the
Client API
to create the partitioned topic which name contains-partition-{not-number}
when they enable partitioned type auto-creation.But we didn't get stats and update it.
Modifications
Support getting stats and updating partitioned topics with the keyword
-partition-{not-number}
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: