Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-12478

Consumer group may lose data for newly expanded partitions when add partitions for topic if the group is set to consume from the latest

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.1.1
    • None
    • clients

    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

        1. safe-console-consumer.png
          107 kB
          hudeqi
        2. safe-consume.png
          55 kB
          hudeqi
        3. safe-produce.png
          327 kB
          hudeqi
        4. trunk-console-consumer.png
          81 kB
          hudeqi
        5. trunk-consume.png
          65 kB
          hudeqi
        6. trunk-produce.png
          384 kB
          hudeqi

        Issue Links

          Activity

            People

              hudeqi hudeqi
              hudeqi hudeqi
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 1,158h
                  1,158h
                  Remaining:
                  Remaining Estimate - 1,158h
                  1,158h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified