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

Commit db2d5da

Browse files
committed
Upsert redactions in case they already exists
Occasionally, in combination with retention, redactions aren't deleted from the database whenever they are due for deletion. The server will eventually try to backfill the deleted events and trip over the already existing redaction events. Switching to an UPSERT for those events allows us to recover from there situations. The retention code still needs fixing but that is outside of my current comfort zone on this code base. This is related to #8707 where the error was discussed already. Signed-off-by: Andreas Rammhold <[email protected]>
1 parent 33ae301 commit db2d5da

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

changelog.d/10343.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix duplicate key error during backfilling of redaction events that were not deleted by the history purge job. Contributed by Andreas Rammhold (@andir).

synapse/storage/databases/main/events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,11 +1580,11 @@ def _store_redaction(self, txn, event):
15801580
# invalidate the cache for the redacted event
15811581
txn.call_after(self.store._invalidate_get_event_cache, event.redacts)
15821582

1583-
self.db_pool.simple_insert_txn(
1583+
self.db_pool.simple_upsert_txn(
15841584
txn,
15851585
table="redactions",
1586+
keyvalues={"event_id": event.event_id},
15861587
values={
1587-
"event_id": event.event_id,
15881588
"redacts": event.redacts,
15891589
"received_ts": self._clock.time_msec(),
15901590
},

0 commit comments

Comments
 (0)