Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Tidy up get current token for writer
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Oct 20, 2023
1 parent 79fb6fe commit 56e7fb3
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions synapse/storage/util/id_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,28 +726,24 @@ def get_current_token_for_writer(self, instance_name: str) -> int:
instance_name, self._persisted_upto_position
)

max_pos = max(
self._current_positions.values(), default=self._persisted_upto_position
)

# We want to return the maximum "current token" that we can for a
# writer, this helps ensure that streams progress as fast as
# possible.
pos = max(pos, self._persisted_upto_position)

if (
self._instance_name == instance_name
and self._in_flight_fetches
and self._unfinished_ids
and not self._in_flight_fetches
and not self._unfinished_ids
):
# For our own instance when there's nothing in flight, it's safe
# to advance to the maximum persisted position we've seen (as we
# know that any new tokens we request will be greater).
max_pos = max(
max_pos_of_all_writers = max(
self._current_positions.values(),
default=self._persisted_upto_position,
)
pos = max(pos, max_pos)
pos = max(pos, max_pos_of_all_writers)

return self._return_factor * pos

Expand Down

0 comments on commit 56e7fb3

Please sign in to comment.