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

Commit

Permalink
Wait a few events when pruning extremities from the same server
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Dec 14, 2020
1 parent 9ce4277 commit 62c30e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions synapse/storage/persist_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,17 +815,18 @@ async def _prune_extremities(
# 1. we're not currently persisting them;
# 2. they're not our own events (or are dummy events); and
# 3. they're either:
# 1. over N hours old and more than N events ago (we use depth
# to calculate); or
# 2. we are persisting an event from the same domain.
# 1. over N hours old and more than N events ago (we use depth to
# calculate); or
# 2. we are persisting an event from the same domain and more than
# M events ago.
#
# The idea is that we don't want to drop events that are "legitimate"
# extremities (that we would want to include as prev events), only
# "stuck" extremities that are e.g. due to a gap in the graph.
#
# Note that we either drop all of them or none of them. If we only
# drop some of the events we don't know if state res would come to
# the same conclusion.
# Note that we either drop all of them or none of them. If we only drop
# some of the events we don't know if state res would come to the same
# conclusion.

for ev, _ in events_context:
if ev.event_id in dropped_extrems:
Expand Down Expand Up @@ -854,7 +855,14 @@ async def _prune_extremities(
and event.depth < current_depth - 100
):
continue
if get_domain_from_id(event.sender) in new_senders:

# We can be less conservative about dropping extremities from the
# same domain, though we do want to wait a little bit (otherwise
# we'll immediately remove all extremities from a given server).
if (
get_domain_from_id(event.sender) in new_senders
and event.depth < current_depth - 20
):
continue

logger.debug(
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_prune_gap(self):
"content": {"membership": Membership.JOIN},
"room_id": self.room_id,
"sender": "@user:other",
"depth": 10,
"depth": 50,
"prev_events": ["$some_unknown_message"],
"auth_events": [],
"origin_server_ts": self.clock.time_msec(),
Expand Down

0 comments on commit 62c30e8

Please sign in to comment.