2
votes

Suppose:

  1. Kakfa consumer reads a message M from its assigned partition P
  2. It gets network-partitioned away from the broker
  3. Kafka detects this and reassigns P to a consumer on another machine.
  4. Network-partition is healed, and the first consumer tries to commit the offset for message M

Will there be any exception thrown in step 4? Is there a check which detects that the first consumer is no longer assigned partition P, and so shouldn't be committing offsets for it?

2

2 Answers

0
votes

In this case, the first consumer can not commit off set anymore. It's assigned partition will be revoked and when it join consumer group again, a rebalancing process will be trigger. So the answer is yes.

0
votes

https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol

The offsets for a given consumer group are maintained by a specific broker called the group coordinator. i.e., a consumer needs to issue its offset commit and fetch requests to this specific broker

Since one group coordinator is responsible and it know which consumers have partition assigned and which consumers have no longer the partition assigned

When they rejoin, they are treated in the same way as a brand new consumer joining the consumer group. They will get one or more partitions assigned by rebalancing (which may be totally different from the partitions they were reading from last time) and the consumer_offset topic will inform them where to start reading from.