Description
This problem is exposed in our product environment: a topic is used to produce monitoring data. After expanding partitions, the consumer side of the business reported that the data is lost.
After preliminary investigation, the lost data is all concentrated in the newly expanded partitions. The reason is: when the server expands, the producer firstly perceives the expansion, and some data is written in the newly expanded partitions. But the consumer group perceives the expansion later, after the rebalance is completed, the newly expanded partitions will be consumed from the latest if it is set to consume from the latest. Within a period of time, the data of the newly expanded partitions is skipped and lost by the consumer.
If it is not necessarily set to consume from the earliest for a huge data flow topic when starts up, this will make the group consume historical data from the broker crazily, which will affect the performance of brokers to a certain extent. Therefore, it is necessary to consume these partitions from the earliest separately.
I did a test and the result is as attached screenshot. Firstly, set by producer and consumer "metadata.max.age.ms" are 500ms and 30000ms respectively.
trunk-console-consumer.png means to use the community version to start the consumer and set "latest".
trunk-produce.png means the data produced, "partition_count" means the number of partitions of the current topic, "message" means the digital content of the corresponding message, "send_to_partition_index" Indicates the index of the partition to which the corresponding message is sent. It can be seen that at 11:32:10, the producer perceives the expansion of the total partitions from 2 to 3, and writes the numbers 38, 41, and 44 into the newly expanded partition 2.
trunk-consume.png represents all the digital content consumed by the community version. You can see that 38 and 41 sent to partition 2 were not consumed at the beginning. Finally, after partition 2 was perceived, 38 and 41 were still not consumed. Instead, it has been consumed from the latest 44, so the two data of 38 and 41 are discarded.
safe-console-consumer.png means to use the fixed version to start the consumer and set "safe_latest".
safe-produce.png means the data produced. It can be seen that at 12:12:09, the producer perceives the expansion of the total partitions from 4 to 5, and writes the numbers 109 and 114 into the newly expanded partition 4.
safe-consume.png represents all the digital content consumed by the fixed version. You can see that 109 sent to partition 4 were not consumed at the beginning. Finally, after partition 4 was perceived,109 was consumed as the first data of partition 4. So the fixed version will not cause consumption to lose data under this condition.
Attachments
Attachments
Issue Links
- is duplicated by
-
KAFKA-15185 Consumers using the latest strategy may lose data after the topic adds partitions
- Resolved
-
KAFKA-12261 Splitting partition causes message loss for consumers with auto.offset.reset=latest
- Resolved
- relates to
-
KAFKA-3370 Add options to auto.offset.reset to reset offsets upon initialization only
- Open
- links to