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

Commit abef8ae

Browse files
committed
Properly setup the un_partial_stated_event_stream_sequence and application_services_txn_id_seq with the portdb script.
1 parent 7cbb2a0 commit abef8ae

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

changelog.d/16043.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a long-standing bug where the `synapse_port_db` failed to configure sequences for application services and partial stated rooms.

synapse/_scripts/synapse_port_db.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,14 +761,18 @@ def alter_table(txn: LoggingTransaction) -> None:
761761

762762
# Step 2. Set up sequences
763763
#
764-
# We do this before porting the tables so that event if we fail half
764+
# We do this before porting the tables so that even if we fail half
765765
# way through the postgres DB always have sequences that are greater
766766
# than their respective tables. If we don't then creating the
767767
# `DataStore` object will fail due to the inconsistency.
768768
self.progress.set_state("Setting up sequence generators")
769769
await self._setup_state_group_id_seq()
770770
await self._setup_user_id_seq()
771771
await self._setup_events_stream_seqs()
772+
await self._setup_sequence(
773+
"un_partial_stated_event_stream_sequence",
774+
("un_partial_stated_event_stream",),
775+
)
772776
await self._setup_sequence(
773777
"device_inbox_sequence", ("device_inbox", "device_federation_outbox")
774778
)
@@ -779,6 +783,11 @@ def alter_table(txn: LoggingTransaction) -> None:
779783
await self._setup_sequence("receipts_sequence", ("receipts_linearized",))
780784
await self._setup_sequence("presence_stream_sequence", ("presence_stream",))
781785
await self._setup_auth_chain_sequence()
786+
await self._setup_sequence(
787+
"application_services_txn_id_seq",
788+
("application_services_txns",),
789+
"txn_id",
790+
)
782791

783792
# Step 3. Get tables.
784793
self.progress.set_state("Fetching tables")
@@ -1083,7 +1092,10 @@ def _setup_events_stream_seqs_set_pos(txn: LoggingTransaction) -> None:
10831092
)
10841093

10851094
async def _setup_sequence(
1086-
self, sequence_name: str, stream_id_tables: Iterable[str]
1095+
self,
1096+
sequence_name: str,
1097+
stream_id_tables: Iterable[str],
1098+
column_name: str = "stream_id",
10871099
) -> None:
10881100
"""Set a sequence to the correct value."""
10891101
current_stream_ids = []
@@ -1093,7 +1105,7 @@ async def _setup_sequence(
10931105
await self.sqlite_store.db_pool.simple_select_one_onecol(
10941106
table=stream_id_table,
10951107
keyvalues={},
1096-
retcol="COALESCE(MAX(stream_id), 1)",
1108+
retcol=f"COALESCE(MAX({column_name}), 1)",
10971109
allow_none=True,
10981110
),
10991111
)

0 commit comments

Comments
 (0)