-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wait for commits to complete in rebalance listener and on unsubscribe
This PR adds the setting `rebalanceSafeCommits`. When set to `true`, we hold up a rebalance until offsets for revoked partitions are committed. This allows the client that gets the partition assigned hereafter to start at the exact right offset, preventing duplicate processing. When `rebalanceSafeCommits` is set to `false` the previous behavior is active. This lets the old stream finish its work in the background while the new stream is already starting. The old behavior causes duplicate processing but can be a bit more performant since rebalances are not hold up. In order to handle commits while waiting for the streams to end, commits are added to a separate queue. To make sure the main poll loop knows about these commits, we also place a `CommitAvailable` value on the command queue. The rebalance listener ZIO effects (and other callbacks) are executed on the calling thread. This is required because the underlying Java client requires single threaded access. It rejects multiple concurrent invocation unless they are from the same thread, that is, the thread that executes the poll. (Remember, the rebalance listener and other callbacks are invoked by the Java client during a call to poll or commit.) Note though that ZIO operations that require time are not possible since these cause the workflow to shift to another thread. Once we know that all commits have been sent to the broker, we need to wait till the callbacks are called. We do this by calling `commitSync` with an empty map of offsets. CommitSync guarantees that all previously send commits complete before commitSync returns. (NOTE: requires patched Kafka client.) The rebalance listener no longer manipulates the state. The rebalance event only collects changes. The main poll loop then use those changes to construct the next state. When the rebalance listener was not invoked, we skip some tasks for a small performance improvement. Added WIP RebalanceSafeCommitConsumerSpec as a testbed for improved unit tests (and also to test the new commit-on-rebalance feature) Also: - End all streams when only onLost is invoked. - Disable zio-intellij's inspection `SimplifyWhenInspection` in Runloop because its suggestion is not equivalent (performance-wise). - Configure a low `max.poll.records` (100 instead of 1000) for tests. There was a concurrency bug that only failed a test the lower setting. The benchmarks continue to use 1000 for `max.poll.records`. - Prevent deadlock by doing unsubscribe with a single consumer access. - Await stream end on unsubscribe and shutdown as well. - Removed method `Runloop.awaitShutdown`, it is not used, not accessible and its semantics are questionable.
- Loading branch information
1 parent
d941b29
commit ac7f61b
Showing
12 changed files
with
1,641 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,081 changes: 1,081 additions & 0 deletions
1,081
zio-kafka-test/src/test/scala/zio/kafka/consumer/RebalanceSafeCommitConsumerSpec.scala
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.