-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Allow non-pesistent topics to be retrieved along with persistent ones from the "GetTopicsOfNamespace" method #2025
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
Conversation
|
@jiazhai please review this when you have time. |
|
Just noticed integration tests are failing. Is this my fault? Should I fix that? |
|
retest this please |
| } | ||
|
|
||
| // Non-persistent topics don't have managed ledges so we have to retrieve them from local cache. | ||
| synchronized (pulsar.getBrokerService().getMultiLayerTopicMap()) { |
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.
This will only answer with the non-persistent topics served by the broker that it's handling the particular request. However, topics for a single namespace can be spread across multiple brokers.
We would need to do something like this ( https://github.com/apache/incubator-pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/NonPersistentTopics.java#L170 ) to get the correct list of non-persistent topics.
I think the best option is to actually use the same API to get the list of non-persistent topics through HTTP. GET /admin/v2/non-persistent/{tenant}/{namespace}. That should take care of everything.
|
| final String topicName2 = "persistent://my-property/my-ns/topic-2-" + key; | ||
| final String topicName3 = "persistent://my-property/my-ns/topic-3-" + key; | ||
| List<String> topicNames = Lists.newArrayList(topicName1, topicName2, topicName3); | ||
| final String topicName4 = "non-persistent://my-property/my-ns/topic-4-" + key; |
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.
seems some space alignment issue.
| String topicName1 = "persistent://my-property/my-ns/pattern-topic-1-" + key; | ||
| String topicName2 = "persistent://my-property/my-ns/pattern-topic-2-" + key; | ||
| String topicName3 = "persistent://my-property/my-ns/pattern-topic-3-" + key; | ||
| final String topicName4 = "non-persistent://my-property/my-ns/pattern-topic-4-" + key; |
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.
also here.
jiazhai
left a comment
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.
Thanks for the fix. Test case looks good. As @merlimat point out, there is better way to get the list.
|
Thanks for reviewing this everyone. |
Yes, I was meaning that in broker side we should use the client API (there are already several cases that already do that). Since a single broker will not have all the topics, and that non-persistent topics don't have additional metadata, the client API call is the only option to get the correct list of non-persistent topics. An additional improvement could be to only make this call if we know the client is interested in non-persistent topics and skip it otherwise. |
|
@merlimat @jiazhai I have updated this feature as you suggested. This is what was done in the latest commits:
Will be glad to receive your feedback. |
|
@merlimat @jiazhai can you review this PR and give @gordeevbr some feedback? |
|
ping @merlimat and @jiazhai . lets give some feedback to @gordeevbr , so that we can move forward with the change here. |
|
retest this please |
| import org.apache.pulsar.common.policies.data.AuthAction; | ||
| import org.apache.pulsar.common.policies.data.BacklogQuota; | ||
| import org.apache.pulsar.common.api.proto.PulsarApi.CommandGetTopicsOfNamespace.Mode; | ||
| import org.apache.pulsar.common.policies.data.*; |
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.
we should avoid using * in import.
| List<String> topics = ((PatternMultiTopicsConsumerImpl<?>) consumer).getPartitionedTopics(); | ||
| List<ConsumerImpl<byte[]>> consumers = ((PatternMultiTopicsConsumerImpl<byte[]>) consumer).getConsumers(); | ||
|
|
||
| assertEquals(topics.size(), 1); |
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.
Test failed at here.
Before patternconsumer created, the producer had been created. By design, it should have 7 topics (1+2+3+1)?
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.
@gordeevbr The mode change looks good to me, Please go ahead.
FYI. Seems this caller also need fix:
2018-08-05\T\16:42:17.037 [ERROR] /home/jenkins/jenkins-slave/workspace/pulsar_precommit_cpp/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/LookupProxyHandler.java:[335,31] method newGetTopicsOfNamespaceRequest in class org.apache.pulsar.common.api.Commands cannot be applied to given types;
2018-08-05\T\16:42:17.037 [ERROR] required: java.lang.String,long,org.apache.pulsar.common.api.proto.PulsarApi.CommandGetTopicsOfNamespace.Mode
2018-08-05\T\16:42:17.037 [ERROR] found: java.lang.String,long
2018-08-05\T\16:42:17.037 [ERROR] reason: actual and formal argument lists differ in length
|
Thanks for your feedback. |
|
I have fixed old tests that were failing, added some new tests to test suites where it was possible, updated features to be consistent with HTTP Lookup, fixed all found issues, and updated with master branch. There's not much new in these commits, mostly fixes and tests. I think it should be ready now. I am, of course, ready to update this PR if deemed necessary. |
|
@gordeevbr cool, thanks. I removed "[wip]". so other people know this PR is ready to review. |
jiazhai
left a comment
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.
+1, Thanks for the work.
|
Would you mind reruning these tests? I'm quite sure some of these were working just now. |
… into GetListOfTopicsNonPersistent
|
run java8 tests |
|
retest this please |
|
run java8 tests |
|
Great. Thank you very much! |
|
This is not working for me in Pulsar 2.11.1. I am able to receive messages from non-persistent topics belonging to single broker only. |
Motivation
Please see issue #2009 for a detailed bug report.
In our use case we require using java client with pattern subscription to read from a set of non-persistent topics. Unfortunately, right now this feature doesn't work. After researching the cause for this I have found out that under the hood the client is requesting a list of topics by namespace from the server and then filters them out by pattern and subscribes to them. The method in Pulsar broker NamespaceService class that is responsible for searching for required topics only uses ledgers, thus returning only persistent topics to the client. The goal of this pull request is to provide a solution for that problem.
Modifications
This pull request updates
getListOfTopicsmethod of NamespaceService class to also include active non-pesistent topics from local broker cache inside themultiLayerTopicsMapcollection of BrokerService in the result.Result
As a result, requesting a list of topics by namespace using the HTTP API or binary API (and thus via the clients) will add non-persistent topics to search result, allowing pattern subscription to be used with non-persistent topics.
Considerations
Since this method pulls non-persistent topics from local broker cache, this probably means that this solution will only work for Pulsar installations with a single broker. And if there are multiple brokers, results might be inconsistent. Unfortunately I don't really know if non-persistent themselves work in multi-broker setups. I have recently asked on Slack if non-persistent topics are being replicated in any way and @merlimat's response was that they don't. Also it seems to be that some other methods that are working with non-persistent topics are using this very same collection.
It seems to me that unit tests have made sure that Java client can work with this setup, but this might still be a breaking change for other clients or if applications working with this API are not expecting non-persistent topics in result.
I have made sure that old unit tests inside the
pulsar-brokersubproject are still working and updated some old tests for this particular use case. Are there any more tests that I can add.Overall, we really need this and I would appreciate if maintainers could share their opinion. Thanks in advance.