@@ -436,7 +436,6 @@ class Consumer(Service, ConsumerT):
436436 flow_active : bool = True
437437 can_resume_flow : Event
438438 suspend_flow : Event
439- not_waiting_next_records : Event
440439
441440 def __init__ (
442441 self ,
@@ -478,8 +477,6 @@ def __init__(
478477 self .randomly_assigned_topics = set ()
479478 self .can_resume_flow = Event ()
480479 self .suspend_flow = Event ()
481- self .not_waiting_next_records = Event ()
482- self .not_waiting_next_records .set ()
483480 self ._reset_state ()
484481 super ().__init__ (loop = loop or self .transport .loop , ** kwargs )
485482 self .transactions = self .transport .create_transaction_manager (
@@ -503,7 +500,6 @@ def _reset_state(self) -> None:
503500 self ._buffered_partitions = set ()
504501 self .can_resume_flow .clear ()
505502 self .suspend_flow .clear ()
506- self .not_waiting_next_records .set ()
507503 self .flow_active = True
508504 self ._time_start = monotonic ()
509505
@@ -585,11 +581,6 @@ def stop_flow(self) -> None:
585581 self .can_resume_flow .clear ()
586582 self .suspend_flow .set ()
587583
588- async def wait_for_stopped_flow (self ) -> None :
589- """Wait until the consumer is not waiting on any newly fetched records."""
590- if not self .not_waiting_next_records .is_set ():
591- await self .not_waiting_next_records .wait ()
592-
593584 def resume_flow (self ) -> None :
594585 """Allow consumer to process messages."""
595586 self .flow_active = True
@@ -742,48 +733,40 @@ async def getmany(self, timeout: float) -> AsyncIterator[Tuple[TP, Message]]:
742733 self .app .monitor .track_tp_end_offset (tp , highwater_mark )
743734 # convert timestamp to seconds from int milliseconds.
744735 yield tp , to_message (tp , record )
736+ else :
737+ self .log .dev (
738+ "getmany called while flow not active. Seek back to committed offsets."
739+ )
740+ await self .perform_seek ()
745741
746742 async def _wait_next_records (
747743 self , timeout : float
748744 ) -> Tuple [Optional [RecordMap ], Optional [Set [TP ]]]:
749745 if not self .flow_active :
750746 await self .wait (self .can_resume_flow )
747+
751748 # Implementation for the Fetcher service.
752- try :
753- self .not_waiting_next_records .clear ()
749+ is_client_only = self .app .client_only
754750
755- is_client_only = self .app .client_only
751+ active_partitions : Optional [Set [TP ]]
752+ if is_client_only :
753+ active_partitions = None
754+ else :
755+ active_partitions = self ._get_active_partitions ()
756756
757- active_partitions : Optional [Set [TP ]]
758- if is_client_only :
759- active_partitions = None
760- else :
761- active_partitions = self ._get_active_partitions ()
762-
763- records : RecordMap = {}
764- if is_client_only or active_partitions :
765- # Fetch records only if active partitions to avoid the risk of
766- # fetching all partitions in the beginning when none of the
767- # partitions is paused/resumed.
768- suspend_flow = self .suspend_flow .wait ()
769- getmany = self ._getmany (
770- active_partitions = active_partitions ,
771- timeout = timeout ,
772- )
773- wait_results = await self .wait_first (getmany , suspend_flow )
774- for coro , result in zip (wait_results .done , wait_results .results ):
775- # Ignore records fetched while flow was suspended
776- if coro is suspend_flow :
777- records = {}
778- break
779- if coro is getmany :
780- records = result
781- else :
782- # We should still release to the event loop
783- await self .sleep (1 )
784- return records , active_partitions
785- finally :
786- self .not_waiting_next_records .set ()
757+ records : RecordMap = {}
758+ if is_client_only or active_partitions :
759+ # Fetch records only if active partitions to avoid the risk of
760+ # fetching all partitions in the beginning when none of the
761+ # partitions is paused/resumed.
762+ records = await self ._getmany (
763+ active_partitions = active_partitions ,
764+ timeout = timeout ,
765+ )
766+ else :
767+ # We should still release to the event loop
768+ await self .sleep (1 )
769+ return records , active_partitions
787770
788771 @abc .abstractmethod
789772 def _to_message (self , tp : TP , record : Any ) -> ConsumerMessage :
0 commit comments