From 07aa6b6259b236b93c491456d6e1e5ef3b2d878c Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 14 Jan 2021 16:16:39 +0000 Subject: [PATCH 1/2] Fix get destinations to catch up query. It was doing a sequential scan on `destination_rooms`, which took minutes. --- .../storage/databases/main/transactions.py | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/synapse/storage/databases/main/transactions.py b/synapse/storage/databases/main/transactions.py index 59207cadd429..cea595ff1940 100644 --- a/synapse/storage/databases/main/transactions.py +++ b/synapse/storage/databases/main/transactions.py @@ -464,19 +464,17 @@ def _get_catch_up_outstanding_destinations_txn( txn: LoggingTransaction, now_time_ms: int, after_destination: Optional[str] ) -> List[str]: q = """ - SELECT destination FROM destinations - WHERE destination IN ( - SELECT destination FROM destination_rooms - WHERE destination_rooms.stream_ordering > - destinations.last_successful_stream_ordering - ) - AND destination > ? - AND ( - retry_last_ts IS NULL OR - retry_last_ts + retry_interval < ? - ) - ORDER BY destination - LIMIT 25 + SELECT DISTINCT destination FROM destinations + INNER JOIN destination_rooms USING (destination) + WHERE + stream_ordering > last_successful_stream_ordering + AND destination > ? + AND ( + retry_last_ts IS NULL OR + retry_last_ts + retry_interval < ? + ) + ORDER BY destination + LIMIT 25 """ txn.execute( q, From bf9cffdb9be220c5bd416de58508583b810c8ff7 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 14 Jan 2021 16:24:14 +0000 Subject: [PATCH 2/2] Newsfile --- changelog.d/9114.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/9114.bugfix diff --git a/changelog.d/9114.bugfix b/changelog.d/9114.bugfix new file mode 100644 index 000000000000..77112abd5cec --- /dev/null +++ b/changelog.d/9114.bugfix @@ -0,0 +1 @@ +Fix bug in federation catchup logic that caused outbound federation to be delayed for large servers after start up. Introduced in v1.21.0.