Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit ad4201c

Browse files
committed
Separate delta by table to avoid deadlocks.
1 parent 0be2974 commit ad4201c

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Copyright 2022 The Matrix.org Foundation C.I.C
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
-- The thread_id columns can now be made non-nullable, this is done by using a
17+
-- constraint (and not altering the column) to avoid taking out a full table lock.
18+
--
19+
-- We initially add an invalid constraint which guards against new data (this
20+
-- doesn't lock the table).
21+
ALTER TABLE event_push_actions
22+
ADD CONSTRAINT event_push_actions_thread_id CHECK (thread_id IS NOT NULL) NOT VALID;
23+
24+
-- We then validate the constraint which doesn't need to worry about new data. It
25+
-- only needs a SHARE UPDATE EXCLUSIVE lock but can still take a while to complete.
26+
INSERT INTO background_updates (ordering, update_name, progress_json) VALUES
27+
(7605, 'event_push_actions_thread_id', '{}');
28+
29+
-- Drop the indexes used to find null thread_ids.
30+
DROP INDEX IF EXISTS event_push_actions_thread_id_null;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Copyright 2022 The Matrix.org Foundation C.I.C
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
-- The thread_id columns can now be made non-nullable, this is done by using a
17+
-- constraint (and not altering the column) to avoid taking out a full table lock.
18+
--
19+
-- We initially add an invalid constraint which guards against new data (this
20+
-- doesn't lock the table).
21+
ALTER TABLE event_push_actions_staging
22+
ADD CONSTRAINT event_push_actions_staging_thread_id CHECK (thread_id IS NOT NULL) NOT VALID;
23+
24+
-- We then validate the constraint which doesn't need to worry about new data. It
25+
-- only needs a SHARE UPDATE EXCLUSIVE lock but can still take a while to complete.
26+
INSERT INTO background_updates (ordering, update_name, progress_json) VALUES
27+
(7605, 'event_push_actions_staging_thread_id', '{}');

synapse/storage/schema/main/delta/76/05thread_notifications_not_null.sql.postgres renamed to synapse/storage/schema/main/delta/76/05thread_notifications_not_null_event_push_summary.sql.postgres

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,13 @@
1818
--
1919
-- We initially add an invalid constraint which guards against new data (this
2020
-- doesn't lock the table).
21-
ALTER TABLE event_push_actions_staging
22-
ADD CONSTRAINT event_push_actions_staging_thread_id CHECK (thread_id IS NOT NULL) NOT VALID;
23-
ALTER TABLE event_push_actions
24-
ADD CONSTRAINT event_push_actions_thread_id CHECK (thread_id IS NOT NULL) NOT VALID;
2521
ALTER TABLE event_push_summary
2622
ADD CONSTRAINT event_push_summary_thread_id CHECK (thread_id IS NOT NULL) NOT VALID;
2723

2824
-- We then validate the constraint which doesn't need to worry about new data. It
2925
-- only needs a SHARE UPDATE EXCLUSIVE lock but can still take a while to complete.
3026
INSERT INTO background_updates (ordering, update_name, progress_json) VALUES
31-
(7605, 'event_push_actions_staging_thread_id', '{}'),
32-
(7605, 'event_push_actions_thread_id', '{}'),
3327
(7605, 'event_push_summary_thread_id', '{}');
3428

3529
-- Drop the indexes used to find null thread_ids.
36-
DROP INDEX IF EXISTS event_push_actions_thread_id_null;
3730
DROP INDEX IF EXISTS event_push_summary_thread_id_null;

0 commit comments

Comments
 (0)