Use `PostgresSequenceGenerator` from `MultiWriterIdGenerator`

partly just to show it works, but alwo to remove a bit of code duplication.
This commit is contained in:
Richard van der Hoff 2020-07-16 10:56:49 +01:00
parent 90b0cdda42
commit 42509b8fb6
1 changed files with 4 additions and 4 deletions

View File

@ -21,6 +21,7 @@ from typing import Dict, Set, Tuple
from typing_extensions import Deque from typing_extensions import Deque
from synapse.storage.database import Database, LoggingTransaction from synapse.storage.database import Database, LoggingTransaction
from synapse.storage.util.sequence import PostgresSequenceGenerator
class IdGenerator(object): class IdGenerator(object):
@ -247,7 +248,6 @@ class MultiWriterIdGenerator:
): ):
self._db = db self._db = db
self._instance_name = instance_name self._instance_name = instance_name
self._sequence_name = sequence_name
# We lock as some functions may be called from DB threads. # We lock as some functions may be called from DB threads.
self._lock = threading.Lock() self._lock = threading.Lock()
@ -260,6 +260,8 @@ class MultiWriterIdGenerator:
# should be less than the minimum of this set (if not empty). # should be less than the minimum of this set (if not empty).
self._unfinished_ids = set() # type: Set[int] self._unfinished_ids = set() # type: Set[int]
self._sequence_gen = PostgresSequenceGenerator(sequence_name)
def _load_current_ids( def _load_current_ids(
self, db_conn, table: str, instance_column: str, id_column: str self, db_conn, table: str, instance_column: str, id_column: str
) -> Dict[str, int]: ) -> Dict[str, int]:
@ -283,9 +285,7 @@ class MultiWriterIdGenerator:
return current_positions return current_positions
def _load_next_id_txn(self, txn): def _load_next_id_txn(self, txn):
txn.execute("SELECT nextval(?)", (self._sequence_name,)) return self._sequence_gen.get_next_id_txn(txn)
(next_id,) = txn.fetchone()
return next_id
async def get_next(self): async def get_next(self):
""" """