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
Make historical events discoverable from backfill for servers without any scrollback history (MSC2716) (federation) #10245
Merged
MadLittleMods
merged 47 commits into
develop
from
madlittlemods/2716-backfill-historical-events-for-federation
Jul 28, 2021
Merged
Changes from all commits
Commits
Show all changes
47 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 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 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 a8c5311
Only connect base insertion event to prev_event_ids
MadLittleMods ae606c7
Make it possible to get the room_version with txn
MadLittleMods bc896cc
Allow but ignore historical events in unsupported room version
MadLittleMods f231066
Move to unique index syntax
MadLittleMods 465b3d8
High-level document how the insertion->chunk lookup works
MadLittleMods 44bb3f0
Remove create_event fallback for room_versions
MadLittleMods 4d936b5
Merge branch 'develop' into madlittlemods/2716-backfill-historical-ev…
MadLittleMods 706770c
Use updated method name
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 @@ | ||
Make historical events discoverable from backfill for servers without any 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,9 +198,6 @@ class EventContentFields: | |
MSC2716_CHUNK_ID = "org.matrix.msc2716.chunk_id" | ||
# For "marker" events | ||
MSC2716_MARKER_INSERTION = "org.matrix.msc2716.marker.insertion" | ||
MSC2716_MARKER_INSERTION_PREV_EVENTS = ( | ||
"org.matrix.msc2716.marker.insertion_prev_events" | ||
) | ||
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. I don't think we will use this 🤷 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. Switched to backfilling the insertion event in #10420 |
||
|
||
|
||
class RoomTypes: | ||
|
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 |
---|---|---|
|
@@ -2748,9 +2748,11 @@ async def _update_auth_events_and_context_for_auth( | |
event.event_id, | ||
e.event_id, | ||
) | ||
context = await self.state_handler.compute_event_context(e) | ||
missing_auth_event_context = ( | ||
await self.state_handler.compute_event_context(e) | ||
) | ||
await self._auth_and_persist_event( | ||
origin, e, context, auth_events=auth | ||
origin, e, missing_auth_event_context, auth_events=auth | ||
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. This will merged separately in #10439 but need the fix here as well |
||
) | ||
|
||
if e.event_id in event_auth_events: | ||
|
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 |
---|---|---|
|
@@ -936,15 +936,46 @@ def _get_backfill_events(self, txn, room_id, event_list, limit): | |
# We want to make sure that we do a breadth-first, "depth" ordered | ||
# search. | ||
|
||
query = ( | ||
"SELECT depth, prev_event_id FROM event_edges" | ||
" INNER JOIN events" | ||
" ON prev_event_id = events.event_id" | ||
" WHERE event_edges.event_id = ?" | ||
" AND event_edges.is_state = ?" | ||
" LIMIT ?" | ||
) | ||
# Look for the prev_event_id connected to the given event_id | ||
query = """ | ||
SELECT depth, prev_event_id FROM event_edges | ||
/* Get the depth of the prev_event_id from the events table */ | ||
INNER JOIN events | ||
ON prev_event_id = events.event_id | ||
/* Find an event which matches the given event_id */ | ||
WHERE event_edges.event_id = ? | ||
AND event_edges.is_state = ? | ||
LIMIT ? | ||
""" | ||
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. Same as the previous query just in this new format with comments |
||
|
||
# Look for the "insertion" events connected to the given event_id | ||
connected_insertion_event_query = """ | ||
SELECT e.depth, i.event_id FROM insertion_event_edges AS i | ||
/* Get the depth of the insertion event from the events table */ | ||
INNER JOIN events AS e USING (event_id) | ||
/* Find an insertion event which points via prev_events to the given event_id */ | ||
WHERE i.insertion_prev_event_id = ? | ||
LIMIT ? | ||
""" | ||
|
||
# Find any chunk connections of a given insertion event | ||
chunk_connection_query = """ | ||
SELECT e.depth, c.event_id FROM insertion_events AS i | ||
/* Find the chunk that connects to the given insertion event */ | ||
INNER JOIN chunk_events AS c | ||
ON i.next_chunk_id = c.chunk_id | ||
/* Get the depth of the chunk start event from the events table */ | ||
INNER JOIN events AS e USING (event_id) | ||
/* Find an insertion event which matches the given event_id */ | ||
WHERE i.event_id = ? | ||
LIMIT ? | ||
""" | ||
|
||
# In a PriorityQueue, the lowest valued entries are retrieved first. | ||
# We're using depth as the priority in the queue. | ||
# Depth is lowest at the oldest-in-time message and highest and | ||
# newest-in-time message. We add events to the queue with a negative depth so that | ||
# we process the newest-in-time messages first going backwards in time. | ||
queue = PriorityQueue() | ||
|
||
for event_id in event_list: | ||
|
@@ -970,9 +1001,48 @@ def _get_backfill_events(self, txn, room_id, event_list, limit): | |
|
||
event_results.add(event_id) | ||
|
||
# Try and find any potential historical chunks of message history. | ||
# | ||
# First we look for an insertion event connected to the current | ||
# event (by prev_event). If we find any, we need to go and try to | ||
# find any chunk events connected to the insertion event (by | ||
# chunk_id). If we find any, we'll add them to the queue and | ||
# navigate up the DAG like normal in the next iteration of the loop. | ||
txn.execute( | ||
connected_insertion_event_query, (event_id, limit - len(event_results)) | ||
) | ||
connected_insertion_event_id_results = txn.fetchall() | ||
logger.debug( | ||
"_get_backfill_events: connected_insertion_event_query %s", | ||
connected_insertion_event_id_results, | ||
) | ||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for row in connected_insertion_event_id_results: | ||
connected_insertion_event_depth = row[0] | ||
connected_insertion_event = row[1] | ||
queue.put((-connected_insertion_event_depth, connected_insertion_event)) | ||
|
||
# Find any chunk connections for the given insertion event | ||
txn.execute( | ||
chunk_connection_query, | ||
(connected_insertion_event, limit - len(event_results)), | ||
) | ||
chunk_start_event_id_results = txn.fetchall() | ||
logger.debug( | ||
"_get_backfill_events: chunk_start_event_id_results %s", | ||
chunk_start_event_id_results, | ||
) | ||
for row in chunk_start_event_id_results: | ||
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( | ||
"_get_backfill_events: prev_event_ids %s", prev_event_id_results | ||
) | ||
|
||
for row in txn: | ||
for row in prev_event_id_results: | ||
if row[1] not in event_results: | ||
queue.put((-row[0], row[1])) | ||
|
||
|
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.