This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track unconverted device list outbound pokes using a position instead (…
…#14516) When a local device list change is added to `device_lists_changes_in_room`, the `converted_to_destinations` flag is set to `FALSE` and the `_handle_new_device_update_async` background process is started. This background process looks for unconverted rows in `device_lists_changes_in_room`, copies them to `device_lists_outbound_pokes` and updates the flag. To update the `converted_to_destinations` flag, the database performs a `DELETE` and `INSERT` internally, which fragments the table. To avoid this, track unconverted rows using a `(stream ID, room ID)` position instead of the flag. From now on, the `converted_to_destinations` column indicates rows that need converting to outbound pokes, but does not indicate whether the conversion has already taken place. Closes #14037. Signed-off-by: Sean Quah <seanq@matrix.org>
- Loading branch information
Showing
6 changed files
with
158 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Refactor conversion of device list changes in room to outbound pokes to track unconverted rows using a `(stream ID, room ID)` position instead of updating the `converted_to_destinations` flag on every row. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
synapse/storage/schema/main/delta/73/12refactor_device_list_outbound_pokes.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* 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. | ||
*/ | ||
|
||
-- Prior to this schema delta, we tracked the set of unconverted rows in | ||
-- `device_lists_changes_in_room` using the `converted_to_destinations` flag. When rows | ||
-- were converted to `device_lists_outbound_pokes`, the `converted_to_destinations` flag | ||
-- would be set. | ||
-- | ||
-- After this schema delta, the `converted_to_destinations` is still populated like | ||
-- before, but the set of unconverted rows is determined by the `stream_id` in the new | ||
-- `device_lists_changes_converted_stream_position` table. | ||
-- | ||
-- If rolled back, Synapse will re-send all device list changes that happened since the | ||
-- schema delta. | ||
|
||
CREATE TABLE IF NOT EXISTS device_lists_changes_converted_stream_position( | ||
Lock CHAR(1) NOT NULL DEFAULT 'X' UNIQUE, -- Makes sure this table only has one row. | ||
-- The (stream id, room id) of the last row in `device_lists_changes_in_room` that | ||
-- has been converted to `device_lists_outbound_pokes`. Rows with a strictly larger | ||
-- (stream id, room id) where `converted_to_destinations` is `FALSE` have not been | ||
-- converted. | ||
stream_id BIGINT NOT NULL, | ||
-- `room_id` may be an empty string, which compares less than all valid room IDs. | ||
room_id TEXT NOT NULL, | ||
CHECK (Lock='X') | ||
); | ||
|
||
INSERT INTO device_lists_changes_converted_stream_position (stream_id, room_id) VALUES ( | ||
( | ||
SELECT COALESCE( | ||
-- The last converted stream id is the smallest unconverted stream id minus | ||
-- one. | ||
MIN(stream_id) - 1, | ||
-- If there is no unconverted stream id, the last converted stream id is the | ||
-- largest stream id. | ||
-- Otherwise, pick 1, since stream ids start at 2. | ||
(SELECT COALESCE(MAX(stream_id), 1) FROM device_lists_changes_in_room) | ||
) FROM device_lists_changes_in_room WHERE NOT converted_to_destinations | ||
), | ||
'' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters