kirktrue commented on PR #13920:
URL: https://github.com/apache/kafka/pull/13920#issuecomment-1609641313

   @flashmouse I'm a little slow on the uptake, so I'm trying to come up with a 
scenario. Let's say the following is true:
   
   * Topic `foo` has three partitions
   * The consumer group has two consumers, `consumer` and `otherConsumer`
   
   In the first case, let's say that `consumer` has one partition and 
`otherConsumer` has two. In that case it's as balanced as possible, right? But 
the code in `isBalanced` as written disagrees:
   
   ```java
   if (consumerPartitionCount < otherConsumerPartitionCount) {
       return false;
   }
   ```
   
   Because `1` is less than `2` 😄 But it's going to run into problems because 
by returning `false` from `isBalanced`, I assume we then trigger a rebalance, 
which—at best— will cause the ownership of that partition to move from 
`otherConsumer` to `consumer`. When the next balance check for is run, we're in 
the same position 🤷‍♂️ 
   
   But with your fix:
   
   ```java
   if (consumerPartitionCount + 1 < otherConsumerPartitionCount) {
       return false;
   }
   ```
   
   It's effectively stating that the `consumer` has to have _at least_ two 
partitions difference, correct? Because `1 + 1` is _not less_ then `2`.
   
   Do I have the above (mostly) correct?
   
   Thanks!


-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to