mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-29 15:39:00 +03:00
Fix schema delta for servers that have not backfilled (#8396)
Fixes #8395.
This commit is contained in:
parent
c77c4a2fcd
commit
3e87d79e1c
3 changed files with 9 additions and 2 deletions
1
changelog.d/8396.feature
Normal file
1
changelog.d/8396.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Add experimental support for sharding event persister.
|
|
@ -21,6 +21,8 @@ SELECT setval('events_stream_seq', (
|
||||||
|
|
||||||
CREATE SEQUENCE IF NOT EXISTS events_backfill_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 setval('events_backfill_stream_seq', (
|
||||||
SELECT COALESCE(-MIN(stream_ordering), 1) FROM events
|
SELECT GREATEST(COALESCE(-MIN(stream_ordering), 1), 1) FROM events
|
||||||
));
|
));
|
||||||
|
|
|
@ -287,8 +287,12 @@ class MultiWriterIdGenerator:
|
||||||
min_stream_id = min(self._current_positions.values(), default=None)
|
min_stream_id = min(self._current_positions.values(), default=None)
|
||||||
|
|
||||||
if min_stream_id is 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 = """
|
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,
|
"id": id_column,
|
||||||
"table": table,
|
"table": table,
|
||||||
|
|
Loading…
Reference in a new issue