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

Commit

Permalink
Simplify purge room by just re-running the same txn
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar committed Jul 16, 2022
1 parent cedbe2a commit c83db92
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions synapse/storage/databases/main/purge_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,26 +319,22 @@ async def purge_room(self, room_id: str) -> List[int]:
Returns:
The list of state groups to delete.
"""

# This first runs the purge transaction with READ_COMMITTED isolation level,
# meaning any new rows in the tables will not trigger a serialization error.
# We then run the same purge a second time without this isolation level to
# purge any of those rows which were added during the first.

state_groups_to_delete = await self.db_pool.runInteraction(
"purge_room",
self._purge_room_txn,
room_id=room_id,
# This is safe because we don't care if room data is updated during the transaction, note
# we run a second transaction to cleanup tables we may write to during this transaction.
isolation_level=IsolationLevel.READ_COMMITTED,
)

def _purge_room_second_pass_txn(txn: LoggingTransaction, room_id: str) -> None:
for table in (
"event_push_actions",
"stream_ordering_to_exterm",
):
logger.info("[purge] removing %s from %s", room_id, table)
txn.execute("DELETE FROM %s WHERE room_id=?" % (table,), (room_id,))

await self.db_pool.runInteraction(
"purge_room_second_pass",
_purge_room_second_pass_txn,
"purge_room",
self._purge_room_txn,
room_id=room_id,
)

Expand Down

0 comments on commit c83db92

Please sign in to comment.