diff options
author | Erik Johnston <erikj@jki.re> | 2018-02-06 14:31:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-06 14:31:24 +0000 |
commit | 3d33eef6fcbba474664a9bccdcb8822c6f72ee8c (patch) | |
tree | ad7a2201514be1acebc9ef72a10e9cbcc7f6696c /synapse/storage/engines/sqlite3.py | |
parent | Merge pull request #2849 from matrix-org/rav/clean_up_state_delta (diff) | |
download | synapse-3d33eef6fcbba474664a9bccdcb8822c6f72ee8c.tar.xz |
Store state groups separately from events (#2784)
* Split state group persist into seperate storage func * Add per database engine code for state group id gen * Move store_state_group to StateReadStore This allows other workers to use it, and so resolve state. * Hook up store_state_group * Fix tests * Rename _store_mult_state_groups_txn * Rename StateGroupReadStore * Remove redundant _have_persisted_state_group_txn * Update comments * Comment compute_event_context * Set start val for state_group_id_seq ... otherwise we try to recreate old state groups * Update comments * Don't store state for outliers * Update comment * Update docstring as state groups are ints
Diffstat (limited to 'synapse/storage/engines/sqlite3.py')
-rw-r--r-- | synapse/storage/engines/sqlite3.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/synapse/storage/engines/sqlite3.py b/synapse/storage/engines/sqlite3.py index 755c9a1f07..60f0fa7fb3 100644 --- a/synapse/storage/engines/sqlite3.py +++ b/synapse/storage/engines/sqlite3.py @@ -16,6 +16,7 @@ from synapse.storage.prepare_database import prepare_database import struct +import threading class Sqlite3Engine(object): @@ -24,6 +25,11 @@ class Sqlite3Engine(object): def __init__(self, database_module, database_config): self.module = database_module + # The current max state_group, or None if we haven't looked + # in the DB yet. + self._current_state_group_id = None + self._current_state_group_id_lock = threading.Lock() + def check_database(self, txn): pass @@ -43,6 +49,19 @@ class Sqlite3Engine(object): def lock_table(self, txn, table): return + def get_next_state_group_id(self, txn): + """Returns an int that can be used as a new state_group ID + """ + # We do application locking here since if we're using sqlite then + # we are a single process synapse. + with self._current_state_group_id_lock: + if self._current_state_group_id is None: + txn.execute("SELECT COALESCE(max(id), 0) FROM state_groups") + self._current_state_group_id = txn.fetchone()[0] + + self._current_state_group_id += 1 + return self._current_state_group_id + # Following functions taken from: https://github.com/coleifer/peewee |