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

Commit

Permalink
Upsert redactions in case they already exists
Browse files Browse the repository at this point in the history
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 <andreas@rammhold.de>
  • Loading branch information
andir committed Jul 8, 2021
1 parent 33ae301 commit db2d5da
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/10343.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix duplicate key error during backfilling of redaction events that were not deleted by the history purge job. Contributed by Andreas Rammhold (@andir).
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,11 +1580,11 @@ def _store_redaction(self, txn, event):
# invalidate the cache for the redacted event
txn.call_after(self.store._invalidate_get_event_cache, event.redacts)

self.db_pool.simple_insert_txn(
self.db_pool.simple_upsert_txn(
txn,
table="redactions",
keyvalues={"event_id": event.event_id},
values={
"event_id": event.event_id,
"redacts": event.redacts,
"received_ts": self._clock.time_msec(),
},
Expand Down

0 comments on commit db2d5da

Please sign in to comment.