From 89b4551e4808a0accf2cc40d49943f381cb77cd4 Mon Sep 17 00:00:00 2001 From: Nick Mills-Barrett Date: Sat, 4 Jun 2022 18:33:58 +0100 Subject: [PATCH 1/3] Use READ COMMITTED isolation level when inserting read receipts --- synapse/storage/databases/main/receipts.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/synapse/storage/databases/main/receipts.py b/synapse/storage/databases/main/receipts.py index 21e954ccc188..b2c44d0f782f 100644 --- a/synapse/storage/databases/main/receipts.py +++ b/synapse/storage/databases/main/receipts.py @@ -29,7 +29,7 @@ from synapse.api.constants import EduTypes, ReceiptTypes from synapse.replication.slave.storage._slaved_id_tracker import SlavedIdTracker from synapse.replication.tcp.streams import ReceiptsStream -from synapse.storage._base import SQLBaseStore, db_to_json, make_in_list_sql_clause +from synapse.storage._base import SQLBaseStore, IsolationLevel, db_to_json, make_in_list_sql_clause from synapse.storage.database import ( DatabasePool, LoggingDatabaseConnection, @@ -764,6 +764,10 @@ async def insert_receipt( linearized_event_id, data, stream_id=stream_id, + # Read committed is actually beneficial here because we check for a receipt with + # greater stream order, and checking the very latest data at select time is better + # than the data at transaction start time. + isolation_level=IsolationLevel.READ_COMMITTED, ) # If the receipt was older than the currently persisted one, nothing to do. From a7cc1b8c0daddfc9e5cf07130626ed7b8723c89c Mon Sep 17 00:00:00 2001 From: Nick Mills-Barrett Date: Sat, 4 Jun 2022 18:36:07 +0100 Subject: [PATCH 2/3] Add changelog file --- changelog.d/12957.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/12957.misc diff --git a/changelog.d/12957.misc b/changelog.d/12957.misc new file mode 100644 index 000000000000..0c075276ec8a --- /dev/null +++ b/changelog.d/12957.misc @@ -0,0 +1 @@ +Use lower isolation level when inserting read receipts to avoid serialization errors. Contributed by Nick @ Beeper. From b5976c1dcf10cdc7b6ccf6bb214738fb183932d5 Mon Sep 17 00:00:00 2001 From: Nick Mills-Barrett Date: Sat, 4 Jun 2022 18:42:36 +0100 Subject: [PATCH 3/3] Fix import --- synapse/storage/databases/main/receipts.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/synapse/storage/databases/main/receipts.py b/synapse/storage/databases/main/receipts.py index b2c44d0f782f..b6106affa644 100644 --- a/synapse/storage/databases/main/receipts.py +++ b/synapse/storage/databases/main/receipts.py @@ -29,13 +29,14 @@ from synapse.api.constants import EduTypes, ReceiptTypes from synapse.replication.slave.storage._slaved_id_tracker import SlavedIdTracker from synapse.replication.tcp.streams import ReceiptsStream -from synapse.storage._base import SQLBaseStore, IsolationLevel, db_to_json, make_in_list_sql_clause +from synapse.storage._base import SQLBaseStore, db_to_json, make_in_list_sql_clause from synapse.storage.database import ( DatabasePool, LoggingDatabaseConnection, LoggingTransaction, ) from synapse.storage.engines import PostgresEngine +from synapse.storage.engines._base import IsolationLevel from synapse.storage.util.id_generators import ( AbstractStreamIdTracker, MultiWriterIdGenerator,