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

Commit

Permalink
Include the room ID in more purge room log lines. (#15222)
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep authored Mar 8, 2023
1 parent f4fc83a commit 88efc75
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions changelog.d/15222.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve log lines when purging rooms.
2 changes: 1 addition & 1 deletion synapse/handlers/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ async def _shutdown_and_purge_room(

await self._storage_controllers.purge_events.purge_room(room_id)

logger.info("complete")
logger.info("purge complete for room_id %s", room_id)
self._delete_by_id[delete_id].status = DeleteStatus.STATUS_COMPLETE
except Exception:
f = Failure()
Expand Down
22 changes: 13 additions & 9 deletions synapse/storage/controllers/purge_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
from typing import TYPE_CHECKING, Set

from synapse.logging.context import nested_logging_context
from synapse.storage.databases import Databases

if TYPE_CHECKING:
Expand All @@ -33,8 +34,9 @@ def __init__(self, hs: "HomeServer", stores: Databases):
async def purge_room(self, room_id: str) -> None:
"""Deletes all record of a room"""

state_groups_to_delete = await self.stores.main.purge_room(room_id)
await self.stores.state.purge_room_state(room_id, state_groups_to_delete)
with nested_logging_context(room_id):
state_groups_to_delete = await self.stores.main.purge_room(room_id)
await self.stores.state.purge_room_state(room_id, state_groups_to_delete)

async def purge_history(
self, room_id: str, token: str, delete_local_events: bool
Expand All @@ -51,15 +53,17 @@ async def purge_history(
(instead of just marking them as outliers and deleting their
state groups).
"""
state_groups = await self.stores.main.purge_history(
room_id, token, delete_local_events
)

logger.info("[purge] finding state groups that can be deleted")
with nested_logging_context(room_id):
state_groups = await self.stores.main.purge_history(
room_id, token, delete_local_events
)

sg_to_delete = await self._find_unreferenced_groups(state_groups)
logger.info("[purge] finding state groups that can be deleted")
sg_to_delete = await self._find_unreferenced_groups(state_groups)

await self.stores.state.purge_unreferenced_state_groups(room_id, sg_to_delete)
await self.stores.state.purge_unreferenced_state_groups(
room_id, sg_to_delete
)

async def _find_unreferenced_groups(self, state_groups: Set[int]) -> Set[int]:
"""Used when purging history to figure out which state groups can be
Expand Down
11 changes: 6 additions & 5 deletions synapse/storage/databases/main/purge_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,23 @@ async def purge_room(self, room_id: str) -> List[int]:
# 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.

logger.info("[purge] Starting initial main purge of [1/2]")
state_groups_to_delete = await self.db_pool.runInteraction(
"purge_room",
self._purge_room_txn,
room_id=room_id,
isolation_level=IsolationLevel.READ_COMMITTED,
)

logger.info("[purge] Starting secondary main purge of [2/2]")
state_groups_to_delete.extend(
await self.db_pool.runInteraction(
"purge_room",
self._purge_room_txn,
room_id=room_id,
),
)
logger.info("[purge] Done with main purge")

return state_groups_to_delete

Expand Down Expand Up @@ -376,7 +379,7 @@ def _purge_room_txn(self, txn: LoggingTransaction, room_id: str) -> List[int]:
)
referenced_chain_id_tuples = list(txn)

logger.info("[purge] removing events from event_auth_chain_links")
logger.info("[purge] removing from event_auth_chain_links")
txn.executemany(
"""
DELETE FROM event_auth_chain_links WHERE
Expand All @@ -399,7 +402,7 @@ def _purge_room_txn(self, txn: LoggingTransaction, room_id: str) -> List[int]:
"rejections",
"state_events",
):
logger.info("[purge] removing %s from %s", room_id, table)
logger.info("[purge] removing from %s", table)

txn.execute(
"""
Expand Down Expand Up @@ -454,7 +457,7 @@ def _purge_room_txn(self, txn: LoggingTransaction, room_id: str) -> List[int]:
# happy
"rooms",
):
logger.info("[purge] removing %s from %s", room_id, table)
logger.info("[purge] removing from %s", table)
txn.execute("DELETE FROM %s WHERE room_id=?" % (table,), (room_id,))

# Other tables we do NOT need to clear out:
Expand Down Expand Up @@ -486,6 +489,4 @@ def _purge_room_txn(self, txn: LoggingTransaction, room_id: str) -> List[int]:
# that already exist.
self._invalidate_cache_and_stream(txn, self.have_seen_event, (room_id,))

logger.info("[purge] done")

return state_groups
2 changes: 2 additions & 0 deletions synapse/storage/databases/state/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +805,14 @@ async def purge_room_state(
state_groups_to_delete: State groups to delete
"""

logger.info("[purge] Starting state purge")
await self.db_pool.runInteraction(
"purge_room_state",
self._purge_room_state_txn,
room_id,
state_groups_to_delete,
)
logger.info("[purge] Done with state purge")

def _purge_room_state_txn(
self,
Expand Down

0 comments on commit 88efc75

Please sign in to comment.