add some logging to purge_history

This commit is contained in:
Richard van der Hoff 2017-05-10 17:46:41 +01:00
parent a3648f84b2
commit b64d312421

View file

@ -2033,6 +2033,8 @@ class EventsStore(SQLBaseStore):
for event_id, state_key in event_rows: for event_id, state_key in event_rows:
txn.call_after(self._get_state_group_for_event.invalidate, (event_id,)) txn.call_after(self._get_state_group_for_event.invalidate, (event_id,))
logger.debug("[purge] Finding new backward extremities")
# We calculate the new entries for the backward extremeties by finding # We calculate the new entries for the backward extremeties by finding
# all events that point to events that are to be purged # all events that point to events that are to be purged
txn.execute( txn.execute(
@ -2045,6 +2047,8 @@ class EventsStore(SQLBaseStore):
) )
new_backwards_extrems = txn.fetchall() new_backwards_extrems = txn.fetchall()
logger.debug("[purge] replacing backward extremities: %r", new_backwards_extrems)
txn.execute( txn.execute(
"DELETE FROM event_backward_extremities WHERE room_id = ?", "DELETE FROM event_backward_extremities WHERE room_id = ?",
(room_id,) (room_id,)
@ -2059,6 +2063,8 @@ class EventsStore(SQLBaseStore):
] ]
) )
logger.debug("[purge] finding redundant state groups")
# Get all state groups that are only referenced by events that are # Get all state groups that are only referenced by events that are
# to be deleted. # to be deleted.
txn.execute( txn.execute(
@ -2076,6 +2082,10 @@ class EventsStore(SQLBaseStore):
state_rows = txn.fetchall() state_rows = txn.fetchall()
state_groups_to_delete = [sg for sg, in state_rows] state_groups_to_delete = [sg for sg, in state_rows]
logger.debug(
"[purge] finding state groups which depend on redundant state groups"
)
# Now we get all the state groups that rely on these state groups # Now we get all the state groups that rely on these state groups
new_state_edges = [] new_state_edges = []
chunks = [ chunks = [
@ -2096,6 +2106,8 @@ class EventsStore(SQLBaseStore):
# Now we turn the state groups that reference to-be-deleted state groups # Now we turn the state groups that reference to-be-deleted state groups
# to non delta versions. # to non delta versions.
for new_state_edge in new_state_edges: for new_state_edge in new_state_edges:
logger.debug("[purge] de-delta-ing remaining state group %s",
new_state_edge)
curr_state = self._get_state_groups_from_groups_txn( curr_state = self._get_state_groups_from_groups_txn(
txn, [new_state_edge], types=None txn, [new_state_edge], types=None
) )
@ -2132,6 +2144,7 @@ class EventsStore(SQLBaseStore):
], ],
) )
logger.debug("[purge] removing redundant state groups")
txn.executemany( txn.executemany(
"DELETE FROM state_groups_state WHERE state_group = ?", "DELETE FROM state_groups_state WHERE state_group = ?",
state_rows state_rows
@ -2140,12 +2153,15 @@ class EventsStore(SQLBaseStore):
"DELETE FROM state_groups WHERE id = ?", "DELETE FROM state_groups WHERE id = ?",
state_rows state_rows
) )
# Delete all non-state # Delete all non-state
logger.debug("[purge] removing events from event_to_state_groups")
txn.executemany( txn.executemany(
"DELETE FROM event_to_state_groups WHERE event_id = ?", "DELETE FROM event_to_state_groups WHERE event_id = ?",
[(event_id,) for event_id, _ in event_rows] [(event_id,) for event_id, _ in event_rows]
) )
logger.debug("[purge] updating room_depth")
txn.execute( txn.execute(
"UPDATE room_depth SET min_depth = ? WHERE room_id = ?", "UPDATE room_depth SET min_depth = ? WHERE room_id = ?",
(topological_ordering, room_id,) (topological_ordering, room_id,)
@ -2171,16 +2187,15 @@ class EventsStore(SQLBaseStore):
"event_signatures", "event_signatures",
"rejections", "rejections",
): ):
logger.debug("[purge] removing non-state events from %s", table)
txn.executemany( txn.executemany(
"DELETE FROM %s WHERE event_id = ?" % (table,), "DELETE FROM %s WHERE event_id = ?" % (table,),
to_delete to_delete
) )
txn.executemany(
"DELETE FROM events WHERE event_id = ?",
to_delete
)
# Mark all state and own events as outliers # Mark all state and own events as outliers
logger.debug("[purge] marking events as outliers")
txn.executemany( txn.executemany(
"UPDATE events SET outlier = ?" "UPDATE events SET outlier = ?"
" WHERE event_id = ?", " WHERE event_id = ?",
@ -2190,6 +2205,8 @@ class EventsStore(SQLBaseStore):
] ]
) )
logger.debug("[purge] done")
@defer.inlineCallbacks @defer.inlineCallbacks
def is_event_after(self, event_id1, event_id2): def is_event_after(self, event_id1, event_id2):
"""Returns True if event_id1 is after event_id2 in the stream """Returns True if event_id1 is after event_id2 in the stream