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

Commit

Permalink
Fix schema delta for servers that have not backfilled (#8396)
Browse files Browse the repository at this point in the history
Fixes #8395.
  • Loading branch information
erikjohnston authored Sep 25, 2020
1 parent c77c4a2 commit 3e87d79
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/8396.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add experimental support for sharding event persister.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ SELECT setval('events_stream_seq', (

CREATE SEQUENCE IF NOT EXISTS events_backfill_stream_seq;

-- If the server has never backfilled a room then doing `-MIN(...)` will give
-- a negative result, hence why we do `GREATEST(...)`
SELECT setval('events_backfill_stream_seq', (
SELECT COALESCE(-MIN(stream_ordering), 1) FROM events
SELECT GREATEST(COALESCE(-MIN(stream_ordering), 1), 1) FROM events
));
6 changes: 5 additions & 1 deletion synapse/storage/util/id_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,12 @@ def _load_current_ids(
min_stream_id = min(self._current_positions.values(), default=None)

if min_stream_id is None:
# We add a GREATEST here to ensure that the result is always
# positive. (This can be a problem for e.g. backfill streams where
# the server has never backfilled).
sql = """
SELECT COALESCE(%(agg)s(%(id)s), 1) FROM %(table)s
SELECT GREATEST(COALESCE(%(agg)s(%(id)s), 1), 1)
FROM %(table)s
""" % {
"id": id_column,
"table": table,
Expand Down

0 comments on commit 3e87d79

Please sign in to comment.