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

Commit e3e73e1

Browse files
authored
Upsert redactions in case they already exists (#10343)
* 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 <andreas@rammhold.de> * Also purge redactions when purging events Previously redacints where left behind leading to backfilling issues when the server stumbled across the already existing yet to be backfilled redactions. This issues has been discussed in #8707. Signed-off-by: Andreas Rammhold <andreas@rammhold.de>
1 parent d26094e commit e3e73e1

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-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 errors during backfill caused by previously purged redaction events. 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
},

synapse/storage/databases/main/purge_events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def _purge_history_txn(
215215
"event_relations",
216216
"event_search",
217217
"rejections",
218+
"redactions",
218219
):
219220
logger.info("[purge] removing events from %s", table)
220221

0 commit comments

Comments
 (0)