From 3353d35dc0f28b3160529af7d05d44ae759e557c Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Tue, 9 Jul 2024 21:25:06 +0100 Subject: [PATCH 1/3] Only log once when waiting for current token to catch up Rather than once every 0.5s --- synapse/notifier.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/synapse/notifier.py b/synapse/notifier.py index c3ecf86ec4f..7a2b54036c3 100644 --- a/synapse/notifier.py +++ b/synapse/notifier.py @@ -773,6 +773,7 @@ async def wait_for_stream_token(self, stream_token: StreamToken) -> bool: stream_token = await self.event_sources.bound_future_token(stream_token) start = self.clock.time_msec() + logged = False while True: current_token = self.event_sources.get_current_token() if stream_token.is_before_or_eq(current_token): @@ -783,11 +784,13 @@ async def wait_for_stream_token(self, stream_token: StreamToken) -> bool: if now - start > 10_000: return False - logger.info( - "Waiting for current token to reach %s; currently at %s", - stream_token, - current_token, - ) + if not logged: + logger.info( + "Waiting for current token to reach %s; currently at %s", + stream_token, + current_token, + ) + logged = True # TODO: be better await self.clock.sleep(0.5) From 0062c9ea00d0f7257043e1fb96aed3709cb32658 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Tue, 9 Jul 2024 21:27:52 +0100 Subject: [PATCH 2/3] Newsfile Signed-off-by: Olivier 'reivilibre --- changelog.d/17428.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/17428.bugfix diff --git a/changelog.d/17428.bugfix b/changelog.d/17428.bugfix new file mode 100644 index 00000000000..cbfd7b0c39b --- /dev/null +++ b/changelog.d/17428.bugfix @@ -0,0 +1 @@ +Reduce volume of 'Waiting for current token' logs, which were introduced in v1.109.0. \ No newline at end of file From ac7ebb8b14746d88dcbcc835c89eaf030a6bc4d8 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Wed, 10 Jul 2024 16:31:02 +0100 Subject: [PATCH 3/3] Use shorter formatting for StreamToken --- synapse/types/__init__.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/synapse/types/__init__.py b/synapse/types/__init__.py index b22a13ef016..fc46db80a6c 100644 --- a/synapse/types/__init__.py +++ b/synapse/types/__init__.py @@ -740,6 +740,13 @@ def bound_stream_token(self, max_stream: int) -> "RoomStreamToken": return super().bound_stream_token(max_stream) + def __str__(self) -> str: + instances = ", ".join(f"{k}: {v}" for k, v in sorted(self.instance_map.items())) + return ( + f"RoomStreamToken(stream: {self.stream}, topological: {self.topological}, " + f"instances: {{{instances}}})" + ) + @attr.s(frozen=True, slots=True, order=False) class MultiWriterStreamToken(AbstractMultiWriterStreamToken): @@ -824,6 +831,13 @@ def is_stream_position_in_range( return True + def __str__(self) -> str: + instances = ", ".join(f"{k}: {v}" for k, v in sorted(self.instance_map.items())) + return ( + f"MultiWriterStreamToken(stream: {self.stream}, " + f"instances: {{{instances}}})" + ) + class StreamKeyType(Enum): """Known stream types. @@ -1082,6 +1096,15 @@ def is_before_or_eq(self, other_token: "StreamToken") -> bool: return True + def __str__(self) -> str: + return ( + f"StreamToken(room: {self.room_key}, presence: {self.presence_key}, " + f"typing: {self.typing_key}, receipt: {self.receipt_key}, " + f"account_data: {self.account_data_key}, push_rules: {self.push_rules_key}, " + f"to_device: {self.to_device_key}, device_list: {self.device_list_key}, " + f"groups: {self.groups_key}, un_partial_stated_rooms: {self.un_partial_stated_rooms_key})" + ) + StreamToken.START = StreamToken( RoomStreamToken(stream=0), 0, 0, MultiWriterStreamToken(stream=0), 0, 0, 0, 0, 0, 0