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

fix: Cleanup backpressure state between assignments #299

Merged
merged 1 commit into from
Nov 6, 2023
Merged
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
19 changes: 12 additions & 7 deletions arroyo/processing/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def _close_strategy() -> None:
)
self.__processing_strategy = None
self.__message = None # avoid leaking buffered messages across assignments
self.__is_paused = False
self._clear_backpressure()

self.__metrics_buffer.incr_timing(
"arroyo.consumer.shutdown.time", time.time() - start_close
Expand Down Expand Up @@ -262,7 +264,7 @@ def __commit(self, offsets: Mapping[Partition, int], force: bool = False) -> Non
If force is passed, commit immediately and do not throttle. This should
be used during consumer shutdown where we do not want to wait before committing.
"""
for (partition, offset) in offsets.items():
for partition, offset in offsets.items():
self.__buffered_messages.pop(partition, offset - 1)

self.__consumer.stage_offsets(offsets)
Expand Down Expand Up @@ -306,6 +308,14 @@ def run(self) -> None:
logger.info("Processor terminated")
raise

def _clear_backpressure(self) -> None:
if self.__backpressure_timestamp is not None:
self.__metrics_buffer.incr_timing(
"arroyo.consumer.paused.time",
time.time() - self.__backpressure_timestamp,
)
self.__backpressure_timestamp = None

def _handle_invalid_message(self, exc: InvalidMessage) -> None:
# Do not "carry over" message if it is the invalid one. Every other
# message should be re-submitted to the strategy.
Expand Down Expand Up @@ -419,12 +429,7 @@ def _run_once(self) -> None:
self.__is_paused = False

# Clear backpressure timestamp if it is set
if self.__backpressure_timestamp is not None:
self.__metrics_buffer.incr_timing(
"arroyo.consumer.paused.time",
time.time() - self.__backpressure_timestamp,
)
self.__backpressure_timestamp = None
self._clear_backpressure()

self.__message = None
else:
Expand Down
Loading