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

Fix port script fails when DB has no backfilled events. #8729

Merged
merged 3 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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/8729.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix port script fails when DB has no backfilled events. Broke in v1.21.0.
2 changes: 1 addition & 1 deletion scripts/synapse_port_db
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ class Porter(object):
"ALTER SEQUENCE events_stream_seq RESTART WITH %s", (next_id,)
)

txn.execute("SELECT -MIN(stream_ordering) FROM events")
txn.execute("SELECT GREATEST(-MIN(stream_ordering), 1) FROM events")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this does fix things, but what is the purpose of negating the minimum stream_ordering here? And wouldn't using GREATEST and - here mean that we almost always end up with 1 as it's greater?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stream_ordering is negative for backfilled events, so if e.g. the min is -52, then GREATEST(- -52 1) is 52, while if there are no backfilled events we may end up with a positive min so we get GREATEST(-1, 1) which is 1.

curr_id = txn.fetchone()[0]
if curr_id:
richvdh marked this conversation as resolved.
Show resolved Hide resolved
next_id = curr_id + 1
Expand Down