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

Commit 52a947d

Browse files
authored
Updates to the Room DAG concepts development document (#12179)
Some stuff that came up while we were talking about #12173.
1 parent 88cd6f9 commit 52a947d

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

changelog.d/12179.doc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updates to the Room DAG concepts development document.

docs/development/room-dag-concepts.md

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,72 @@ rather than skipping any that arrived late; whereas if you're looking at a
3030
historical section of timeline (i.e. `/messages`), you want to see the best
3131
representation of the state of the room as others were seeing it at the time.
3232

33+
## Outliers
3334

34-
## Forward extremity
35+
We mark an event as an `outlier` when we haven't figured out the state for the
36+
room at that point in the DAG yet. They are "floating" events that we haven't
37+
yet correlated to the DAG.
3538

36-
Most-recent-in-time events in the DAG which are not referenced by any other events' `prev_events` yet.
39+
Outliers typically arise when we fetch the auth chain or state for a given
40+
event. When that happens, we just grab the events in the state/auth chain,
41+
without calculating the state at those events, or backfilling their
42+
`prev_events`.
3743

38-
The forward extremities of a room are used as the `prev_events` when the next event is sent.
44+
So, typically, we won't have the `prev_events` of an `outlier` in the database,
45+
(though it's entirely possible that we *might* have them for some other
46+
reason). Other things that make outliers different from regular events:
3947

48+
* We don't have state for them, so there should be no entry in
49+
`event_to_state_groups` for an outlier. (In practice this isn't always
50+
the case, though I'm not sure why: see https://github.com/matrix-org/synapse/issues/12201).
4051

41-
## Backward extremity
52+
* We don't record entries for them in the `event_edges`,
53+
`event_forward_extremeties` or `event_backward_extremities` tables.
4254

43-
The current marker of where we have backfilled up to and will generally be the
44-
`prev_events` of the oldest-in-time events we have in the DAG. This gives a starting point when
45-
backfilling history.
55+
Since outliers are not tied into the DAG, they do not normally form part of the
56+
timeline sent down to clients via `/sync` or `/messages`; however there is an
57+
exception:
4658

47-
When we persist a non-outlier event, we clear it as a backward extremity and set
48-
all of its `prev_events` as the new backward extremities if they aren't already
49-
persisted in the `events` table.
59+
### Out-of-band membership events
5060

61+
A special case of outlier events are some membership events for federated rooms
62+
that we aren't full members of. For example:
5163

52-
## Outliers
64+
* invites received over federation, before we join the room
65+
* *rejections* for said invites
66+
* knock events for rooms that we would like to join but have not yet joined.
5367

54-
We mark an event as an `outlier` when we haven't figured out the state for the
55-
room at that point in the DAG yet.
68+
In all the above cases, we don't have the state for the room, which is why they
69+
are treated as outliers. They are a bit special though, in that they are
70+
proactively sent to clients via `/sync`.
5671

57-
We won't *necessarily* have the `prev_events` of an `outlier` in the database,
58-
but it's entirely possible that we *might*.
72+
## Forward extremity
73+
74+
Most-recent-in-time events in the DAG which are not referenced by any other
75+
events' `prev_events` yet. (In this definition, outliers, rejected events, and
76+
soft-failed events don't count.)
77+
78+
The forward extremities of a room (or at least, a subset of them, if there are
79+
more than ten) are used as the `prev_events` when the next event is sent.
80+
81+
The "current state" of a room (ie: the state which would be used if we
82+
generated a new event) is, therefore, the resolution of the room states
83+
at each of the forward extremities.
84+
85+
## Backward extremity
86+
87+
The current marker of where we have backfilled up to and will generally be the
88+
`prev_events` of the oldest-in-time events we have in the DAG. This gives a starting point when
89+
backfilling history.
5990

60-
For example, when we fetch the event auth chain or state for a given event, we
61-
mark all of those claimed auth events as outliers because we haven't done the
62-
state calculation ourself.
91+
Note that, unlike forward extremities, we typically don't have any backward
92+
extremity events themselves in the database - or, if we do, they will be "outliers" (see
93+
above). Either way, we don't expect to have the room state at a backward extremity.
6394

95+
When we persist a non-outlier event, if it was previously a backward extremity,
96+
we clear it as a backward extremity and set all of its `prev_events` as the new
97+
backward extremities if they aren't already persisted as non-outliers. This
98+
therefore keeps the backward extremities up-to-date.
6499

65100
## State groups
66101

0 commit comments

Comments
 (0)