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

Non lazy loading sync not blocking during fast join #14831

Closed
wants to merge 11 commits into from

Conversation

MatMaul
Copy link
Contributor

@MatMaul MatMaul commented Jan 12, 2023

Fix #12989.

DMR built on this in #14870

Pull Request Checklist

@MatMaul MatMaul self-assigned this Jan 13, 2023
@MatMaul MatMaul force-pushed the mv/non-ll-sync-fast-join branch 2 times, most recently from 39a0ddc to 6b43520 Compare January 16, 2023 17:06
@MatMaul MatMaul changed the title [WIP] Non lazy loading sync not blocking during fast join Non lazy loading sync not blocking during fast join Jan 16, 2023
@MatMaul MatMaul force-pushed the mv/non-ll-sync-fast-join branch 2 times, most recently from abbfb9d to 13ea6fa Compare January 17, 2023 08:11
Signed-off-by: Mathieu Velten <mathieuv@matrix.org>
@MatMaul MatMaul force-pushed the mv/non-ll-sync-fast-join branch from 13ea6fa to 3bad02f Compare January 17, 2023 08:32
@MatMaul MatMaul marked this pull request as ready for review January 17, 2023 09:59
@MatMaul MatMaul requested a review from a team as a code owner January 17, 2023 09:59
Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable. Do you have any complement tests for this? (i.e. how do we know this works?)

changelog.d/14831.misc Outdated Show resolved Hide resolved
synapse/types/__init__.py Outdated Show resolved Hide resolved
synapse/storage/databases/main/room.py Outdated Show resolved Hide resolved
synapse/handlers/sync.py Outdated Show resolved Hide resolved
synapse/types/__init__.py Show resolved Hide resolved
synapse/handlers/sync.py Outdated Show resolved Hide resolved
synapse/handlers/sync.py Outdated Show resolved Hide resolved
synapse/handlers/sync.py Outdated Show resolved Hide resolved
synapse/handlers/sync.py Outdated Show resolved Hide resolved
synapse/handlers/sync.py Show resolved Hide resolved
@MatMaul
Copy link
Contributor Author

MatMaul commented Jan 17, 2023

Seems reasonable. Do you have any complement tests for this? (i.e. how do we know this works?)

Yes, I've just opened a PR with Complement side of the changes.
This includes a test that was checking sync was blocking, and is now checking that it is NOT blocking and that we still get the joined room after the resync (NonLazySyncDuringPartialStateJoin).

Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Would be good to double-check #14831 (comment) if you get a chance though

@squahtx
Copy link
Contributor

squahtx commented Jan 17, 2023

Perhaps I have missed something, but when a room is un-partial stated while an incremental sync is waiting for updates, do we wake up the sync?
Also can we have a complement test for it?

@squahtx
Copy link
Contributor

squahtx commented Jan 17, 2023

also do we want / need to do anything for rooms that become un-partial stated after we leave them?

@MatMaul
Copy link
Contributor Author

MatMaul commented Jan 18, 2023

Perhaps I have missed something, but when a room is un-partial stated while an incremental sync is waiting for updates, do we wake up the sync? Also can we have a complement test for it?

Oh sorry I missed your comment. I think I came to the conclusion that it was handled generically by the stream code but I'll double check, and add a test for it indeed, thanks.

@DMRobertson DMRobertson self-requested a review January 18, 2023 14:31
@@ -1819,8 +1819,12 @@ async def _generate_sync_entry_for_rooms(

# Retrieve rooms that got un partial stated in the meantime, only useful in case
# of a non lazy-loading-members sync.
# We also skip calculating that in case of initial sync since we don't need it.
Copy link
Contributor

@DMRobertson DMRobertson Jan 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following you here. I thought we want to exclude partially-joined rooms from all non-lazy load syncs. Why should that not also apply to an initial, non-lazy sync?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We skip calculating the rooms that got unpartialstated because in case of initial, we have another piece of code that already exclude any partial stated rooms. The stream of unpartialstated rooms is only useful to know which ones have been unpartialed between 2 syncs, for an initial sync we just directly check the DB.

@MatMaul
Copy link
Contributor Author

MatMaul commented Jan 18, 2023

Oh sorry I missed your comment. I think I came to the conclusion that it was handled generically by the stream code but I'll double check, and add a test for it indeed, thanks.

I have a test, and I was wrong, it doesn't work :/ I am trying to fix it right now.

also do we want / need to do anything for rooms that become un-partial stated after we leave them?

I'll put some thoughts into that after fixing the notifying behavior.

Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing where we exclude things for partially joined rooms during incremental, non-lazy syncs. C.f. matrix-org/complement#584 (review)

I'm finding this tricky to follow in general. It might be worth pairing tomorrow to try and chop this up into some smaller pieces, if you're up for that

Comment on lines +1820 to +1822
# Retrieve rooms that got un partial stated in the meantime, only useful in case
# of a non lazy-loading-members sync.
# We also skip calculating that in case of initial sync since we don't need it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: For nonlazy, incremental syncs: find all the rooms we excluded in previous nonlazy syncs that we can now disclose to the user.

Comment on lines +1846 to +1848
have_changed = await self._have_rooms_changed(
sync_result_builder, un_partial_stated_rooms
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every un-psed room during the sync period is considered to have "changed", i.e., client needs to be informed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rooms which are partial stated need to not sure up in a non-lazy sync. Where is this done? Should this be here?

EJ: this method is better called "should_we_tell_the_client_about_this_room_lol"

entry = RoomSyncResultBuilder(
room_id=room_id,
rtype="joined",
events=None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EJ: are we going to lose events from room_events? Maybe... but we should treat this like a newly_joined room (it is from the client's perspective) so I think this is fine

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EJ: Does newly_joined_rooms need to be updated to include un-partial-stated rooms and exclude those which are currently partial stated? See the return value of this function

Comment on lines +2239 to +2245
# Do not include rooms that we don't have the full state yet
# in case of non lazy-loading-members sync.
if (
not sync_config.filter_collection.lazy_load_members()
) and await self.store.is_partial_state_room(event.room_id):
continue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an initial sync, we completely ignore rooms that are currently partially stated

Comment on lines 1825 to 1830
since_token
and not sync_result_builder.sync_config.filter_collection.lazy_load_members()
):
un_partial_stated_rooms_since = 0
if sync_result_builder.since_token is not None:
un_partial_stated_rooms_since = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we're checking since_token on +1825, we always hit +1830. So 1828 and 1829 are redundant.

@MatMaul
Copy link
Contributor Author

MatMaul commented Jan 18, 2023

Proper wake up of the long polling syncs has been added, and a matching test has been added to complement.

@DMRobertson
Copy link
Contributor

also do we want / need to do anything for rooms that become un-partial stated after we leave them?

@squahtx Putting aside the fact that we can't leave during partial state yet... (oh, I guess you could be kicked)...

We think this should be okay.

  • Eager syncs won't see the room when we partial-join
  • Eager syncs won't see anything when we leave during partial-state, because partial state rooms are hidden from eager syncs
  • When the resync completes, the call to get_un_partial_stated_rooms_between will only return rooms that we're currently joined to (via its third argument).

Worth a complement test though. I'll add it as a todo on the leave-during-resync issue.

@DMRobertson
Copy link
Contributor

Superseded by #14870

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Faster joins: non-lazy_load_members /syncs should not block
3 participants