From a638116e9b4661f89523e4c13490df7bbcdb7429 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 17 Nov 2023 09:48:15 +0000 Subject: [PATCH 1/3] Also discard 'caches' stream POSITIONS Follow on from #16640 --- synapse/replication/tcp/streams/_base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/synapse/replication/tcp/streams/_base.py b/synapse/replication/tcp/streams/_base.py index cc34dfb322f9..f9d9f4387497 100644 --- a/synapse/replication/tcp/streams/_base.py +++ b/synapse/replication/tcp/streams/_base.py @@ -305,6 +305,14 @@ def minimal_local_current_token(self) -> Token: # which means we need to negate it. return -self.store._backfill_id_gen.get_minimal_local_current_token() + def can_discard_position( + self, instance_name: str, prev_token: int, new_token: int + ) -> bool: + # Caches streams can't go backwards, so we know we can ignore any + # positions where the tokens are from before the current token. + + return new_token <= self.current_token(instance_name) + class PresenceStream(_StreamFromIdGen): @attr.s(slots=True, frozen=True, auto_attribs=True) @@ -519,6 +527,14 @@ def minimal_local_current_token(self) -> Token: return self.store._cache_id_gen.get_minimal_local_current_token() return self.current_token(self.local_instance_name) + def can_discard_position( + self, instance_name: str, prev_token: int, new_token: int + ) -> bool: + # Caches streams can't go backwards, so we know we can ignore any + # positions where the tokens are from before the current token. + + return new_token <= self.current_token(instance_name) + class DeviceListsStream(_StreamFromIdGen): """Either a user has updated their devices or a remote server needs to be From 37b0f5d991a14c7ebd01bcec91b04d39affa7f5a Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 17 Nov 2023 09:48:59 +0000 Subject: [PATCH 2/3] Newsfile --- changelog.d/16655.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/16655.misc diff --git a/changelog.d/16655.misc b/changelog.d/16655.misc new file mode 100644 index 000000000000..3b1cc2185d20 --- /dev/null +++ b/changelog.d/16655.misc @@ -0,0 +1 @@ +More efficiently handle no-op `POSITION` over replication. From 2b91e8a9e8f7800f55294e2dfab60fd1f9576368 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 17 Nov 2023 13:13:17 +0000 Subject: [PATCH 3/3] Update synapse/replication/tcp/streams/_base.py --- synapse/replication/tcp/streams/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/replication/tcp/streams/_base.py b/synapse/replication/tcp/streams/_base.py index f9d9f4387497..1f6402c2da97 100644 --- a/synapse/replication/tcp/streams/_base.py +++ b/synapse/replication/tcp/streams/_base.py @@ -308,7 +308,7 @@ def minimal_local_current_token(self) -> Token: def can_discard_position( self, instance_name: str, prev_token: int, new_token: int ) -> bool: - # Caches streams can't go backwards, so we know we can ignore any + # Backfill stream can't go backwards, so we know we can ignore any # positions where the tokens are from before the current token. return new_token <= self.current_token(instance_name)