-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Faster joins: persist to database #12012
Changes from 4 commits
e1d95e8
36f8a6a
9f34681
57ff630
ad0078f
f499f40
446fae6
e3c84ff
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Preparation for faster-room-join work: persist information on which events and roos have partial state to the database. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2152,6 +2152,23 @@ def _store_event_state_mappings_txn( | |
|
||
state_groups[event.event_id] = context.state_group | ||
|
||
# if we have partial state for these events, record the fact. (This happens | ||
# here rather than in _store_event_txn because it also needs to happen when | ||
# we de-outlier an event.) | ||
Comment on lines
+2163
to
+2165
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. I'm unclear on why we need to do this again when de-outliering. Does de-outliering not imply that the event has already been through this code once? 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. seems to be another great question. I'll try and remember what's going on here. 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. Right, I've remembered what this is about. Outliers have no state at all, so it's meaningless to say that they have "partial state". So, the first time they go through this code, we would not expect to set the partial-state flag. When we de-outlier the event, it's possible that we might de-outlier it with only partial state, and in that case we need to add a row to I've added a robustness check to make sure it's true that outliers are never flagged with partial-state in 446fae6. I've also got it on my todo list to make sure we end up with tests which include de-outliering events with partial state. 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. Thanks for the explanation! So the outliers we persist will never be flagged with partial state because we always use * with the exception of the outlier 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.
Yeah, that looks a bit bogus. It means we end up recording state at the leave event, but also flagging it as an outlier, which seems wrong. Either it shouldn't be an outlier, or we shouldn't record the state at it. I'm going to park this for now though. 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. |
||
self.db_pool.simple_insert_many_txn( | ||
txn, | ||
table="partial_state_events", | ||
keys=("room_id", "event_id"), | ||
values=[ | ||
( | ||
event.room_id, | ||
event.event_id, | ||
) | ||
for event, ctx in events_and_contexts | ||
if ctx.partial_state | ||
], | ||
) | ||
|
||
self.db_pool.simple_upsert_many_txn( | ||
txn, | ||
table="event_to_state_groups", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Copyright 2022 The Matrix.org Foundation C.I.C | ||
* | ||
* 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. | ||
*/ | ||
|
||
-- rooms which we have done a partial-state-style join to | ||
CREATE TABLE IF NOT EXISTS partial_state_rooms ( | ||
room_id TEXT PRIMARY KEY, | ||
FOREIGN KEY(room_id) REFERENCES rooms(room_id) | ||
); | ||
|
||
-- a list of remote servers we believe are in the room | ||
CREATE TABLE IF NOT EXISTS partial_state_rooms_servers ( | ||
room_id TEXT NOT NULL REFERENCES partial_state_rooms(room_id), | ||
server_name TEXT NOT NULL, | ||
UNIQUE(room_id, server_name) | ||
); | ||
|
||
-- a list of events with partial state. We can't store this in the `events` table | ||
-- itself, because `events` is meant to be append-only. | ||
CREATE TABLE IF NOT EXISTS partial_state_events ( | ||
-- the room_id is denormalised for efficient indexing (the canonical source is `events`) | ||
room_id TEXT NOT NULL REFERENCES partial_state_rooms(room_id), | ||
event_id TEXT NOT NULL REFERENCES events(event_id), | ||
UNIQUE(event_id) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS partial_state_events_room_id_idx | ||
ON partial_state_events (room_id); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.