Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1778917

Browse files
committedJun 17, 2024··
Make sure we load after the sequence has been fixed up
1 parent 59ce4a4 commit 1778917

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed
 

Diff for: ‎synapse/storage/util/id_generators.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,6 @@ def __init__(
278278
# no active writes in progress.
279279
self._max_position_of_local_instance = self._max_seen_allocated_stream_id
280280

281-
# This goes and fills out the above state from the database.
282-
self._load_current_ids(db_conn, tables, sequence_name)
283-
284281
self._sequence_gen = build_sequence_generator(
285282
db_conn=db_conn,
286283
database_engine=db.engine,
@@ -305,6 +302,13 @@ def __init__(
305302
positive=positive,
306303
)
307304

305+
# This goes and fills out the above state from the database.
306+
# This may read on the PostgreSQL sequence, and
307+
# SequenceGenerator.check_consistency might have fixed up the sequence, which
308+
# means the SequenceGenerator needs to be setup before we read the value from
309+
# the sequence.
310+
self._load_current_ids(db_conn, tables, sequence_name)
311+
308312
self._max_seen_allocated_stream_id = max(
309313
self._current_positions.values(), default=1
310314
)
@@ -373,9 +377,7 @@ def _load_current_ids(
373377
cur.execute(f"SELECT last_value FROM {sequence_name}")
374378
row = cur.fetchone()
375379
assert row is not None
376-
self._current_positions[self._instance_name] = (
377-
row[0] * self._return_factor
378-
)
380+
self._current_positions[self._instance_name] = row[0]
379381

380382
# We set the `_persisted_upto_position` to be the minimum of all current
381383
# positions. If empty we use the max stream ID from the DB table.

0 commit comments

Comments
 (0)
Please sign in to comment.