ANALYZE new stream ordering column (#10326)

Fixes #10325
pull/10331/head
Brendan Abolivier 2021-07-07 11:56:17 +02:00 committed by GitHub
parent 994722410a
commit 9ad8455895
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

1
changelog.d/10326.bugfix Normal file
View File

@ -0,0 +1 @@
Fix a long-standing bug where Synapse would return errors after 2<sup>31</sup> events were handled by the server.

View File

@ -1146,6 +1146,16 @@ class EventsBackgroundUpdatesStore(SQLBaseStore):
logger.info("completing stream_ordering migration: %s", sql) logger.info("completing stream_ordering migration: %s", sql)
txn.execute(sql) txn.execute(sql)
# ANALYZE the new column to build stats on it, to encourage PostgreSQL to use the
# indexes on it.
# We need to pass execute a dummy function to handle the txn's result otherwise
# it tries to call fetchall() on it and fails because there's no result to fetch.
await self.db_pool.execute(
"background_analyze_new_stream_ordering_column",
lambda txn: None,
"ANALYZE events(stream_ordering2)",
)
await self.db_pool.runInteraction( await self.db_pool.runInteraction(
"_background_replace_stream_ordering_column", process "_background_replace_stream_ordering_column", process
) )