This repository has been 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 rooms.room_version
column
#6729
Merged
+270
−73
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7b6be4b
Have `make_membership_event` return room version
erikjohnston f01d0d5
Check room_version from make_join matches returned state.
erikjohnston a42b675
Use RoomVersion consistently throughout room upgrade
erikjohnston 963237f
Add rooms.room_version column and populate it in store_room
erikjohnston e7618af
Read room version from rooms table.
erikjohnston 0bb025a
Newsfile
erikjohnston 892bab9
Add background update
erikjohnston 70be703
Correctly raise exception if unknown room version
erikjohnston ced73b3
Add comment
erikjohnston 53a75fa
Use explicit is not None
erikjohnston e825fd0
Add comments about paranoia
erikjohnston 1474a49
Correctly handle and document UnsupportedRoomVersionError
erikjohnston 126599e
Merge branch 'develop' of github.com:matrix-org/synapse into erikj/ro…
erikjohnston 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 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 |
---|---|---|
|
@@ -28,10 +28,10 @@ | |
|
||
from synapse.api.constants import EventTypes | ||
from synapse.api.errors import StoreError | ||
from synapse.api.room_versions import RoomVersion | ||
from synapse.api.room_versions import RoomVersion, RoomVersions | ||
from synapse.storage._base import SQLBaseStore | ||
from synapse.storage.data_stores.main.search import SearchStore | ||
from synapse.storage.database import Database | ||
from synapse.storage.database import Database, LoggingTransaction | ||
from synapse.types import ThirdPartyInstanceID | ||
from synapse.util.caches.descriptors import cached, cachedInlineCallbacks | ||
|
||
|
@@ -612,6 +612,7 @@ def _quarantine_media_txn( | |
|
||
class RoomBackgroundUpdateStore(SQLBaseStore): | ||
REMOVE_TOMESTONED_ROOMS_BG_UPDATE = "remove_tombstoned_rooms_from_directory" | ||
ADD_ROOMS_ROOM_VERSION_COLUMN = "add_rooms_room_version_column" | ||
|
||
def __init__(self, database: Database, db_conn, hs): | ||
super(RoomBackgroundUpdateStore, self).__init__(database, db_conn, hs) | ||
|
@@ -627,6 +628,11 @@ def __init__(self, database: Database, db_conn, hs): | |
self._remove_tombstoned_rooms_from_directory, | ||
) | ||
|
||
self.db.updates.register_background_update_handler( | ||
self.ADD_ROOMS_ROOM_VERSION_COLUMN, | ||
self._background_add_rooms_room_version_column, | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def _background_insert_retention(self, progress, batch_size): | ||
"""Retrieves a list of all rooms within a range and inserts an entry for each of | ||
|
@@ -695,6 +701,69 @@ def _background_insert_retention_txn(txn): | |
|
||
defer.returnValue(batch_size) | ||
|
||
async def _background_add_rooms_room_version_column( | ||
self, progress: dict, batch_size: int | ||
): | ||
"""Background update to go and add room version inforamtion to `rooms` | ||
table from `current_state_events` table. | ||
""" | ||
|
||
last_room_id = progress.get("room_id", "") | ||
|
||
def _background_add_rooms_room_version_column_txn(txn: LoggingTransaction): | ||
sql = """ | ||
SELECT room_id, json FROM current_state_events | ||
INNER JOIN event_json USING (room_id, event_id) | ||
WHERE room_id > ? AND type = 'm.room.create' AND state_key = '' | ||
ORDER BY room_id | ||
LIMIT ? | ||
""" | ||
|
||
txn.execute(sql, (last_room_id, batch_size)) | ||
|
||
updates = [] | ||
for room_id, event_json in txn: | ||
event_dict = json.loads(event_json) | ||
room_version_id = event_dict.get("content", {}).get( | ||
"room_version", RoomVersions.V1.identifier | ||
) | ||
|
||
creator = event_dict.get("content").get("creator") | ||
|
||
updates.append((room_id, creator, room_version_id)) | ||
|
||
if not updates: | ||
return True | ||
|
||
new_last_room_id = "" | ||
for room_id, creator, room_version_id in updates: | ||
self.db.simple_upsert_txn( | ||
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're expecting to find rooms which aren't currently in 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. Nooooooooooooooooo not really. But equally I don't fancy betting on that fact, given we don't insert it in the same places we insert I could add a comment |
||
txn, | ||
table="rooms", | ||
keyvalues={"room_id": room_id}, | ||
values={"room_version": room_version_id}, | ||
insertion_values={"is_public": False, "creator": creator}, | ||
) | ||
new_last_room_id = room_id | ||
|
||
self.db.updates._background_update_progress_txn( | ||
txn, self.ADD_ROOMS_ROOM_VERSION_COLUMN, {"room_id": new_last_room_id} | ||
) | ||
|
||
return False | ||
|
||
end = await self.db.runInteraction( | ||
"_background_add_rooms_room_version_column", | ||
_background_add_rooms_room_version_column_txn, | ||
) | ||
|
||
if end: | ||
await self.db.updates._end_background_update( | ||
self.ADD_ROOMS_ROOM_VERSION_COLUMN | ||
) | ||
|
||
return batch_size | ||
|
||
async def _remove_tombstoned_rooms_from_directory( | ||
self, progress, batch_size | ||
) -> int: | ||
|
This file contains 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
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.
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.
is this going to table-scan
CSE
? shouldn't we base it onrooms
instead?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.
There's a unique index on
(room_id, type, state_key)
so it just walks the index.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.
right, but it's going to need to walk the entire index? Or am I misunderstanding how btree indexes work?
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.
Well, it'll iterate over each room and then look up the create event for each within that, AIUI.
The query plan for it on jki.re seems to show it doing that:
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.
right, my concern is the index scan over that entire index, which is presumably huge on big servers, and it seems like a bunch of unnecessary I/O when we don't care about all the other events in that index.
this isn't a blocking comment; if you think it's going to be ok then that's fine. it was just a thought.
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.
I'm reasonably sure it'll be fine. It will efficiently jump straight to the correct room ID, and jumping to the next room ID is fast (it won't have to iterate over all the state in the room, as it uses the tree structure to do it), so it should just be looking up the next room ID in the btree index, using the index to pull out the create event ID, repeating.