Repository navigation
Share one lifted committer per consumer in injectK - #297
Merged
Merged
Conversation
`injectK` lifted every record with `CommittableConsumerRecord#mapK`, and fs2-kafka's `KafkaCommitter#mapK` allocates a new committer on each call. `CommittableOffsetBatch` groups offsets by committer identity, so a batch of lifted records held one committer per record and `commitBatchWithin` issued one parallel `commitAsync` per record instead of a single merged commit, with no ordering guarantee between them. The lift now happens once per underlying committer: `P.liftK` is built once per stream, a `mapAccumulate` over the unwrapped `WriterT` keeps a map from each original committer to its lifted counterpart, and every record is rebuilt around the shared one. `CommittableOffset.apply` is package-private, so `LiftedCommittableOffset` in package `fs2.kafka` performs that rebuild. The new spec runs three records over two partitions through `injectK` and checks the batch has one committer and commits once with the latest offset of each partition; it fails with three on the previous implementation.
Oliver-Taylor
approved these changes
Sep 28, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 What's included in this PR?
Follow-up to #293.
injectKlifted every record withCommittableConsumerRecord#mapK, and fs2-kafka'sKafkaCommitter#mapKallocates a new committer on each call.CommittableOffsetBatchgroups offsets by committer identity, so a batch of lifted records held one committer per record:commitBatchWithin(orCommittableOffsetBatch.fromFoldable) issued one parallelcommitAsyncper record instead of a single merged commit, with no ordering guarantee between them.The lift now happens once per underlying committer.
P.liftKis built once per stream, amapAccumulateover the unwrappedWriterTkeeps a map from each original committer to its lifted counterpart, and every record is rebuilt around the shared one.CommittableOffset.applyis package-private in fs2-kafka, so a smallLiftedCommittableOffsetobject in packagefs2.kafkaperforms the rebuild; it can go once fs2-kafka givesmapKstructural equality.TracedConsumerSpecruns three records over two partitions throughinjectKand checks the batch has one committer and commits once with the latest offset of each partition. It fails with three committers on the previous implementation.