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

Commit 1ca427a

Browse files
committed
Update the rejected state of events during resync
Events can be un-rejected or newly-rejected during resync, so ensure we update the database and caches when that happens.
1 parent 505be78 commit 1ca427a

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

changelog.d/13459.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Faster joins: update the rejected state of events during de-partial-stating.

synapse/storage/databases/main/events_worker.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,3 +2139,58 @@ def _get_partial_state_events_batch_txn(
21392139
(room_id,),
21402140
)
21412141
return [row[0] for row in txn]
2142+
2143+
def mark_event_rejected_txn(
2144+
self,
2145+
txn: LoggingTransaction,
2146+
event_id: str,
2147+
rejection_reason: Optional[str],
2148+
) -> None:
2149+
"""Mark an event that was previously accepted as rejected, or vice versa
2150+
2151+
This can happen, for example, when resyncing state during a faster join.
2152+
2153+
Args:
2154+
txn:
2155+
event_id: ID of event to update
2156+
rejection_reason: reason it has been rejected, or None if it is now accepted
2157+
"""
2158+
if rejection_reason is None:
2159+
logger.info(
2160+
"Marking previously-processed event %s as accepted",
2161+
event_id,
2162+
)
2163+
self.db_pool.simple_delete_txn(
2164+
txn,
2165+
"rejections",
2166+
keyvalues={"event_id": event_id},
2167+
)
2168+
else:
2169+
logger.info(
2170+
"Marking previously-processed event %s as rejected(%s)",
2171+
event_id,
2172+
rejection_reason,
2173+
)
2174+
self.db_pool.simple_upsert_txn(
2175+
txn,
2176+
table="rejections",
2177+
keyvalues={"event_id": event_id},
2178+
values={
2179+
"reason": rejection_reason,
2180+
"last_check": self._clock.time_msec(),
2181+
},
2182+
)
2183+
self.db_pool.simple_update_txn(
2184+
txn,
2185+
table="events",
2186+
keyvalues={"event_id": event_id},
2187+
updatevalues={"rejection_reason": rejection_reason},
2188+
)
2189+
2190+
self.invalidate_get_event_cache_after_txn(txn, event_id)
2191+
2192+
# TODO(faster_joins): invalidate the cache on workers. Ideally we'd just
2193+
# call '_send_invalidation_to_replication', but we actually need the other
2194+
# end to call _invalidate_local_event_cache() rather than (just)
2195+
# _get_event_cache.invalidate().
2196+
# https://github.com/matrix-org/synapse/issues/12994

synapse/storage/databases/main/state.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ def _update_state_for_partial_state_event_txn(
430430
updatevalues={"state_group": state_group},
431431
)
432432

433+
# the event may now be rejected where it was not before, or vice versa,
434+
# in which case we need to update the rejected flags.
435+
if bool(context.rejected) != (event.rejected_reason is not None):
436+
self.mark_event_rejected_txn(txn, event.event_id, context.rejected)
437+
433438
self.db_pool.simple_delete_one_txn(
434439
txn,
435440
table="partial_state_events",

0 commit comments

Comments
 (0)