Skip to content

Commit

Permalink
Make sure we load after the sequence has been fixed up
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose committed Jun 17, 2024
1 parent 59ce4a4 commit 1778917
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions synapse/storage/util/id_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,6 @@ def __init__(
# no active writes in progress.
self._max_position_of_local_instance = self._max_seen_allocated_stream_id

# This goes and fills out the above state from the database.
self._load_current_ids(db_conn, tables, sequence_name)

self._sequence_gen = build_sequence_generator(
db_conn=db_conn,
database_engine=db.engine,
Expand All @@ -305,6 +302,13 @@ def __init__(
positive=positive,
)

# This goes and fills out the above state from the database.
# This may read on the PostgreSQL sequence, and
# SequenceGenerator.check_consistency might have fixed up the sequence, which
# means the SequenceGenerator needs to be setup before we read the value from
# the sequence.
self._load_current_ids(db_conn, tables, sequence_name)

self._max_seen_allocated_stream_id = max(
self._current_positions.values(), default=1
)
Expand Down Expand Up @@ -373,9 +377,7 @@ def _load_current_ids(
cur.execute(f"SELECT last_value FROM {sequence_name}")
row = cur.fetchone()
assert row is not None
self._current_positions[self._instance_name] = (
row[0] * self._return_factor
)
self._current_positions[self._instance_name] = row[0]

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

0 comments on commit 1778917

Please sign in to comment.