-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Store state groups separately from events #2784
Changes from 9 commits
cb222e2
0f18d58
c8c8f53
1b2af72
2fdf245
e66f2c3
693ea27
a742398
90cd2e6
c695725
22be520
2694524
7018b68
a6b415c
4a72132
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,15 +208,22 @@ def compute_event_context(self, event, old_state=None): | |
context.current_state_ids = {} | ||
context.prev_state_ids = {} | ||
context.prev_state_events = [] | ||
context.state_group = self.store.get_next_state_group() | ||
|
||
context.state_group = yield self.store.store_state_group( | ||
event.event_id, | ||
event.room_id, | ||
prev_group=None, | ||
delta_ids=None, | ||
current_state_ids=context.current_state_ids, | ||
) | ||
|
||
defer.returnValue(context) | ||
|
||
if old_state: | ||
context = EventContext() | ||
context.prev_state_ids = { | ||
(s.type, s.state_key): s.event_id for s in old_state | ||
} | ||
context.state_group = self.store.get_next_state_group() | ||
|
||
if event.is_state(): | ||
key = (event.type, event.state_key) | ||
|
@@ -229,6 +236,14 @@ def compute_event_context(self, event, old_state=None): | |
else: | ||
context.current_state_ids = context.prev_state_ids | ||
|
||
context.state_group = yield self.store.store_state_group( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to create a new state_group if it's not a state event? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. Basically, we've been explicitly told the state at this point ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
event.event_id, | ||
event.room_id, | ||
prev_group=None, | ||
delta_ids=None, | ||
current_state_ids=context.current_state_ids, | ||
) | ||
|
||
context.prev_state_events = [] | ||
defer.returnValue(context) | ||
|
||
|
@@ -242,8 +257,6 @@ def compute_event_context(self, event, old_state=None): | |
context = EventContext() | ||
context.prev_state_ids = curr_state | ||
if event.is_state(): | ||
context.state_group = self.store.get_next_state_group() | ||
|
||
key = (event.type, event.state_key) | ||
if key in context.prev_state_ids: | ||
replaces = context.prev_state_ids[key] | ||
|
@@ -261,15 +274,30 @@ def compute_event_context(self, event, old_state=None): | |
context.prev_group = entry.prev_group | ||
context.delta_ids = dict(entry.delta_ids) | ||
context.delta_ids[key] = event.event_id | ||
|
||
context.state_group = yield self.store.store_state_group( | ||
event.event_id, | ||
event.room_id, | ||
prev_group=entry.prev_group, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. generally the logic in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That was a typo tbh.
I've tried to add some comments |
||
delta_ids=entry.delta_ids, | ||
current_state_ids=context.current_state_ids, | ||
) | ||
else: | ||
context.current_state_ids = context.prev_state_ids | ||
context.prev_group = entry.prev_group | ||
context.delta_ids = entry.delta_ids | ||
|
||
if entry.state_group is None: | ||
entry.state_group = self.store.get_next_state_group() | ||
entry.state_group = yield self.store.store_state_group( | ||
event.event_id, | ||
event.room_id, | ||
prev_group=entry.prev_group, | ||
delta_ids=entry.delta_ids, | ||
current_state_ids=context.current_state_ids, | ||
) | ||
entry.state_id = entry.state_group | ||
|
||
context.state_group = entry.state_group | ||
context.current_state_ids = context.prev_state_ids | ||
context.prev_group = entry.prev_group | ||
context.delta_ids = entry.delta_ids | ||
|
||
context.prev_state_events = [] | ||
defer.returnValue(context) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -742,9 +742,8 @@ def _persist_events_txn(self, txn, events_and_contexts, backfilled, | |
events_and_contexts=events_and_contexts, | ||
) | ||
|
||
# Insert into the state_groups, state_groups_state, and | ||
# event_to_state_groups tables. | ||
self._store_mult_state_groups_txn(txn, events_and_contexts) | ||
# Insert into event_to_state_groups tables. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/tables/table/. Or just s/tables// |
||
self._store_event_state_mappings_txn(txn, events_and_contexts) | ||
|
||
# _store_rejected_events_txn filters out any events which were | ||
# rejected, and returns the filtered list. | ||
|
@@ -979,10 +978,9 @@ def _update_outliers_txn(self, txn, events_and_contexts): | |
# an outlier in the database. We now have some state at that | ||
# so we need to update the state_groups table with that state. | ||
|
||
# insert into the state_group, state_groups_state and | ||
# event_to_state_groups tables. | ||
# insert into event_to_state_groups tables. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
try: | ||
self._store_mult_state_groups_txn(txn, ((event, context),)) | ||
self._store_event_state_mappings_txn(txn, ((event, context),)) | ||
except Exception: | ||
logger.exception("") | ||
raise | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright 2018 New Vector Ltd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from synapse.storage.engines import PostgresEngine | ||
|
||
|
||
def run_create(cur, database_engine, *args, **kwargs): | ||
if isinstance(database_engine, PostgresEngine): | ||
cur.execute("CREATE SEQUENCE state_group_id_seq") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you not need to initialise this? (see ab8567a which I did when playing with this) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooh, yes. I've cherry-picked that. |
||
|
||
|
||
def run_upgrade(*args, **kwargs): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as per
#synapse-dev
: we don't currently store a state group here, and it's not obvious to me that the state group we will store will be meaningful.