@@ -278,9 +278,6 @@ def __init__(
278
278
# no active writes in progress.
279
279
self ._max_position_of_local_instance = self ._max_seen_allocated_stream_id
280
280
281
- # This goes and fills out the above state from the database.
282
- self ._load_current_ids (db_conn , tables , sequence_name )
283
-
284
281
self ._sequence_gen = build_sequence_generator (
285
282
db_conn = db_conn ,
286
283
database_engine = db .engine ,
@@ -305,6 +302,13 @@ def __init__(
305
302
positive = positive ,
306
303
)
307
304
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
+
308
312
self ._max_seen_allocated_stream_id = max (
309
313
self ._current_positions .values (), default = 1
310
314
)
@@ -373,9 +377,7 @@ def _load_current_ids(
373
377
cur .execute (f"SELECT last_value FROM { sequence_name } " )
374
378
row = cur .fetchone ()
375
379
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 ]
379
381
380
382
# We set the `_persisted_upto_position` to be the minimum of all current
381
383
# positions. If empty we use the max stream ID from the DB table.
0 commit comments