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

Fix schema delta for servers that have not backfilled #8396

Merged
merged 3 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all 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/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