-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Adding configuration to disable auto-topic creation #3450
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
sijie
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.
I think a better approach is to disable auto creation at broker side. So administrators can disable this behavior while creating the cluster.
|
Ok, I found that the change should be in |
|
@ConcurrencyPractitioner : cool. pulsar broker uses managed ledger to store the topic partitions. there is actually a config in managed ledger Hope this gives you some entries for you to check out the code. |
|
Ok, I did some digging and here's what I found: I found that My best guess is that if there is no Z-Node for a ledger, then that means no partitions exists for it either. @sijie At this point, I'm not too sure what connection Edit: Ok, after some more digging. I have found that when |
|
Ok, there are some kinks in my understanding. Wouldn't disabling |
Ah, you are right. So I think in the task, you should do following:
Hope this clarify the tasks to do for this feature. |
sijie
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.
I think allowAutoTopicCreation should be a flag in broker configuration, rather than in ManagedLedgerConfig. So BrokerService would set different createIfMissing values at different scenarios based on whether allowAutoTopicCreation is set to true or not.
Also we need add new unit tests and integration tests to cover this feature.
| }); | ||
| } | ||
|
|
||
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.
nit: remove trailing spaces
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 agree!
|
Hi @sijie I've moved the config, but where would you suggest that we add the test? I've made some efforts and discovered a couple of candidate test locations like |
|
I think you need to verify following cases: when autoCreateTopic is disabled, 1) you can't publish or consume from topics when topics are not explicitly created. 2) you can create partitioned and non-partitions topics from pulsar admin rest endpoint. You can add a new test case to pulsar-broker module. There are plenty test cases using MockedPulsarServiceBaseTest, you can check them out as examples. |
|
HI @sijie, I'm currently using Eclipse to develop for Pulsar. What IDE do you use for Pulsar? |
|
I am using Intellij for my java development. For Lombok with Eclipse, I think if you run Here is one blog post about that - https://howtodoinjava.com/automation/lombok-eclipse-installation-examples/ Hope that helps. |
|
Thanks for the pointers. Just wanting to confirm, is it the community version or the licensed version? Also, I did some work on I also modified the config value i.e. WDYT of this? |
you mean Intellij? I am using the community version. |
|
Retest this please. |
|
@sijie Ok, added the PersistentTopicsTest. There are a couple more tests to go, but other than that, this PR should be getting close. |
sijie
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.
@ConcurrencyPractitioner overall looks good to me.
I think there are two remaining tasks for this. if you can do them in a follow up pull request, that would be great.
currently we don't have any rest endpoint for creating non-partitioned topics. so if we disable auto-creation of topics, people doesn't have any mechanisms to create non-partitioned topics.
so we need to add a rest endpoint for creating non-partitioned topic. this includes both admin rest endpoint change, a commandline cli change and documentation. I am wondering if you are interested in continuing the contributions in a subsequent pull request.
| } | ||
| } else if (rc == Code.NONODE.intValue()) { | ||
| // Z-node doesn't exist | ||
| log.warn("createIfMissing has value of {}", createIfMissing); |
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.
nit: is this for debugging purpose?
| return getOrCreateTopic(topic, false /* use allowAutoTopicCreation */); | ||
| } | ||
|
|
||
| public CompletableFuture<Topic> getOrCreateTopic(String topic, boolean defaultConfig) { |
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.
nit: defaultConfig => useAllowAutoTopicCreationSetting
|
|
||
| public CompletableFuture<Topic> getOrCreateTopic(String topic, boolean defaultConfig) { | ||
| boolean createIfMissing = defaultConfig ? pulsar.getConfiguration().isAllowAutoTopicCreation() : true; | ||
| log.warn("The createIfMissing value had been set to {}", createIfMissing); |
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.
hmm, can you move the logging to debug, otherwise it will be very annoying.
| } | ||
|
|
||
| getManagedLedgerConfig(topicName).thenAccept(managedLedgerConfig -> { | ||
| log.warn("createIfMissing has been set to {}", createIfMissing); |
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.
log.debug?
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.
remove this comment or turn it to log.debug
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.
@ConcurrencyPractitioner can you also remove this log.warn statement?
|
|
||
| public CompletableFuture<Optional<Topic>> getTopicIfExists(final String topic) { | ||
| return getTopic(topic, false /* createIfMissing */); | ||
| return getTopic(topic, false /* use allowAutoTopicCreation */); |
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.
should this be true?
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.
Uh no. getTopicIfExists should never create a topic. That is the purpose of this method.
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.
oh I see. so the comment of the flag here is wrong, no?
it should be /* createIfMissing */
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.
Oh, good point. I goofed.
|
|
||
| public CompletableFuture<Topic> getOrCreateTopic(final String topic) { | ||
| return getTopic(topic, true /* createIfMissing */).thenApply(Optional::get); | ||
| return getOrCreateTopic(topic, false /* use allowAutoTopicCreation */); |
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.
should this be true?
| import org.testng.annotations.AfterMethod; | ||
| import org.testng.annotations.BeforeMethod; | ||
| import org.testng.annotations.DataProvider; | ||
| import org.testng.annotations.Ignore; |
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.
it is not needed any more no?
|
Retest this please. |
|
@ConcurrencyPractitioner I have a comment left regarding the comment. otherwise, this change is ready to go. |
|
Ok @sijie Done. |
| } | ||
| } | ||
|
|
||
| service.getOrCreateTopic(topicName.toString()) |
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.
you don't need true here, it defaults to true.
| log.info("[{}][{}] Creating producer. producerId={}", remoteAddress, topicName, producerId); | ||
|
|
||
| service.getOrCreateTopic(topicName.toString()).thenAccept((Topic topic) -> { | ||
| service.getOrCreateTopic(topicName.toString(), true).thenAccept((Topic topic) -> { |
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.
as above.
| return getOrCreateTopic(topic, true /* use allowAutoTopicCreation */); | ||
| } | ||
|
|
||
| public CompletableFuture<Topic> getOrCreateTopic(String topic, boolean useAllowAutoTopicCreationSetting) { |
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.
Instead of creating a new override for getOrCreateTopic, make getTopic public.
Then the one place that calls getOrCreateTopic(..., false) can instead call getTopic(..., true), and getOrCreateTopic() can become
public CompletableFuture<Topic> getOrCreateTopic(final String topic) {
return getTopic(topic, pulsar.getConfiguration().isAllowAutoTopicCreation()).thenApply(Optional::get);
}
|
About the rest endpoint @sijie I'm good on following through about creating it. Although to be fair, where would be the best place to add the command line client change? |
|
Retest this please. |
|
@ConcurrencyPractitioner it should be in the same location as createPartitionedTopic (both broker and client sides) |
ivankelly
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.
Looks good to me. 👍
|
@sijie Should I add the endpoint in a separate PR or this one? |
|
@ConcurrencyPractitioner let's do it in a separated PR |
|
run integration tests |
|
@sijie or @ivankelly Do you think this could be merged? |
|
@ConcurrencyPractitioner well done |
Master Issue: #4926 ### Motivation Curently the partitioned-topic and non-partitioned topic is a little confuse for users. in PR #3450 we add config for auto-topic-creation. We could leverage this config to provide some more config for auto-topic-creation. ### Modifications - Add `allowAutoTopicCreationType` and `allowAutoTopicCreationNumPartitions` to configuration. - Users can use both configurations when they decide to create a topic automatically. - Add test. - Update doc.
Master Issue: #4926 Curently the partitioned-topic and non-partitioned topic is a little confuse for users. in PR #3450 we add config for auto-topic-creation. We could leverage this config to provide some more config for auto-topic-creation. - Add `allowAutoTopicCreationType` and `allowAutoTopicCreationNumPartitions` to configuration. - Users can use both configurations when they decide to create a topic automatically. - Add test. - Update doc. (cherry picked from commit 547c421)
Feature Request
There was a request for this feature in #3436.
Documentation
Will add to documentation a description of the new feature.