Skip to content

[fix][broker] Support getStats/update partitioned topic with -partition-#19235

Merged
yuruguo merged 1 commit intoapache:masterfrom
yuruguo:validate-partitioned-topic
Jun 6, 2023
Merged

[fix][broker] Support getStats/update partitioned topic with -partition-#19235
yuruguo merged 1 commit intoapache:masterfrom
yuruguo:validate-partitioned-topic

Conversation

@yuruguo
Copy link
Copy Markdown
Contributor

@yuruguo yuruguo commented Jan 15, 2023

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:

@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Jan 15, 2023
@yuruguo yuruguo self-assigned this Jan 15, 2023
@yuruguo yuruguo added this to the 2.12.0 milestone Jan 15, 2023
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 15, 2023

Codecov Report

Attention: Patch coverage is 33.33333% with 6 lines in your changes missing coverage. Please review.

Project coverage is 62.04%. Comparing base (fcecca4) to head (1bf2492).
Report is 1828 commits behind head on master.

Files with missing lines Patch % Lines
...pache/pulsar/broker/admin/v2/PersistentTopics.java 33.33% 2 Missing and 2 partials ⚠️
...he/pulsar/broker/admin/v2/NonPersistentTopics.java 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@              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     
Flag Coverage Δ
inttests 24.62% <0.00%> (-0.34%) ⬇️
systests 25.23% <0.00%> (-0.43%) ⬇️
unittests 59.19% <33.33%> (+41.64%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...he/pulsar/broker/admin/v2/NonPersistentTopics.java 61.92% <33.33%> (+34.14%) ⬆️
...pache/pulsar/broker/admin/v2/PersistentTopics.java 75.01% <33.33%> (+65.39%) ⬆️

... and 1253 files with indirect coverage changes

Copy link
Copy Markdown
Contributor

@HQebupt HQebupt left a comment

Choose a reason for hiding this comment

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

LGTM

@yuruguo yuruguo force-pushed the validate-partitioned-topic branch from 46cc314 to 2db9596 Compare January 29, 2023 02:43
@Technoboy-
Copy link
Copy Markdown
Contributor

It's better to discuss this on the dev mail list.

@ApiParam(value = "The number of partitions for the topic",
required = true, type = "int", defaultValue = "0")
int numPartitions) {
validateTopicName(tenant, namespace, encodedTopic);
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

@yuruguo yuruguo Feb 19, 2023

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.

@QueryParam("getEarliestTimeInBacklog") @DefaultValue("false") boolean getEarliestTimeInBacklog) {
try {
validatePartitionedTopicName(tenant, namespace, encodedTopic);
validateTopicName(tenant, namespace, encodedTopic);
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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 ifisPartitioned()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?

@yuruguo yuruguo force-pushed the validate-partitioned-topic branch from 2db9596 to 1bf2492 Compare February 19, 2023 11:28
@QueryParam("getEarliestTimeInBacklog") @DefaultValue("false") boolean getEarliestTimeInBacklog) {
try {
validatePartitionedTopicName(tenant, namespace, encodedTopic);
validateTopicName(tenant, namespace, encodedTopic);
Copy link
Copy Markdown
Contributor

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 ifisPartitioned()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?

@github-actions
Copy link
Copy Markdown

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions Bot added the Stale label Mar 23, 2023
@poorbarcode poorbarcode modified the milestones: 3.0.0, 3.1.0 Apr 10, 2023
@yuruguo yuruguo merged commit f4386c8 into apache:master Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants