This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add support for MSC2716 marker events (federation) #10498
Merged
Merged
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
d2e2aa7
Make historical messages available to federated servers
MadLittleMods 2d942ec
Debug message not available on federation
MadLittleMods 38bcf13
Add base starting insertion point when no chunk ID is provided
MadLittleMods e405a23
Fix messages from multiple senders in historical chunk
MadLittleMods 36f1565
Remove debug lines
MadLittleMods 05d6c51
Messing with selecting insertion event extremeties
MadLittleMods defc536
Merge branch 'develop' into madlittlemods/2716-backfill-historical-ev…
MadLittleMods dfad8a8
Move db schema change to new version
MadLittleMods 7d850db
Add more better comments
MadLittleMods 164dee4
Make a fake requester with just what we need
MadLittleMods 04b1f7e
Store insertion events in table
MadLittleMods b703962
Make base insertion event float off on its own
MadLittleMods 8c205e5
Validate that the app service can actually control the given user
MadLittleMods 7b8b2d1
Add some better comments on what we're trying to check for
MadLittleMods 281588f
Merge branch 'develop' into madlittlemods/2716-backfill-historical-ev…
MadLittleMods 4226165
Continue debugging
MadLittleMods baae5d8
Share validation logic
MadLittleMods c05e43b
Add inserted historical messages to /backfill response
MadLittleMods 02b1bea
Remove debug sql queries
MadLittleMods 66cf5be
Merge branch 'develop' into madlittlemods/2716-backfill-historical-ev…
MadLittleMods ab8011b
Some marker event implemntation trials
MadLittleMods f20ba02
Clean up PR
MadLittleMods 64aeb73
Rename insertion_event_id to just event_id
MadLittleMods ea7c30d
Add some better sql comments
MadLittleMods 9a6fd3f
More accurate description
MadLittleMods 0f6179f
Add changelog
MadLittleMods 5970e3f
Make it clear what MSC the change is part of
MadLittleMods bc13396
Add more detail on which insertion event came through
MadLittleMods 669da52
Address review and improve sql queries
MadLittleMods 9a86e05
Only use event_id as unique constraint
MadLittleMods 8999567
Fix test case where insertion event is already in the normal DAG
MadLittleMods 35a4569
Remove debug changes
MadLittleMods 164e32b
Add support for MSC2716 marker events
MadLittleMods 435f074
Process markers when we receive it over federation
MadLittleMods e0e1bd0
WIP: make hs2 backfill historical messages after marker event
MadLittleMods d63c34c
hs2 to better ask for insertion event extremity
MadLittleMods 2196ba5
Add insertion_event_extremities table
MadLittleMods b2be8ce
Switch to chunk events so we can auth via power_levels
MadLittleMods 04a29fe
Switch to chunk events for federation
MadLittleMods 258fa57
Add unstable room version to support new historical PL
MadLittleMods 8ebbc5f
Merge branch 'madlittlemods/2716-backfill-historical-events-for-feder…
MadLittleMods 187ab28
Messy: Fix undefined state_group for federated historical events
MadLittleMods 9d70e95
Revert "Messy: Fix undefined state_group for federated historical eve…
MadLittleMods 9352635
Fix federated events being rejected for no state_groups
MadLittleMods 5c454b7
Merge branch 'develop' into madlittlemods/2716-backfill-historical-ev…
MadLittleMods e881cff
Merge branch 'develop' into madlittlemods/2716-backfill-historical-ev…
MadLittleMods c9330ec
Merge branch 'develop' into madlittlemods/2716-backfill-historical-ev…
MadLittleMods 347a3e1
Merge branch 'madlittlemods/2716-backfill-historical-events-for-feder…
MadLittleMods 97fb158
Merge branch 'develop' into madlittlemods/2716-marker-events
MadLittleMods f115aec
Adapting to experimental room version
MadLittleMods b55315f
Some log cleanup
MadLittleMods 088c3ef
Add better comments around extremity fetching code and why
MadLittleMods 8072170
Rename to be more accurate to what the function returns
MadLittleMods 44b883c
Add changelog
MadLittleMods 5268749
Ignore rejected events
MadLittleMods 71c2f05
Use simplified upsert
MadLittleMods b832264
Add Erik's explanation of extra event checks
MadLittleMods 1dc0996
Clarify that the depth is not directly correlated to the backwards ex…
MadLittleMods 32af944
lock only matters for sqlite
MadLittleMods 1b7e627
Move new SQL changes to its own delta file
MadLittleMods e6e48ed
Clean up upsert docstring
MadLittleMods 23bc5e5
Bump database schema version (62)
MadLittleMods 92dd985
Merge branch 'develop' into madlittlemods/2716-marker-events-v2
MadLittleMods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add support for "marker" events which makes historical events discoverable for servers that already have all of the scrollback history (part of MSC2716). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -671,27 +671,97 @@ def _get_auth_chain_difference_txn( | |
# Return all events where not all sets can reach them. | ||
return {eid for eid, n in event_to_missing_sets.items() if n} | ||
|
||
async def get_oldest_events_with_depth_in_room(self, room_id): | ||
async def get_oldest_event_ids_with_depth_in_room(self, room_id) -> Dict[str, int]: | ||
"""Gets the oldest events(backwards extremities) in the room along with the | ||
aproximate depth. | ||
|
||
We use this function so that we can compare and see if someones current | ||
depth at their current scrollback is within pagination range of the | ||
event extremeties. If the current depth is close to the depth of given | ||
oldest event, we can trigger a backfill. | ||
|
||
Args: | ||
room_id: Room where we want to find the oldest events | ||
|
||
Returns: | ||
Map from event_id to depth | ||
""" | ||
|
||
def get_oldest_event_ids_with_depth_in_room_txn(txn, room_id): | ||
# Assemble a dictionary with event_id -> depth for the oldest events | ||
# we know of in the room. Backwards extremeties are the oldest | ||
# events we know of in the room but we only know of them because | ||
# some other event referenced them by prev_event and aren't peristed | ||
# in our database yet (meaning we don't know their depth | ||
# specifically). So we need to look for the aproximate depth from | ||
# the events connected to the current backwards extremeties. | ||
sql = """ | ||
SELECT b.event_id, MAX(e.depth) FROM events as e | ||
/** | ||
* Get the edge connections from the event_edges table | ||
* so we can see whether this event's prev_events points | ||
* to a backward extremity in the next join. | ||
*/ | ||
INNER JOIN event_edges as g | ||
ON g.event_id = e.event_id | ||
/** | ||
* We find the "oldest" events in the room by looking for | ||
* events connected to backwards extremeties (oldest events | ||
* in the room that we know of so far). | ||
*/ | ||
INNER JOIN event_backward_extremities as b | ||
ON g.prev_event_id = b.event_id | ||
WHERE b.room_id = ? AND g.is_state is ? | ||
GROUP BY b.event_id | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No change to the query, just new |
||
|
||
txn.execute(sql, (room_id, False)) | ||
|
||
return dict(txn) | ||
|
||
return await self.db_pool.runInteraction( | ||
"get_oldest_events_with_depth_in_room", | ||
self.get_oldest_events_with_depth_in_room_txn, | ||
"get_oldest_event_ids_with_depth_in_room", | ||
get_oldest_event_ids_with_depth_in_room_txn, | ||
room_id, | ||
) | ||
|
||
def get_oldest_events_with_depth_in_room_txn(self, txn, room_id): | ||
sql = ( | ||
"SELECT b.event_id, MAX(e.depth) FROM events as e" | ||
" INNER JOIN event_edges as g" | ||
" ON g.event_id = e.event_id" | ||
" INNER JOIN event_backward_extremities as b" | ||
" ON g.prev_event_id = b.event_id" | ||
" WHERE b.room_id = ? AND g.is_state is ?" | ||
" GROUP BY b.event_id" | ||
) | ||
async def get_insertion_event_backwards_extremities_in_room( | ||
self, room_id | ||
) -> Dict[str, int]: | ||
"""Get the insertion events we know about that we haven't backfilled yet. | ||
|
||
txn.execute(sql, (room_id, False)) | ||
We use this function so that we can compare and see if someones current | ||
depth at their current scrollback is within pagination range of the | ||
insertion event. If the current depth is close to the depth of given | ||
insertion event, we can trigger a backfill. | ||
|
||
return dict(txn) | ||
Args: | ||
room_id: Room where we want to find the oldest events | ||
|
||
Returns: | ||
Map from event_id to depth | ||
""" | ||
|
||
def get_insertion_event_backwards_extremities_in_room_txn(txn, room_id): | ||
sql = """ | ||
SELECT b.event_id, MAX(e.depth) FROM insertion_events as i | ||
/* We only want insertion events that are also marked as backwards extremities */ | ||
INNER JOIN insertion_event_extremities as b USING (event_id) | ||
/* Get the depth of the insertion event from the events table */ | ||
INNER JOIN events AS e USING (event_id) | ||
WHERE b.room_id = ? | ||
GROUP BY b.event_id | ||
""" | ||
|
||
txn.execute(sql, (room_id,)) | ||
|
||
return dict(txn) | ||
|
||
return await self.db_pool.runInteraction( | ||
"get_insertion_event_backwards_extremities_in_room", | ||
get_insertion_event_backwards_extremities_in_room_txn, | ||
room_id, | ||
) | ||
|
||
async def get_max_depth_of(self, event_ids: List[str]) -> Tuple[str, int]: | ||
"""Returns the event ID and depth for the event that has the max depth from a set of event IDs | ||
|
@@ -1041,7 +1111,6 @@ def _get_backfill_events(self, txn, room_id, event_list, limit): | |
if row[1] not in event_results: | ||
queue.put((-row[0], row[1])) | ||
|
||
# Navigate up the DAG by prev_event | ||
txn.execute(query, (event_id, False, limit - len(event_results))) | ||
prev_event_id_results = txn.fetchall() | ||
logger.debug( | ||
|
@@ -1136,6 +1205,19 @@ def _delete_old_forward_extrem_cache_txn(txn): | |
_delete_old_forward_extrem_cache_txn, | ||
) | ||
|
||
async def insert_insertion_extremity(self, event_id: str, room_id: str) -> None: | ||
await self.db_pool.simple_upsert( | ||
table="insertion_event_extremities", | ||
keyvalues={"event_id": event_id}, | ||
values={ | ||
"event_id": event_id, | ||
"room_id": room_id, | ||
}, | ||
insertion_values={}, | ||
desc="insert_insertion_extremity", | ||
lock=False, | ||
) | ||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
async def insert_received_event_to_staging( | ||
self, origin: str, event: EventBase | ||
) -> None: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.