-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug in sliding sync when using old DB. (default instance_name
to "master"
)
#17398
Changes from 6 commits
59314d5
c742b74
b2880b6
b177307
5a47fed
24444a4
d15d8ab
5f1612e
fb2fc47
c8f1411
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix bug in experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync` endpoint when using an old database. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,12 +50,7 @@ | |
from synapse.storage.databases.main.cache import CacheInvalidationWorkerStore | ||
from synapse.storage.databases.main.events_worker import EventsWorkerStore | ||
from synapse.storage.engines import Sqlite3Engine | ||
from synapse.storage.roommember import ( | ||
GetRoomsForUserWithStreamOrdering, | ||
MemberSummary, | ||
ProfileInfo, | ||
RoomsForUser, | ||
) | ||
from synapse.storage.roommember import MemberSummary, ProfileInfo, RoomsForUser | ||
from synapse.types import ( | ||
JsonDict, | ||
PersistedEventPosition, | ||
|
@@ -494,7 +489,11 @@ def _get_rooms_for_local_user_where_membership_is_txn( | |
sender=sender, | ||
membership=membership, | ||
event_id=event_id, | ||
event_pos=PersistedEventPosition(instance_name, stream_ordering), | ||
event_pos=PersistedEventPosition( | ||
# If instance_name is null we default to "master" | ||
instance_name or "master", | ||
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. We should probably have some constant to represent (can iterate in another PR) 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. The typing from the SQL queries makes this type of thing too easy. Kinda wish we had to duck-type all of it to narrow things down (forced by the linter instead of letting it slide because 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. There's no real easy way of annotating the types of the returned rows that aren't error prone, e.g. here we'd probably assume 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 guess we just need to use the 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 have thought about this in the past, the best idea I came up with is: during the trial tests, have Postgres return the type information of the SQL statements (and combine this with an API change on the |
||
stream_ordering, | ||
), | ||
room_version_id=room_version, | ||
) | ||
erikjohnston marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for room_id, sender, membership, event_id, instance_name, stream_ordering, room_version in txn | ||
|
@@ -606,53 +605,6 @@ async def get_local_current_membership_for_user_in_room( | |
|
||
return results | ||
|
||
@cached(max_entries=500000, iterable=True) | ||
async def get_rooms_for_user_with_stream_ordering( | ||
self, user_id: str | ||
) -> FrozenSet[GetRoomsForUserWithStreamOrdering]: | ||
"""Returns a set of room_ids the user is currently joined to. | ||
|
||
If a remote user only returns rooms this server is currently | ||
participating in. | ||
|
||
Args: | ||
user_id | ||
|
||
Returns: | ||
Returns the rooms the user is in currently, along with the stream | ||
ordering of the most recent join for that user and room, along with | ||
the room version of the room. | ||
""" | ||
return await self.db_pool.runInteraction( | ||
"get_rooms_for_user_with_stream_ordering", | ||
self._get_rooms_for_user_with_stream_ordering_txn, | ||
user_id, | ||
) | ||
|
||
def _get_rooms_for_user_with_stream_ordering_txn( | ||
self, txn: LoggingTransaction, user_id: str | ||
) -> FrozenSet[GetRoomsForUserWithStreamOrdering]: | ||
# We use `current_state_events` here and not `local_current_membership` | ||
# as a) this gets called with remote users and b) this only gets called | ||
# for rooms the server is participating in. | ||
sql = """ | ||
SELECT room_id, e.instance_name, e.stream_ordering | ||
FROM current_state_events AS c | ||
INNER JOIN events AS e USING (room_id, event_id) | ||
WHERE | ||
c.type = 'm.room.member' | ||
AND c.state_key = ? | ||
AND c.membership = ? | ||
""" | ||
|
||
txn.execute(sql, (user_id, Membership.JOIN)) | ||
return frozenset( | ||
GetRoomsForUserWithStreamOrdering( | ||
room_id, PersistedEventPosition(instance, stream_id) | ||
) | ||
for room_id, instance, stream_id in txn | ||
) | ||
|
||
async def get_users_server_still_shares_room_with( | ||
self, user_ids: Collection[str] | ||
) -> Set[str]: | ||
|
@@ -701,13 +653,6 @@ async def get_rooms_for_user(self, user_id: str) -> FrozenSet[str]: | |
If a remote user only returns rooms this server is currently | ||
participating in. | ||
""" | ||
rooms = self.get_rooms_for_user_with_stream_ordering.cache.get_immediate( | ||
(user_id,), | ||
None, | ||
update_metrics=False, | ||
) | ||
if rooms: | ||
return frozenset(r.room_id for r in rooms) | ||
|
||
room_ids = await self.db_pool.simple_select_onecol( | ||
table="current_state_events", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for trying out Sliding Sync and jumping on a fix for this!