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

Commit

Permalink
Remove no-op send_command for Redis replication. (#15274)
Browse files Browse the repository at this point in the history
With Redis commands do not need to be re-issued by the main
process (they fan-out to all processes at once) and thus it is no
longer necessary to worry about them reflecting recursively forever.
  • Loading branch information
clokep committed Mar 16, 2023
1 parent b0a0fb5 commit afb216c
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 89 deletions.
2 changes: 1 addition & 1 deletion changelog.d/15272.misc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Remove unused class `DirectTcpReplicationClientFactory`.
Clean-up direct TCP replication code.
1 change: 1 addition & 0 deletions changelog.d/15274.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean-up direct TCP replication code.
26 changes: 1 addition & 25 deletions synapse/replication/tcp/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,23 +625,6 @@ def on_REMOTE_SERVER_UP(

self._notifier.notify_remote_server_up(cmd.data)

# We relay to all other connections to ensure every instance gets the
# notification.
#
# When configured to use redis we'll always only have one connection and
# so this is a no-op (all instances will have already received the same
# REMOTE_SERVER_UP command).
#
# For direct TCP connections this will relay to all other connections
# connected to us. When on master this will correctly fan out to all
# other direct TCP clients and on workers there'll only be the one
# connection to master.
#
# (The logic here should also be sound if we have a mix of Redis and
# direct TCP connections so long as there is only one traffic route
# between two instances, but that is not currently supported).
self.send_command(cmd, ignore_conn=conn)

def new_connection(self, connection: IReplicationConnection) -> None:
"""Called when we have a new connection."""
self._connections.append(connection)
Expand Down Expand Up @@ -689,21 +672,14 @@ def connected(self) -> bool:
"""
return bool(self._connections)

def send_command(
self, cmd: Command, ignore_conn: Optional[IReplicationConnection] = None
) -> None:
def send_command(self, cmd: Command) -> None:
"""Send a command to all connected connections.
Args:
cmd
ignore_conn: If set don't send command to the given connection.
Used when relaying commands from one connection to all others.
"""
if self._connections:
for connection in self._connections:
if connection == ignore_conn:
continue

try:
connection.send_command(cmd)
except Exception:
Expand Down
63 changes: 0 additions & 63 deletions tests/replication/tcp/test_remote_server_up.py

This file was deleted.

0 comments on commit afb216c

Please sign in to comment.