MartijnVisser commented on code in PR #354: URL: https://github.com/apache/flink-connector-kafka/pull/354#discussion_r4687156519
########## docs/content/docs/connectors/datastream/kafka.md: ########## @@ -306,6 +306,26 @@ topics are only checked once during source startup or recovery. When a topic is found missing or recreated, the source fails with a ```TopicIntegrityException```. +### Removing Topics from the Subscription +The Kafka source never revokes a split once it has been assigned to a reader. If you remove a topic +from the subscription (for example by changing ```setTopics(String...)```) and restore the job from a +checkpoint or savepoint, the readers restore the splits of the removed topic from state and keep +reading it alongside the subscribed topics. The same applies to a topic that no longer matches the +pattern of ```setTopicPattern(Pattern)``` and to partitions removed from ```setPartitions(Set)```. +Partition discovery detects such partitions, but only logs ```Discovered removed partitions: [...]```. +The <a href="#topic-integrity-check">topic integrity check</a> does not detect them either, because +it only checks the subscribed topics. + +To stop reading a removed topic, change the ```uid``` of the source and restart the job from the +savepoint with ```--allow-non-restored-state```. This drops the offsets of all splits of the source, +not only of the removed topic, so the new source starts from its starting offsets. To continue from +the offsets committed by the previous job, enable [offset committing](#consumer-offset-committing) +and use ```OffsetsInitializer.committedOffsets()```. Review Comment: `committedOffsets()` defaults to `OffsetResetStrategy.NONE`, so the switch from the ticket (topic A to B) fails with `NoOffsetForPartitionException`, since B has no committed offsets. Maybe suggest `committedOffsets(OffsetResetStrategy.EARLIEST)`? ########## docs/content/docs/connectors/datastream/kafka.md: ########## @@ -306,6 +306,26 @@ topics are only checked once during source startup or recovery. When a topic is found missing or recreated, the source fails with a ```TopicIntegrityException```. +### Removing Topics from the Subscription +The Kafka source never revokes a split once it has been assigned to a reader. If you remove a topic +from the subscription (for example by changing ```setTopics(String...)```) and restore the job from a +checkpoint or savepoint, the readers restore the splits of the removed topic from state and keep +reading it alongside the subscribed topics. The same applies to a topic that no longer matches the +pattern of ```setTopicPattern(Pattern)``` and to partitions removed from ```setPartitions(Set)```. +Partition discovery detects such partitions, but only logs ```Discovered removed partitions: [...]```. +The <a href="#topic-integrity-check">topic integrity check</a> does not detect them either, because +it only checks the subscribed topics. + +To stop reading a removed topic, change the ```uid``` of the source and restart the job from the +savepoint with ```--allow-non-restored-state```. This drops the offsets of all splits of the source, +not only of the removed topic, so the new source starts from its starting offsets. To continue from +the offsets committed by the previous job, enable [offset committing](#consumer-offset-committing) Review Comment: Stop-with-savepoint doesn't commit the savepoint's offsets (FLINK-36532), so this restarts from the last checkpoint and re-reads what came after it. I think the docs should say so. ########## docs/content.zh/docs/connectors/datastream/kafka.md: ########## @@ -283,6 +283,22 @@ Source 启动或恢复时执行一次。 当某个 Topic 被检测为缺失或被重建时,Source 会抛出 ```TopicIntegrityException``` 并使作业失败。 +<a name="removing-topics-from-the-subscription"></a> + +### 从订阅中移除 Topic +Kafka Source 一旦将分片分配给某个读取器,就不会再收回该分片。如果从订阅中移除了某个 Topic(例如修改了 +```setTopics(String...)```),并从 checkpoint 或 savepoint 恢复作业,读取器会从状态中恢复被移除 Topic 的分片, +并在读取已订阅 Topic 的同时继续读取它。对于不再匹配 ```setTopicPattern(Pattern)``` 正则表达式的 Topic,以及从 +```setPartitions(Set)``` 中移除的分区,情况也是如此。动态分区检查能够检测到这些分区,但只会记录 +```Discovered removed partitions: [...]``` 日志。Topic 完整性检查也不会检测到它们,因为它只检查已订阅的 Topic。 + +要停止读取被移除的 Topic,请修改 Source 的 ```uid```,并使用 ```--allow-non-restored-state``` 参数从 savepoint +重启作业。这会丢弃该 Source 所有分片的 offset,而不仅仅是被移除 Topic 的 offset,因此新的 Source 会从其起始消费位点开始读取。 +如果要从上一个作业提交的 offset 继续消费,请启用消费位点提交,并使用 ```OffsetsInitializer.committedOffsets()```。 Review Comment: Same two points here. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
