@@ -166,7 +166,6 @@ private[kafka] final class KafkaConsumerActor[F[_], K, V](
166166 private [this ] def fetch (
167167 partition : TopicPartition ,
168168 streamId : StreamId ,
169- partitionStreamId : PartitionStreamId ,
170169 callback : ((Chunk [CommittableConsumerRecord [F , K , V ]], FetchCompletedReason )) => F [Unit ]
171170 ): F [Unit ] = {
172171 val assigned =
@@ -176,7 +175,7 @@ private[kafka] final class KafkaConsumerActor[F[_], K, V](
176175 ref
177176 .modify { state =>
178177 val (newState, oldFetch) =
179- state.withFetch(partition, streamId, partitionStreamId, callback)
178+ state.withFetch(partition, streamId, callback)
180179 (newState, (newState, oldFetch))
181180 }
182181 .flatMap {
@@ -567,8 +566,8 @@ private[kafka] final class KafkaConsumerActor[F[_], K, V](
567566 case Request .Assign (partitions, callback) => assign(partitions, callback)
568567 case Request .SubscribePattern (pattern, callback) => subscribe(pattern, callback)
569568 case Request .Unsubscribe (callback) => unsubscribe(callback)
570- case Request .Fetch (partition, streamId, partitionStreamId, callback) =>
571- fetch(partition, streamId, partitionStreamId, callback)
569+ case Request .Fetch (partition, streamId, callback) =>
570+ fetch(partition, streamId, callback)
572571 case request @ Request .Commit (_, _) => commit(request)
573572 case request @ Request .ManualCommitAsync (_, _) => manualCommitAsync(request)
574573 case request @ Request .ManualCommitSync (_, _) => manualCommitSync(request)
@@ -634,11 +633,9 @@ private[kafka] object KafkaConsumerActor {
634633 }
635634
636635 type StreamId = Int
637- type PartitionStreamId = Int
638636
639637 final case class State [F [_], K , V ](
640638 fetches : Map [TopicPartition , Map [StreamId , FetchRequest [F , K , V ]]],
641- partitionStreamIds : Map [TopicPartition , PartitionStreamId ],
642639 records : Map [TopicPartition , NonEmptyVector [CommittableConsumerRecord [F , K , V ]]],
643640 pendingCommits : Chain [Request .Commit [F , K , V ]],
644641 onRebalances : Chain [OnRebalance [F , K , V ]],
@@ -655,48 +652,29 @@ private[kafka] object KafkaConsumerActor {
655652 def withFetch (
656653 partition : TopicPartition ,
657654 streamId : StreamId ,
658- partitionStreamId : PartitionStreamId ,
659655 callback : ((Chunk [CommittableConsumerRecord [F , K , V ]], FetchCompletedReason )) => F [Unit ]
660656 ): (State [F , K , V ], List [FetchRequest [F , K , V ]]) = {
661657 val newFetchRequest =
662658 FetchRequest (callback)
663659
664- val oldPartitionFetches =
660+ val oldPartitionFetches : Map [ StreamId , FetchRequest [ F , K , V ]] =
665661 fetches.getOrElse(partition, Map .empty)
666662
667- val oldPartitionFetch =
668- oldPartitionFetches.get (streamId)
663+ val newFetches : Map [ TopicPartition , Map [ StreamId , FetchRequest [ F , K , V ]]] =
664+ fetches.updated(partition, oldPartitionFetches.updated (streamId, newFetchRequest) )
669665
670- val oldPartitionStreamId =
671- partitionStreamIds.getOrElse(partition, 0 )
672-
673- val hasMoreRecentPartitionStreamIds =
674- oldPartitionStreamId > partitionStreamId
675-
676- val newFetches =
677- fetches.updated(partition, {
678- if (hasMoreRecentPartitionStreamIds) oldPartitionFetches - streamId
679- else oldPartitionFetches.updated(streamId, newFetchRequest)
680- })
681-
682- val newPartitionStreamIds =
683- partitionStreamIds.updated(partition, oldPartitionStreamId max partitionStreamId)
684-
685- val fetchesToRevoke =
686- if (hasMoreRecentPartitionStreamIds)
687- newFetchRequest :: oldPartitionFetch.toList
688- else oldPartitionFetch.toList
666+ val fetchesToRevoke : List [FetchRequest [F , K , V ]] =
667+ oldPartitionFetches.get(streamId).toList
689668
690669 (
691- copy(fetches = newFetches, partitionStreamIds = newPartitionStreamIds ),
670+ copy(fetches = newFetches),
692671 fetchesToRevoke
693672 )
694673 }
695674
696675 def withoutFetches (partitions : Set [TopicPartition ]): State [F , K , V ] =
697676 copy(
698- fetches = fetches.filterKeysStrict(! partitions.contains(_)),
699- partitionStreamIds = partitionStreamIds.filterKeysStrict(! partitions.contains(_))
677+ fetches = fetches.filterKeysStrict(! partitions.contains(_))
700678 )
701679
702680 def withRecords (
@@ -707,7 +685,6 @@ private[kafka] object KafkaConsumerActor {
707685 def withoutFetchesAndRecords (partitions : Set [TopicPartition ]): State [F , K , V ] =
708686 copy(
709687 fetches = fetches.filterKeysStrict(! partitions.contains(_)),
710- partitionStreamIds = partitionStreamIds.filterKeysStrict(! partitions.contains(_)),
711688 records = records.filterKeysStrict(! partitions.contains(_))
712689 )
713690
@@ -743,25 +720,14 @@ private[kafka] object KafkaConsumerActor {
743720 append(fs.mkString(" [" , " , " , " ]" ))
744721 }(" " , " , " , " " )
745722
746- val partitionStreamIdsString =
747- partitionStreamIds.toList
748- .sortBy { case (tp, _) => tp }
749- .mkStringAppend {
750- case (append, (tp, id)) =>
751- append(tp.toString)
752- append(" -> " )
753- append(id.toString)
754- }(" " , " , " , " " )
755-
756- s " State(fetches = Map( $fetchesString), partitionStreamIds = Map( $partitionStreamIdsString), records = Map( ${recordsString(records)}), pendingCommits = $pendingCommits, onRebalances = $onRebalances, rebalancing = $rebalancing, subscribed = $subscribed, streaming = $streaming) "
723+ s " State(fetches = Map( $fetchesString), records = Map( ${recordsString(records)}), pendingCommits = $pendingCommits, onRebalances = $onRebalances, rebalancing = $rebalancing, subscribed = $subscribed, streaming = $streaming) "
757724 }
758725 }
759726
760727 object State {
761728 def empty [F [_], K , V ]: State [F , K , V ] =
762729 State (
763730 fetches = Map .empty,
764- partitionStreamIds = Map .empty,
765731 records = Map .empty,
766732 pendingCommits = Chain .empty,
767733 onRebalances = Chain .empty,
@@ -830,7 +796,6 @@ private[kafka] object KafkaConsumerActor {
830796 final case class Fetch [F [_], K , V ](
831797 partition : TopicPartition ,
832798 streamId : StreamId ,
833- partitionStreamId : PartitionStreamId ,
834799 callback : ((Chunk [CommittableConsumerRecord [F , K , V ]], FetchCompletedReason )) => F [Unit ]
835800 ) extends Request [F , K , V ]
836801
0 commit comments