MartijnVisser commented on code in PR #354: URL: https://github.com/apache/flink-connector-kafka/pull/354#discussion_r4770186542
########## docs/content.zh/docs/connectors/datastream/kafka.md: ########## @@ -283,6 +283,28 @@ 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```,并使用 ```--allowNonRestoredState```(```-n```)参数从 savepoint +重启作业。这会丢弃该 Source 所有分片的 offset,而不仅仅是被移除 Topic 的 offset,因此新的 Source 会从其起始消费位点开始读取。 +如果要从上一个作业提交的 offset 继续消费,请启用消费位点提交,并使用 +```OffsetsInitializer.committedOffsets(OffsetResetStrategy.EARLIEST)```。重置策略适用于没有已提交 offset 的分区, +例如新订阅 Topic 的分区。如果使用 ```committedOffsets()```(即 ```OffsetResetStrategy.NONE```),Source 会在这些分区上抛出 +```NoOffsetForPartitionException``` 并失败。已提交的 offset 可能落后于 savepoint,因此部分数据可能会被重复读取。 + +修改 Source 的 ```uid``` 也会改变下游未设置 ```uid``` 的算子自动生成的 ID。```--allowNonRestoredState``` 会同时丢弃这些算子的状态, +并且不会报错。重启作业之前,请确认所有有状态的算子都设置了 ```uid```。 Review Comment: Same here. ########## docs/content/docs/connectors/datastream/kafka.md: ########## @@ -306,6 +306,34 @@ 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 ```--allowNonRestoredState``` (```-n```). 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(OffsetResetStrategy.EARLIEST)```. The reset strategy +applies to partitions without committed offsets, such as the partitions of a newly subscribed topic. +With ```committedOffsets()```, which uses ```OffsetResetStrategy.NONE```, the source fails with a +```NoOffsetForPartitionException``` on such partitions. The committed offsets can be behind the +savepoint, so some records may be read again. + +Changing the ```uid``` of the source also changes the generated IDs of downstream operators that +have no ```uid``` set. ```--allowNonRestoredState``` then drops their state as well, without an error. +Check that all stateful operators have a ```uid``` before you restart the job. Review Comment: Adding the `uid` now doesn't help: the operator gets a new ID and loses its state anyway. In my run it only survived if the `uid` was set when the savepoint was taken, or with `setUidHash` set to the old generated ID. Could the docs say that? -- 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]
