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

ANALYZE new stream ordering column #10326

Merged
merged 8 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10326.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug where Synapse would return errors after 2<sup>31</sup> events were handled by the server.
babolivier marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions synapse/storage/databases/main/events_bg_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,11 +1141,20 @@ async def _background_replace_stream_ordering_column(
) -> int:
"""Drop the old 'stream_ordering' column and rename 'stream_ordering2' into its place."""

def analyze_new_column(txn: Cursor) -> None:
txn.execute("ANALYZE events(stream_ordering2)")

def process(txn: Cursor) -> None:
for sql in _REPLACE_STREAM_ORDERING_SQL_COMMANDS:
logger.info("completing stream_ordering migration: %s", sql)
txn.execute(sql)

# ANALYZE the new column to build stats on it, to encourage PostgreSQL to use the
# indexes on it.
await self.db_pool.runInteraction(
"_background_analyze_new_stream_ordering_column", analyze_new_column
)
babolivier marked this conversation as resolved.
Show resolved Hide resolved

await self.db_pool.runInteraction(
"_background_replace_stream_ordering_column", process
)
Expand Down