Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent unlimited enqueueing of CommitAvailable commands #1390

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private[consumer] final class Runloop private (
sameThreadRuntime: Runtime[Any],
consumer: ConsumerAccess,
commandQueue: Queue[RunloopCommand],
commitAvailable: Queue[Boolean],
partitionsHub: Hub[Take[Throwable, PartitionAssignment]],
diagnostics: Diagnostics,
maxStreamPullInterval: Duration,
Expand Down Expand Up @@ -488,6 +489,7 @@ private[consumer] final class Runloop private (

ZStream
.fromQueue(commandQueue)
.merge(ZStream.fromQueue(commitAvailable).as(RunloopCommand.CommitAvailable))
.takeWhile(_ != RunloopCommand.StopRunloop)
.runFoldChunksDiscardZIO(initialState) { (state, commands) =>
for {
Expand Down Expand Up @@ -581,8 +583,10 @@ object Runloop {
partitionsHub: Hub[Take[Throwable, PartitionAssignment]]
): URIO[Scope, Runloop] =
for {
_ <- ZIO.addFinalizer(diagnostics.emit(Finalization.RunloopFinalized))
commandQueue <- ZIO.acquireRelease(Queue.unbounded[RunloopCommand])(_.shutdown)
_ <- ZIO.addFinalizer(diagnostics.emit(Finalization.RunloopFinalized))
commandQueue <- ZIO.acquireRelease(Queue.unbounded[RunloopCommand])(_.shutdown)
// A one-element dropping queue used to signal between two fibers that new commits are pending and we should poll
commitAvailable <- ZIO.acquireRelease(Queue.dropping[Boolean](1))(_.shutdown)
lastRebalanceEvent <- Ref.Synchronized.make[RebalanceEvent](RebalanceEvent.None)
initialState = State.initial
currentStateRef <- Ref.make(initialState)
Expand All @@ -594,7 +598,7 @@ object Runloop {
settings.commitTimeout,
diagnostics,
metrics,
commandQueue.offer(RunloopCommand.CommitAvailable).unit,
commitAvailable.offer(true).unit,
sameThreadRuntime
)
rebalanceCoordinator = new RebalanceCoordinator(
Expand All @@ -611,6 +615,7 @@ object Runloop {
sameThreadRuntime = sameThreadRuntime,
consumer = consumer,
commandQueue = commandQueue,
commitAvailable = commitAvailable,
partitionsHub = partitionsHub,
diagnostics = diagnostics,
maxStreamPullInterval = maxStreamPullInterval,
Expand Down