Skip to content

fix get partition metadata problem for a non-existed topic#8818

Merged
codelipenghui merged 7 commits into
apache:masterfrom
aloyszhang:no-exist
Jan 7, 2021
Merged

fix get partition metadata problem for a non-existed topic#8818
codelipenghui merged 7 commits into
apache:masterfrom
aloyszhang:no-exist

Conversation

@aloyszhang

Copy link
Copy Markdown
Contributor

Fixes #8813

Motivation

Currently, getting the partition metadata for a non-existed topic, it returns 0 instead of throwing an exception.
This pr fix this by throwing an exception.

Modifications

If no metadata found in global zk, then will check whether the topic is exist, if yes, will return 0, otherwise will throw an exception.

@BewareMyPower BewareMyPower left a comment

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.

A unit test should be added to cover the case when a PulsarAdmin tries to get the partition metadata of a non-existed topic.

@BewareMyPower

BewareMyPower commented Dec 4, 2020

Copy link
Copy Markdown
Contributor

Please rebase to the latest master since the master branch was broken before.

@aloyszhang

Copy link
Copy Markdown
Contributor Author

@BewareMyPower I'll do this later.

@aloyszhang
aloyszhang force-pushed the no-exist branch 3 times, most recently from 41b824b to 533e000 Compare December 7, 2020 16:14
@sijie sijie added triage/week-50 type/bug The PR fixed a bug or issue reported a bug labels Dec 8, 2020
@sijie sijie added this to the 2.8.0 milestone Dec 8, 2020
@wolfstudy

Copy link
Copy Markdown
Member

@BewareMyPower Please take a look this change again, thanks.

@BewareMyPower

Copy link
Copy Markdown
Contributor

@aloyszhang could you rebase to latest master?

Comment on lines +707 to +709
if (e.getCause().getMessage().contains("Topic not exist.")) {
throw new org.apache.pulsar.broker.web.RestException(Response.Status.NOT_FOUND, "Topic 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.

Could you please clarify why throw (RestException) e.getCause() does not work here? If e.getCause is instance of RestException, I think we can throw it directly. I might be missing something here.

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.

I'll check this PR and push later.

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.

Thanks @aloyszhang

Comment on lines +723 to +727
// Since CompletableFuture wrappers exception, so we will lost the Status
// rebuild the Status if exception message contains "Topic not exist."
if (e.getCause().getMessage().contains("Topic not exist.")) {
throw new org.apache.pulsar.broker.web.RestException(Response.Status.NOT_FOUND, "Topic 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.

Same as the above comment.

}
} catch (RestException restException) {
if (Status.NOT_FOUND.getStatusCode() != restException.getResponse().getStatus()) {
throw restException;

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 think it's not correct handling here, If got 404 here, it means the partitioned metadata does not exist right? If the partitioned metadata does exist, why should we prevent the non-partitioned topic creation?

Comment on lines +1177 to +1189
CompletableFuture<List<String>> future = new CompletableFuture<>();
pulsar.getBrokerService().fetchPartitionedTopicMetadataAsync(topicName).whenComplete((meta, t) -> {
if (t != null) {
future.completeExceptionally(t);
return;
}
List<String> result = Lists.newArrayList();
for (int i = 0; i < meta.partitions; i++) {
result.add(topicName.getPartition(i).toString());
}
return CompletableFuture.completedFuture(result);
future.complete(result);
});
return future;

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.

What is the difference between these changes? Why we change the thenCompose to whenComplete?

if (e.getCause() instanceof RestException) {
// Since CompletableFuture wrappers exception, so we will lost the Status
// rebuild the Status if exception message contains "Topic not exist."
if (e.getCause().getMessage().contains("Topic 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.

Please do not rely on strings, can we test the actual class?

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.

Yes, I'll change this PR and push again.

pulsar().getBrokerService().fetchPartitionedTopicMetadataAsync(topicName).get();
if (partitionedTopicMetadata.partitions < 1) {
if (!pulsar().getNamespaceService().checkTopicExists(topicName).get()
&& checkAllowAutoCreation

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.

Here is not covered by tests? I noticed the tests only cover the checkAllowAutoCreation=false, could you please help add a test for cover checkAllowAutoCreation=true?

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.

I'll add test case to protect this part of code.

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.

Thanks

@eolivelli eolivelli left a comment

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.

LGTM

@aloyszhang

aloyszhang commented Jan 5, 2021

Copy link
Copy Markdown
Contributor Author

@codelipenghui It seems merge apache/master branch into this pr branch makes more checks failed. For each test ,which namespaces is not explicit created, it'll failed now.

@codelipenghui

Copy link
Copy Markdown
Contributor

/pulsarbot run-failure-checks

@codelipenghui

Copy link
Copy Markdown
Contributor

/pulsarbot run-failure-checks

2 similar comments
@aloyszhang

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@aloyszhang

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@codelipenghui
codelipenghui merged commit a3dfb2a into apache:master Jan 7, 2021
codelipenghui pushed a commit that referenced this pull request Jan 7, 2021
Fixes #8813

Currently, getting the partition metadata for a non-existed topic, it returns 0 instead of throwing an exception.
This pr fix this by  throwing an exception.

If no metadata found in global zk, then will check whether the topic is exist, if yes, will return 0, otherwise will  throw an exception.

(cherry picked from commit a3dfb2a)
codelipenghui pushed a commit that referenced this pull request Jan 7, 2021
Fixes #8813

Currently, getting the partition metadata for a non-existed topic, it returns 0 instead of throwing an exception.
This pr fix this by  throwing an exception.

If no metadata found in global zk, then will check whether the topic is exist, if yes, will return 0, otherwise will  throw an exception.

(cherry picked from commit a3dfb2a)
@codelipenghui codelipenghui added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Jan 7, 2021
@aloyszhang
aloyszhang deleted the no-exist branch January 22, 2021 11:58
merlimat pushed a commit to merlimat/pulsar that referenced this pull request Apr 6, 2021
Fixes apache#8813

### Motivation

Currently, getting the partition metadata for a non-existed topic, it returns 0 instead of throwing an exception.
This pr fix this by  throwing an exception.


### Modifications

If no metadata found in global zk, then will check whether the topic is exist, if yes, will return 0, otherwise will  throw an exception.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/branch-2.7 Archived: 2.7 is end of life release/2.6.3 release/2.7.1 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get partition metadata for a non-existed topic returns 0

6 participants