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
Fix historical messages backfilling in random order on remote homeservers (MSC2716) #11114
Merged
MadLittleMods
merged 55 commits into
develop
from
madlittlemods/return-historical-events-in-order-from-backfill
Feb 7, 2022
Merged
Changes from 10 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
f30302d
Scratch debugging why events appear out of order on remote homeservers
MadLittleMods 438e222
Use OrderedDict to gurantee order returned is the same as we were bui…
MadLittleMods 4983739
Avoid constant missing prev_event fetching while backfilling
MadLittleMods a64bb2e
Add changelog
MadLittleMods 260ca06
Some more trials of trying to get many many events to backfill in ord…
MadLittleMods 886071b
Fix backfill not picking up batch events connected to non-base insert…
MadLittleMods 477c15d
Some more debug logging
MadLittleMods 4191f56
Remove fake prev events from historical state chain
MadLittleMods f39c1da
Remove debug logging
MadLittleMods 7da8012
Remove extra event info
MadLittleMods 69dfa16
Move to sorting the backfill events in the existing sorted
MadLittleMods 83474d9
Put MSC2716 backfill logic behind experimental feature flag
MadLittleMods 1263c7e
Remove unused import
MadLittleMods ee47878
Fix mypy lints
MadLittleMods 5bfde7b
Merge branch 'master' into madlittlemods/return-historical-events-in-…
MadLittleMods 2fbe3f1
Merge branch 'develop' into madlittlemods/return-historical-events-in…
MadLittleMods 1d3f417
Revert back to string interpolation for SQL boolean value
MadLittleMods 4a12304
Put empty prev_events behind new room version
MadLittleMods 9a6d8fa
WIP: Don't include the event we branch from
MadLittleMods 3e09d49
Revert "WIP: Don't include the event we branch from"
MadLittleMods 5afc264
WIP: Sort events topologically when we receive them over backfill
MadLittleMods 6ea263b
Revert "WIP: Sort events topologically when we receive them over back…
MadLittleMods 3d387f9
WIP: Sort events topologically when we receive them over backfill
MadLittleMods fb8e281
Fix direction of fake edges
MadLittleMods c772b35
Implement backfill in handler so we can do fetching later
MadLittleMods e0ff66d
Fix backfill being able to cleanly branch into history and back to "l…
MadLittleMods 76d454f
Some backfill receive sorting fixes but not using it yet
MadLittleMods 3529449
Fix lints
MadLittleMods 321f9ea
Move back to the old get_backfill_events and simplify backfill.
MadLittleMods 15c3282
Remove the new backfill implementation and pull some good parts of th…
MadLittleMods 5db717a
Always process marker events regardless if backfilled
MadLittleMods e96fd5c
Add comment docs
MadLittleMods f3b7b3e
Add better explanatory comment
MadLittleMods 7f2105a
Remove topological sort when receiving backfill events
MadLittleMods 246278e
Fix lints
MadLittleMods ec35be5
Merge branch 'develop' into madlittlemods/return-historical-events-in…
MadLittleMods bc0ba8c
Protect from no auth events for non-existent provided prev_event
MadLittleMods 363aed6
Revert unused refactor to get PDU raw
MadLittleMods d771fbd
Only run the tests package to get streaming Complement output
MadLittleMods b559e23
Merge branch 'develop' into madlittlemods/return-historical-events-in…
MadLittleMods 6b64184
Merge branch 'develop' into madlittlemods/return-historical-events-in…
MadLittleMods 1d00043
Merge branch 'develop' into madlittlemods/return-historical-events-in…
MadLittleMods b071426
Plumb allow_no_prev_events through for MSC2716
MadLittleMods ec33a40
Make the historical events float separately from the state chain
MadLittleMods b99efa8
Plumb allow_no_prev_events through create_and_send_nonmember_event
MadLittleMods 3810ae1
Clarify comments
MadLittleMods df2a152
Fix NPE when trying to grab event from wrong roomId (fix sytest)
MadLittleMods cc4eb72
Merge branch 'develop' into madlittlemods/return-historical-events-in…
MadLittleMods 47590bb
Merge branch 'develop' into madlittlemods/return-historical-events-in…
MadLittleMods a38befa
Some review optimizations
MadLittleMods 033360a
Fix lints
MadLittleMods 3f22e42
Fix unused lint
MadLittleMods e5670ff
Fix lints
MadLittleMods 023bd3e
Don't run MSC2716 complement tests for everyone
MadLittleMods b3fcffb
Use same txn iteration optimization
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 @@ | ||
| Fix [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716) historical messages backfilling in random order on remote homeservers. |
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
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 |
|---|---|---|
|
|
@@ -13,10 +13,6 @@ | |
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def generate_fake_event_id() -> str: | ||
| return "$fake_" + random_string(43) | ||
|
|
||
|
|
||
| class RoomBatchHandler: | ||
| def __init__(self, hs: "HomeServer"): | ||
| self.hs = hs | ||
|
|
@@ -184,7 +180,7 @@ async def persist_state_events_at_start( | |
|
|
||
| # Make the state events float off on their own so we don't have a | ||
| # bunch of `@mxid joined the room` noise between each batch | ||
| prev_event_id_for_state_chain = generate_fake_event_id() | ||
| prev_event_ids_for_state_chain: List[str] = [] | ||
|
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.
|
||
|
|
||
| for state_event in state_events_at_start: | ||
| assert_params_in_dict( | ||
|
|
@@ -221,7 +217,7 @@ async def persist_state_events_at_start( | |
| action=membership, | ||
| content=event_dict["content"], | ||
| outlier=True, | ||
| prev_event_ids=[prev_event_id_for_state_chain], | ||
| prev_event_ids=prev_event_ids_for_state_chain, | ||
| # Make sure to use a copy of this list because we modify it | ||
| # later in the loop here. Otherwise it will be the same | ||
| # reference and also update in the event when we append later. | ||
|
|
@@ -240,7 +236,7 @@ async def persist_state_events_at_start( | |
| ), | ||
| event_dict, | ||
| outlier=True, | ||
| prev_event_ids=[prev_event_id_for_state_chain], | ||
| prev_event_ids=prev_event_ids_for_state_chain, | ||
| # Make sure to use a copy of this list because we modify it | ||
| # later in the loop here. Otherwise it will be the same | ||
| # reference and also update in the event when we append later. | ||
|
|
@@ -251,7 +247,7 @@ async def persist_state_events_at_start( | |
| state_event_ids_at_start.append(event_id) | ||
| auth_event_ids.append(event_id) | ||
| # Connect all the state in a floating chain | ||
| prev_event_id_for_state_chain = event_id | ||
| prev_event_ids_for_state_chain = [event_id] | ||
|
|
||
| return state_event_ids_at_start | ||
|
|
||
|
|
||
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 |
|---|---|---|
|
|
@@ -2139,16 +2139,21 @@ def _update_backward_extremeties(self, txn, events): | |
| " SELECT 1 FROM event_backward_extremities" | ||
| " WHERE event_id = ? AND room_id = ?" | ||
| " )" | ||
| # 1. Don't add an event as a extremity again if we already persisted it | ||
| # as a non-outlier. | ||
| # 2. Don't add an outlier as an extremity if it has no prev_events | ||
| " AND NOT EXISTS (" | ||
| " SELECT 1 FROM events WHERE event_id = ? AND room_id = ? " | ||
| " AND outlier = ?" | ||
| " SELECT 1 FROM events" | ||
| " LEFT JOIN event_edges edge" | ||
| " ON edge.event_id = events.event_id" | ||
| " WHERE events.event_id = ? AND events.room_id = ? AND (events.outlier = FALSE OR edge.event_id IS NULL)" | ||
MadLittleMods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| " )" | ||
| ) | ||
|
|
||
| txn.execute_batch( | ||
| query, | ||
| [ | ||
| (e_id, ev.room_id, e_id, ev.room_id, e_id, ev.room_id, False) | ||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| (e_id, ev.room_id, e_id, ev.room_id, e_id, ev.room_id) | ||
| for ev in events | ||
| for e_id in ev.prev_event_ids() | ||
| if not ev.internal_metadata.is_outlier() | ||
|
|
@@ -2167,6 +2172,10 @@ def _update_backward_extremeties(self, txn, events): | |
| (ev.event_id, ev.room_id) | ||
| for ev in events | ||
| if not ev.internal_metadata.is_outlier() | ||
| # If we encountered an event with no prev_events, then we might | ||
| # as well remove it now because it won't ever have anything else | ||
| # to backfill from. | ||
| or len(ev.prev_event_ids()) == 0 | ||
|
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. Since the floating historical state are outliers, we want to still try to remove them if we know they don't have any |
||
| ], | ||
| ) | ||
|
|
||
|
|
||
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.