diff options
author | Richard van der Hoff <richard@matrix.org> | 2020-07-16 10:58:12 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2020-07-16 11:25:08 +0100 |
commit | 3c36ae17a53987ed1ba40910f548d759883ab20a (patch) | |
tree | b50c45f8fa824a982034698188e9fec11b3c20c7 /synapse/storage/data_stores | |
parent | Use `PostgresSequenceGenerator` from `MultiWriterIdGenerator` (diff) | |
download | synapse-3c36ae17a53987ed1ba40910f548d759883ab20a.tar.xz |
Use SequenceGenerator for state group ID allocation
Diffstat (limited to 'synapse/storage/data_stores')
-rw-r--r-- | synapse/storage/data_stores/state/store.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/synapse/storage/data_stores/state/store.py b/synapse/storage/data_stores/state/store.py index 5db9f20135..128c09a2cf 100644 --- a/synapse/storage/data_stores/state/store.py +++ b/synapse/storage/data_stores/state/store.py @@ -24,6 +24,8 @@ from synapse.storage._base import SQLBaseStore from synapse.storage.data_stores.state.bg_updates import StateBackgroundUpdateStore from synapse.storage.database import Database from synapse.storage.state import StateFilter +from synapse.storage.types import Cursor +from synapse.storage.util.sequence import build_sequence_generator from synapse.types import StateMap from synapse.util.caches.descriptors import cached from synapse.util.caches.dictionary_cache import DictionaryCache @@ -92,6 +94,14 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore): "*stateGroupMembersCache*", 500000, ) + def get_max_state_group_txn(txn: Cursor): + txn.execute("SELECT COALESCE(max(id), 0) FROM state_groups") + return txn.fetchone()[0] + + self._state_group_seq_gen = build_sequence_generator( + self.database_engine, get_max_state_group_txn, "state_group_id_seq" + ) + @cached(max_entries=10000, iterable=True) def get_state_group_delta(self, state_group): """Given a state group try to return a previous group and a delta between @@ -386,7 +396,7 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore): # AFAIK, this can never happen raise Exception("current_state_ids cannot be None") - state_group = self.database_engine.get_next_state_group_id(txn) + state_group = self._state_group_seq_gen.get_next_id_txn(txn) self.db.simple_insert_txn( txn, |