Browse Source
This commit adds explicit offset commit in the ConsumerGroupHandler.Cleanup() method, which is called during consumer group rebalancing. This ensures all marked offsets are committed BEFORE partitions are reassigned to other consumers, significantly reducing duplicate message consumption during rebalancing. Problem: - Cleanup() was not committing offsets before rebalancing - When partition reassigned to another consumer, it started from last committed offset - Uncommitted messages (processed but not yet committed) were read again by new consumer - This caused ~100-200% duplicate messages during rebalancing in tests Solution: - Add session.Commit() in Cleanup() method - This runs after all ConsumeClaim goroutines have exited - Ensures all MarkMessage() calls are committed before partition release - New consumer starts from the last processed offset, not an older committed offset Benefits: - Dramatically reduces duplicate messages during rebalancing - Improves at-least-once semantics (closer to exactly-once for normal cases) - Better performance (less redundant processing) - Cleaner test results (expected duplicates only from actual failures) Kafka Rebalancing Lifecycle: 1. Rebalance triggered (consumer join/leave, timeout, etc.) 2. All ConsumeClaim goroutines cancelled 3. Cleanup() called ← WE COMMIT HERE NOW 4. Partitions reassigned to other consumers 5. New consumer starts from last committed offset ← NOW MORE UP-TO-DATE Expected Results: - Before: ~100-200% duplicates during rebalancing (2-3x reads) - After: <10% duplicates (only from uncommitted in-flight messages) This is a critical fix for production deployments where consumer churn (scaling, restarts, failures) causes frequent rebalancing.pull/7329/head
1 changed files with 10 additions and 2 deletions
Loading…
Reference in new issue