You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "poorbarcode (via GitHub)" <gi...@apache.org> on 2025/03/07 12:03:20 UTC
[PR] [FLINK-37436] Fix that flink-connector-pulsar used a incorrect API when dynamically creating topics by DynamicTopicRouter [flink-connector-pulsar]
poorbarcode opened a new pull request, #104:
URL: https://github.com/apache/flink-connector-pulsar/pull/104
## Purpose of the change
#### Background 1: dynamically create a Pulsar Topic by Flink connector-pulsar
Flink connector-pulsar provided a way to dynamically create a Pulsar Topic when DynamicTopicRouter returns a non-existing one. see also: [flink-connector-pulsar/flink-connector-pulsar/src/main/java/org/apache/flink/connector/pulsar/sink/writer/topic/ProducerRegister.java at main · apache/flink-connector-pulsar](https://github.com/apache/flink-connector-pulsar/blob/main/flink-connector-pulsar/src/main/java/org/apache/flink/connector/pulsar/sink/writer/topic/ProducerRegister.java#L221).
- `pulsarClient.getPartitionsForTopic(topic)` will create a topic automatically if it does not exist.
#### Background 2: how dynamically created topics in Pulsar Server
- There is a config named `allowAutoTopicCreationType`, which can be set to `
partitioned` or `non-partitioned`
- If it was set `partitioned`, Pulsar will create a partitioned topic with ` {defaultNumPartitions}` partitions. For example, Pulsar will create topics named `{tenant}/{namespace}/{topic name}-partition-0` and `{tenant}/{namespace}/{topic name}-partition-1`, and create a relationship between them, which indicates they are in a same partitioned topic.
- If it was set `non-partitioned`, Pulsar will create a non-partitioned topic. Pulsar will create topics named `{tenant}/{namespace}/{topic name}`, which does not include a suffix `partition-{num}`.
#### Issue:
- if `pulsarClient.getPartitionsForTopic(topic)` get a param `{tenant}/{namespace}/{topic name}-partition-0`, which includes the suffix `partition-0`, Pulsar will create a non-partitioned topic named `{tenant}/{namespace}/{topic name}-partition-0`
- After you call `pulsarClient.getPartitionsForTopic(topic)` with a param `{tenant}/{namespace}/{topic name}-partition-1`, you will get two partitions named `{tenant}/{namespace}/{topic name}-partition-0` and `{tenant}/{namespace}/{topic name}-partition-1`, but there is no relationship record between them.
## Brief change log
Fix the incorrect API calling.
## Verifying this change
This change is a minor change and don't have any tests.
## Significant changes
*(Please check any boxes [x] if the answer is "yes". You can first publish the PR and check them afterwards, for
convenience.)*
- [ ] Dependencies have been added or upgraded
- [ ] Public API has been changed (Public API is any class annotated with `@Public(Evolving)`)
- [ ] Serializers have been changed
- [ ] New feature has been introduced
- If yes, how is this documented? (not applicable / docs / JavaDocs / not documented)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-37436] Fix that flink-connector-pulsar used a incorrect API when dynamically creating topics by DynamicTopicRouter [flink-connector-pulsar]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #104:
URL: https://github.com/apache/flink-connector-pulsar/pull/104#issuecomment-2706280787
Thanks for opening this pull request! Please check out our contributing guidelines. (https://flink.apache.org/contributing/how-to-contribute.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-37436] Fix that flink-connector-pulsar used a incorrect API when dynamically creating topics by DynamicTopicRouter [flink-connector-pulsar]
Posted by "ferenc-csaky (via GitHub)" <gi...@apache.org>.
ferenc-csaky commented on code in PR #104:
URL: https://github.com/apache/flink-connector-pulsar/pull/104#discussion_r2440777883
##########
flink-connector-pulsar/src/main/java/org/apache/flink/connector/pulsar/sink/writer/topic/ProducerRegister.java:
##########
@@ -218,6 +219,14 @@ private <T> Producer<T> getOrCreateProducer(String topic, Schema<T> schema)
try {
// Use this method for auto creating the non-exist topics. Otherwise, it will throw an
// exception.
+ TopicName topicName = TopicName.get(topic);
+ // Step-1: create partitioned topic metadata.
+ if (topicName.isPartitioned()) {
+ pulsarClient
+ .getPartitionsForTopic(TopicName.get(topic).getPartitionedTopicName())
+ .get();
+ }
+ // Step-2: create partition.
Review Comment:
Shouldn't step 2 inside an `else` branch? I don't know anything about the pulsar client but duplicating this call does not seem right.
##########
flink-connector-pulsar/src/main/java/org/apache/flink/connector/pulsar/sink/writer/topic/ProducerRegister.java:
##########
@@ -218,6 +219,14 @@ private <T> Producer<T> getOrCreateProducer(String topic, Schema<T> schema)
try {
// Use this method for auto creating the non-exist topics. Otherwise, it will throw an
// exception.
+ TopicName topicName = TopicName.get(topic);
+ // Step-1: create partitioned topic metadata.
+ if (topicName.isPartitioned()) {
+ pulsarClient
+ .getPartitionsForTopic(TopicName.get(topic).getPartitionedTopicName())
+ .get();
Review Comment:
It seems to me this could be simplified to:
```java
pulsarClient.getPartitionsForTopic(topicName.getPartitionedTopicName()).get();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org