From 4d3ed3c371001a2edf9d178e0dd48dc804c610f1 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 16 Sep 2021 17:25:38 -0500 Subject: [PATCH 1/8] Rename MSC2716 things from chunk to batch to match /batch_send endpoint See https://github.com/matrix-org/matrix-doc/pull/2716#discussion_r684574497 Dropping support for older MSC2716 room versions so we don't have to worry about supporting both chunk and batch events. --- synapse/api/constants.py | 10 ++-- synapse/api/room_versions.py | 20 +------ synapse/event_auth.py | 8 +-- synapse/events/utils.py | 6 +- synapse/rest/client/room_batch.py | 76 ++++++++++++------------ synapse/storage/databases/main/events.py | 46 +++++++------- 6 files changed, 75 insertions(+), 91 deletions(-) diff --git a/synapse/api/constants.py b/synapse/api/constants.py index 829061c870c4..c6454aafc569 100644 --- a/synapse/api/constants.py +++ b/synapse/api/constants.py @@ -121,7 +121,7 @@ class EventTypes: SpaceParent = "m.space.parent" MSC2716_INSERTION = "org.matrix.msc2716.insertion" - MSC2716_CHUNK = "org.matrix.msc2716.chunk" + MSC2716_BATCH = "org.matrix.msc2716.batch" MSC2716_MARKER = "org.matrix.msc2716.marker" @@ -200,11 +200,11 @@ class EventContentFields: # Used on normal messages to indicate they were historically imported after the fact MSC2716_HISTORICAL = "org.matrix.msc2716.historical" - # For "insertion" events to indicate what the next chunk ID should be in + # For "insertion" events to indicate what the next batch ID should be in # order to connect to it - MSC2716_NEXT_CHUNK_ID = "org.matrix.msc2716.next_chunk_id" - # Used on "chunk" events to indicate which insertion event it connects to - MSC2716_CHUNK_ID = "org.matrix.msc2716.chunk_id" + MSC2716_NEXT_BATCH_ID = "org.matrix.msc2716.next_batch_id" + # Used on "batch" events to indicate which insertion event it connects to + MSC2716_BATCH_ID = "org.matrix.msc2716.batch_id" # For "marker" events MSC2716_MARKER_INSERTION = "org.matrix.msc2716.marker.insertion" diff --git a/synapse/api/room_versions.py b/synapse/api/room_versions.py index a19be6707a85..4d0bf51ffc56 100644 --- a/synapse/api/room_versions.py +++ b/synapse/api/room_versions.py @@ -244,24 +244,8 @@ class RoomVersions: msc2716_historical=False, msc2716_redactions=False, ) - MSC2716 = RoomVersion( - "org.matrix.msc2716", - RoomDisposition.UNSTABLE, - EventFormatVersions.V3, - StateResolutionVersions.V2, - enforce_key_validity=True, - special_case_aliases_auth=False, - strict_canonicaljson=True, - limit_notifications_power_levels=True, - msc2176_redaction_rules=False, - msc3083_join_rules=False, - msc3375_redaction_rules=False, - msc2403_knocking=True, - msc2716_historical=True, - msc2716_redactions=False, - ) - MSC2716v2 = RoomVersion( - "org.matrix.msc2716v2", + MSC2716v3 = RoomVersion( + "org.matrix.msc2716v3", RoomDisposition.UNSTABLE, EventFormatVersions.V3, StateResolutionVersions.V2, diff --git a/synapse/event_auth.py b/synapse/event_auth.py index c3a0c10499d9..72d66ec872e4 100644 --- a/synapse/event_auth.py +++ b/synapse/event_auth.py @@ -207,7 +207,7 @@ def check( if ( event.type == EventTypes.MSC2716_INSERTION - or event.type == EventTypes.MSC2716_CHUNK + or event.type == EventTypes.MSC2716_BATCH or event.type == EventTypes.MSC2716_MARKER ): check_historical(room_version_obj, event, auth_events) @@ -549,14 +549,14 @@ def check_historical( auth_events: StateMap[EventBase], ) -> None: """Check whether the event sender is allowed to send historical related - events like "insertion", "chunk", and "marker". + events like "insertion", "batch", and "marker". Returns: None Raises: AuthError if the event sender is not allowed to send historical related events - ("insertion", "chunk", and "marker"). + ("insertion", "batch", and "marker"). """ # Ignore the auth checks in room versions that do not support historical # events @@ -570,7 +570,7 @@ def check_historical( if user_level < historical_level: raise AuthError( 403, - 'You don\'t have permission to send send historical related events ("insertion", "chunk", and "marker")', + 'You don\'t have permission to send send historical related events ("insertion", "batch", and "marker")', ) diff --git a/synapse/events/utils.py b/synapse/events/utils.py index fb22337e2759..f86113a448c3 100644 --- a/synapse/events/utils.py +++ b/synapse/events/utils.py @@ -141,9 +141,9 @@ def add_fields(*fields): elif event_type == EventTypes.Redaction and room_version.msc2176_redaction_rules: add_fields("redacts") elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_INSERTION: - add_fields(EventContentFields.MSC2716_NEXT_CHUNK_ID) - elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_CHUNK: - add_fields(EventContentFields.MSC2716_CHUNK_ID) + add_fields(EventContentFields.MSC2716_NEXT_BATCH_ID) + elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_BATCH: + add_fields(EventContentFields.MSC2716_BATCH_ID) elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_MARKER: add_fields(EventContentFields.MSC2716_MARKER_INSERTION) diff --git a/synapse/rest/client/room_batch.py b/synapse/rest/client/room_batch.py index 3172aba60563..4fba1f6144a5 100644 --- a/synapse/rest/client/room_batch.py +++ b/synapse/rest/client/room_batch.py @@ -34,25 +34,25 @@ class RoomBatchSendEventRestServlet(RestServlet): """ - API endpoint which can insert a chunk of events historically back in time + API endpoint which can insert a batch of events historically back in time next to the given `prev_event`. - `chunk_id` comes from `next_chunk_id `in the response of the batch send - endpoint and is derived from the "insertion" events added to each chunk. + `batch_id` comes from `next_batch_id `in the response of the batch send + endpoint and is derived from the "insertion" events added to each batch. It's not required for the first batch send. `state_events_at_start` is used to define the historical state events needed to auth the events like join events. These events will float outside of the normal DAG as outlier's and won't be visible in the chat - history which also allows us to insert multiple chunks without having a bunch - of `@mxid joined the room` noise between each chunk. + history which also allows us to insert multiple batches without having a bunch + of `@mxid joined the room` noise between each batch. - `events` is chronological chunk/list of events you want to insert. - There is a reverse-chronological constraint on chunks so once you insert + `events` is chronological list of events you want to insert. + There is a reverse-chronological constraint on batches so once you insert some messages, you can only insert older ones after that. - tldr; Insert chunks from your most recent history -> oldest history. + tldr; Insert batches from your most recent history -> oldest history. - POST /_matrix/client/unstable/org.matrix.msc2716/rooms//batch_send?prev_event=&chunk_id= + POST /_matrix/client/unstable/org.matrix.msc2716/rooms//batch_send?prev_event=&batch_id= { "events": [ ... ], "state_events_at_start": [ ... ] @@ -120,7 +120,7 @@ def _create_insertion_event_dict( self, sender: str, room_id: str, origin_server_ts: int ): """Creates an event dict for an "insertion" event with the proper fields - and a random chunk ID. + and a random batch ID. Args: sender: The event author MXID @@ -131,13 +131,13 @@ def _create_insertion_event_dict( Tuple of event ID and stream ordering position """ - next_chunk_id = random_string(8) + next_batch_id = random_string(8) insertion_event = { "type": EventTypes.MSC2716_INSERTION, "sender": sender, "room_id": room_id, "content": { - EventContentFields.MSC2716_NEXT_CHUNK_ID: next_chunk_id, + EventContentFields.MSC2716_NEXT_BATCH_ID: next_batch_id, EventContentFields.MSC2716_HISTORICAL: True, }, "origin_server_ts": origin_server_ts, @@ -177,7 +177,7 @@ async def on_POST(self, request, room_id): assert_params_in_dict(body, ["state_events_at_start", "events"]) prev_events_from_query = parse_strings_from_args(request.args, "prev_event") - chunk_id_from_query = parse_string(request, "chunk_id") + batch_id_from_query = parse_string(request, "batch_id") if prev_events_from_query is None: raise SynapseError( @@ -277,18 +277,18 @@ async def on_POST(self, request, room_id): prev_events_from_query ) - # Figure out which chunk to connect to. If they passed in - # chunk_id_from_query let's use it. The chunk ID passed in comes - # from the chunk_id in the "insertion" event from the previous chunk. - last_event_in_chunk = events_to_create[-1] - chunk_id_to_connect_to = chunk_id_from_query + # Figure out which batch to connect to. If they passed in + # batch_id_from_query let's use it. The batch ID passed in comes + # from the batch_id in the "insertion" event from the previous batch. + last_event_in_batch = events_to_create[-1] + batch_id_to_connect_to = batch_id_from_query base_insertion_event = None - if chunk_id_from_query: + if batch_id_from_query: # All but the first base insertion event should point at a fake # event, which causes the HS to ask for the state at the start of - # the chunk later. + # the batch later. prev_event_ids = [fake_prev_event_id] - # TODO: Verify the chunk_id_from_query corresponds to an insertion event + # TODO: Verify the batch_id_from_query corresponds to an insertion event pass # Otherwise, create an insertion event to act as a starting point. # @@ -303,7 +303,7 @@ async def on_POST(self, request, room_id): base_insertion_event_dict = self._create_insertion_event_dict( sender=requester.user.to_string(), room_id=room_id, - origin_server_ts=last_event_in_chunk["origin_server_ts"], + origin_server_ts=last_event_in_batch["origin_server_ts"], ) base_insertion_event_dict["prev_events"] = prev_event_ids.copy() @@ -322,38 +322,38 @@ async def on_POST(self, request, room_id): depth=inherited_depth, ) - chunk_id_to_connect_to = base_insertion_event["content"][ - EventContentFields.MSC2716_NEXT_CHUNK_ID + batch_id_to_connect_to = base_insertion_event["content"][ + EventContentFields.MSC2716_NEXT_BATCH_ID ] - # Connect this current chunk to the insertion event from the previous chunk - chunk_event = { - "type": EventTypes.MSC2716_CHUNK, + # Connect this current batch to the insertion event from the previous batch + batch_event = { + "type": EventTypes.MSC2716_BATCH, "sender": requester.user.to_string(), "room_id": room_id, "content": { - EventContentFields.MSC2716_CHUNK_ID: chunk_id_to_connect_to, + EventContentFields.MSC2716_BATCH_ID: batch_id_to_connect_to, EventContentFields.MSC2716_HISTORICAL: True, }, - # Since the chunk event is put at the end of the chunk, + # Since the batch event is put at the end of the batch, # where the newest-in-time event is, copy the origin_server_ts from # the last event we're inserting - "origin_server_ts": last_event_in_chunk["origin_server_ts"], + "origin_server_ts": last_event_in_batch["origin_server_ts"], } - # Add the chunk event to the end of the chunk (newest-in-time) - events_to_create.append(chunk_event) + # Add the batch event to the end of the batch (newest-in-time) + events_to_create.append(batch_event) - # Add an "insertion" event to the start of each chunk (next to the oldest-in-time - # event in the chunk) so the next chunk can be connected to this one. + # Add an "insertion" event to the start of each batch (next to the oldest-in-time + # event in the batch) so the next batch can be connected to this one. insertion_event = self._create_insertion_event_dict( sender=requester.user.to_string(), room_id=room_id, - # Since the insertion event is put at the start of the chunk, + # Since the insertion event is put at the start of the batch, # where the oldest-in-time event is, copy the origin_server_ts from # the first event we're inserting origin_server_ts=events_to_create[0]["origin_server_ts"], ) - # Prepend the insertion event to the start of the chunk (oldest-in-time) + # Prepend the insertion event to the start of the batch (oldest-in-time) events_to_create = [insertion_event] + events_to_create event_ids = [] @@ -420,8 +420,8 @@ async def on_POST(self, request, room_id): return 200, { "state_events": state_events_at_start, "events": event_ids, - "next_chunk_id": insertion_event["content"][ - EventContentFields.MSC2716_NEXT_CHUNK_ID + "next_batch_id": insertion_event["content"][ + EventContentFields.MSC2716_NEXT_BATCH_ID ], } diff --git a/synapse/storage/databases/main/events.py b/synapse/storage/databases/main/events.py index 40b53274fb3d..f53886fb31c5 100644 --- a/synapse/storage/databases/main/events.py +++ b/synapse/storage/databases/main/events.py @@ -1503,7 +1503,7 @@ def _update_metadata_tables_txn( self._handle_event_relations(txn, event) self._handle_insertion_event(txn, event) - self._handle_chunk_event(txn, event) + self._handle_batch_event(txn, event) # Store the labels for this event. labels = event.content.get(EventContentFields.LABELS) @@ -1776,23 +1776,23 @@ def _handle_insertion_event(self, txn: LoggingTransaction, event: EventBase): if not room_version.msc2716_historical: return - next_chunk_id = event.content.get(EventContentFields.MSC2716_NEXT_CHUNK_ID) - if next_chunk_id is None: - # Invalid insertion event without next chunk ID + next_batch_id = event.content.get(EventContentFields.MSC2716_NEXT_BATCH_ID) + if next_batch_id is None: + # Invalid insertion event without next batch ID return logger.debug( - "_handle_insertion_event (next_chunk_id=%s) %s", next_chunk_id, event + "_handle_insertion_event (next_batch_id=%s) %s", next_batch_id, event ) - # Keep track of the insertion event and the chunk ID + # Keep track of the insertion event and the batch ID self.db_pool.simple_insert_txn( txn, table="insertion_events", values={ "event_id": event.event_id, "room_id": event.room_id, - "next_chunk_id": next_chunk_id, + "next_batch_id": next_batch_id, }, ) @@ -1808,8 +1808,8 @@ def _handle_insertion_event(self, txn: LoggingTransaction, event: EventBase): }, ) - def _handle_chunk_event(self, txn: LoggingTransaction, event: EventBase): - """Handles inserting the chunk edges/connections between the chunk event + def _handle_batch_event(self, txn: LoggingTransaction, event: EventBase): + """Handles inserting the batch edges/connections between the batch event and an insertion event. Part of MSC2716. Args: @@ -1817,45 +1817,45 @@ def _handle_chunk_event(self, txn: LoggingTransaction, event: EventBase): event: The event to process """ - if event.type != EventTypes.MSC2716_CHUNK: - # Not a chunk event + if event.type != EventTypes.MSC2716_BATCH: + # Not a batch event return - # Skip processing a chunk event if the room version doesn't + # Skip processing a batch event if the room version doesn't # support it. room_version = self.store.get_room_version_txn(txn, event.room_id) if not room_version.msc2716_historical: return - chunk_id = event.content.get(EventContentFields.MSC2716_CHUNK_ID) - if chunk_id is None: - # Invalid chunk event without a chunk ID + batch_id = event.content.get(EventContentFields.MSC2716_BATCH_ID) + if batch_id is None: + # Invalid batch event without a batch ID return - logger.debug("_handle_chunk_event chunk_id=%s %s", chunk_id, event) + logger.debug("_handle_batch_event batch_id=%s %s", batch_id, event) - # Keep track of the insertion event and the chunk ID + # Keep track of the insertion event and the batch ID self.db_pool.simple_insert_txn( txn, - table="chunk_events", + table="batch_events", values={ "event_id": event.event_id, "room_id": event.room_id, - "chunk_id": chunk_id, + "batch_id": batch_id, }, ) - # When we receive an event with a `chunk_id` referencing the - # `next_chunk_id` of the insertion event, we can remove it from the + # When we receive an event with a `batch_id` referencing the + # `next_batch_id` of the insertion event, we can remove it from the # `insertion_event_extremities` table. sql = """ DELETE FROM insertion_event_extremities WHERE event_id IN ( SELECT event_id FROM insertion_events - WHERE next_chunk_id = ? + WHERE next_batch_id = ? ) """ - txn.execute(sql, (chunk_id,)) + txn.execute(sql, (batch_id,)) def _handle_redaction(self, txn, redacted_event_id): """Handles receiving a redaction and checking whether we need to remove From 1786113d404a1c7b5df23f65a660613a16cd8804 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 16 Sep 2021 17:36:11 -0500 Subject: [PATCH 2/8] Forgotten chunk -> batch --- synapse/storage/databases/main/room_batch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/synapse/storage/databases/main/room_batch.py b/synapse/storage/databases/main/room_batch.py index 54fa361d3e71..a383388757aa 100644 --- a/synapse/storage/databases/main/room_batch.py +++ b/synapse/storage/databases/main/room_batch.py @@ -18,11 +18,11 @@ class RoomBatchStore(SQLBaseStore): - async def get_insertion_event_by_chunk_id(self, chunk_id: str) -> Optional[str]: + async def get_insertion_event_by_batch_id(self, batch_id: str) -> Optional[str]: """Retrieve a insertion event ID. Args: - chunk_id: The chunk ID of the insertion event to retrieve. + batch_id: The batch ID of the insertion event to retrieve. Returns: The event_id of an insertion event, or None if there is no known @@ -30,7 +30,7 @@ async def get_insertion_event_by_chunk_id(self, chunk_id: str) -> Optional[str]: """ return await self.db_pool.simple_select_one_onecol( table="insertion_events", - keyvalues={"next_chunk_id": chunk_id}, + keyvalues={"next_batch_id": batch_id}, retcol="event_id", allow_none=True, ) From 176c8a9fa2aebd8e37940bb88d91ec82127cf8e0 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 16 Sep 2021 19:16:19 -0500 Subject: [PATCH 3/8] Add SQL changes --- synapse/api/room_versions.py | 2 +- synapse/handlers/message.py | 2 +- .../databases/main/event_federation.py | 30 +++++++++---------- synapse/storage/schema/__init__.py | 2 +- .../64/01msc2716_chunk_to_batch_rename.sql | 23 ++++++++++++++ 5 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql diff --git a/synapse/api/room_versions.py b/synapse/api/room_versions.py index eea3b84af12c..0a895bba480a 100644 --- a/synapse/api/room_versions.py +++ b/synapse/api/room_versions.py @@ -273,9 +273,9 @@ class RoomVersions: RoomVersions.V6, RoomVersions.MSC2176, RoomVersions.V7, - RoomVersions.MSC2716, RoomVersions.V8, RoomVersions.V9, + RoomVersions.MSC2716v3, ) } diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 10f1584a0056..1578cc20dd01 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -1421,7 +1421,7 @@ async def persist_and_notify_client_event( # structural protocol level). is_msc2716_event = ( original_event.type == EventTypes.MSC2716_INSERTION - or original_event.type == EventTypes.MSC2716_CHUNK + or original_event.type == EventTypes.MSC2716_BATCH or original_event.type == EventTypes.MSC2716_MARKER ) if not room_version_obj.msc2716_historical and is_msc2716_event: diff --git a/synapse/storage/databases/main/event_federation.py b/synapse/storage/databases/main/event_federation.py index 047782eb069a..10184d6ae762 100644 --- a/synapse/storage/databases/main/event_federation.py +++ b/synapse/storage/databases/main/event_federation.py @@ -1034,13 +1034,13 @@ def _get_backfill_events(self, txn, room_id, event_list, limit): LIMIT ? """ - # Find any chunk connections of a given insertion event - chunk_connection_query = """ + # Find any batch connections of a given insertion event + batch_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 */ + /* Find the batch that connects to the given insertion event */ + INNER JOIN batch_events AS c + ON i.next_batch_id = c.batch_id + /* Get the depth of the batch 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 = ? @@ -1077,12 +1077,12 @@ 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. + # Try and find any potential historical batches 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 + # find any batch events connected to the insertion event (by + # batch_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)) @@ -1097,17 +1097,17 @@ def _get_backfill_events(self, txn, room_id, event_list, limit): connected_insertion_event = row[1] queue.put((-connected_insertion_event_depth, connected_insertion_event)) - # Find any chunk connections for the given insertion event + # Find any batch connections for the given insertion event txn.execute( - chunk_connection_query, + batch_connection_query, (connected_insertion_event, limit - len(event_results)), ) - chunk_start_event_id_results = txn.fetchall() + batch_start_event_id_results = txn.fetchall() logger.debug( - "_get_backfill_events: chunk_start_event_id_results %s", - chunk_start_event_id_results, + "_get_backfill_events: batch_start_event_id_results %s", + batch_start_event_id_results, ) - for row in chunk_start_event_id_results: + for row in batch_start_event_id_results: if row[1] not in event_results: queue.put((-row[0], row[1])) diff --git a/synapse/storage/schema/__init__.py b/synapse/storage/schema/__init__.py index af9cc69949c3..aa2ce44c6c90 100644 --- a/synapse/storage/schema/__init__.py +++ b/synapse/storage/schema/__init__.py @@ -14,7 +14,7 @@ # When updating these values, please leave a short summary of the changes below. -SCHEMA_VERSION = 63 +SCHEMA_VERSION = 64 """Represents the expectations made by the codebase about the database schema This should be incremented whenever the codebase changes its requirements on the diff --git a/synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql b/synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql new file mode 100644 index 000000000000..5f3899320878 --- /dev/null +++ b/synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql @@ -0,0 +1,23 @@ +/* Copyright 2021 The Matrix.org Foundation C.I.C + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +ALTER TABLE insertion_events RENAME COLUMN next_chunk_id TO next_batch_id; +DROP INDEX insertion_events_next_chunk_id; +CREATE INDEX IF NOT EXISTS insertion_events_next_batch_id ON insertion_events(next_batch_id); + +ALTER TABLE chunk_events RENAME TO batch_events; +ALTER TABLE batch_events RENAME COLUMN chunk_id TO batch_id; +DROP INDEX chunk_events_chunk_id; +CREATE INDEX IF NOT EXISTS batch_events_batch_id ON batch_events(batch_id); From 4318525fa54f6abe02d44d416607cba302cfc0ad Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 16 Sep 2021 19:20:11 -0500 Subject: [PATCH 4/8] Add changelog --- changelog.d/10838.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/10838.misc diff --git a/changelog.d/10838.misc b/changelog.d/10838.misc new file mode 100644 index 000000000000..aff3680641fe --- /dev/null +++ b/changelog.d/10838.misc @@ -0,0 +1 @@ +Rename [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716) fields and event types from `chunk` to `batch` to match the `/batch_send` endpoint From 15b7dae4c2807eb3168fc467622ffde43a2aaccd Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 16 Sep 2021 19:47:02 -0500 Subject: [PATCH 5/8] Fix typo --- synapse/rest/client/room_batch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/rest/client/room_batch.py b/synapse/rest/client/room_batch.py index 1d30f2f92259..259404a87138 100644 --- a/synapse/rest/client/room_batch.py +++ b/synapse/rest/client/room_batch.py @@ -46,7 +46,7 @@ class RoomBatchSendEventRestServlet(RestServlet): API endpoint which can insert a batch of events historically back in time next to the given `prev_event`. - `batch_id` comes from `next_bacth_id `in the response of the batch send + `batch_id` comes from `next_batch_id `in the response of the batch send endpoint and is derived from the "insertion" events added to each batch. It's not required for the first batch send. From 75a74beb7ab7d2d41900ec2b894044955d659dce Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 16 Sep 2021 19:47:40 -0500 Subject: [PATCH 6/8] Add punctuation to changelog --- changelog.d/10838.misc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/10838.misc b/changelog.d/10838.misc index aff3680641fe..b1977d0a2ed7 100644 --- a/changelog.d/10838.misc +++ b/changelog.d/10838.misc @@ -1 +1 @@ -Rename [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716) fields and event types from `chunk` to `batch` to match the `/batch_send` endpoint +Rename [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716) fields and event types from `chunk` to `batch` to match the `/batch_send` endpoint. From 88e626ed5a03b039791452c6e4a557ab4f9083f3 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 20 Sep 2021 18:46:19 -0500 Subject: [PATCH 7/8] Go nuclear for SQLite column renames See https://github.com/matrix-org/synapse/pull/10838#discussion_r711011887 --- ...sc2716_chunk_to_batch_rename.sql.postgres} | 0 ...01msc2716_chunk_to_batch_rename.sql.sqlite | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+) rename synapse/storage/schema/main/delta/64/{01msc2716_chunk_to_batch_rename.sql => 01msc2716_chunk_to_batch_rename.sql.postgres} (100%) create mode 100644 synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql.sqlite diff --git a/synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql b/synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql.postgres similarity index 100% rename from synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql rename to synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql.postgres diff --git a/synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql.sqlite b/synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql.sqlite new file mode 100644 index 000000000000..a091ec566025 --- /dev/null +++ b/synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql.sqlite @@ -0,0 +1,37 @@ +/* Copyright 2021 The Matrix.org Foundation C.I.C + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +-- Re-create the insertion_events table since SQLite doesn't support better +-- renames for columns (next_chunk_id -> next_batch_id) +DROP TABLE insertion_events +CREATE TABLE IF NOT EXISTS insertion_events( + event_id TEXT NOT NULL, + room_id TEXT NOT NULL, + next_batch_id TEXT NOT NULL +); +CREATE UNIQUE INDEX IF NOT EXISTS insertion_events_event_id ON insertion_events(event_id); +CREATE INDEX IF NOT EXISTS insertion_events_next_batch_id ON insertion_events(next_batch_id); + +-- Re-create the chunk_events table since SQLite doesn't support better renames +-- for columns (chunk_id -> batch_id) +DROP TABLE chunk_events +CREATE TABLE IF NOT EXISTS batch_events( + event_id TEXT NOT NULL, + room_id TEXT NOT NULL, + batch_id TEXT NOT NULL +); + +CREATE UNIQUE INDEX IF NOT EXISTS batch_events_event_id ON batch_events(event_id); +CREATE INDEX IF NOT EXISTS batch_events_batch_id ON batch_events(batch_id); From fb905e6d70730a3f8022cbe70832cfcf24f494a2 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 20 Sep 2021 20:30:59 -0500 Subject: [PATCH 8/8] Fix sql syntax --- .../main/delta/64/01msc2716_chunk_to_batch_rename.sql.sqlite | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql.sqlite b/synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql.sqlite index a091ec566025..498956399597 100644 --- a/synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql.sqlite +++ b/synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql.sqlite @@ -15,7 +15,7 @@ -- Re-create the insertion_events table since SQLite doesn't support better -- renames for columns (next_chunk_id -> next_batch_id) -DROP TABLE insertion_events +DROP TABLE insertion_events; CREATE TABLE IF NOT EXISTS insertion_events( event_id TEXT NOT NULL, room_id TEXT NOT NULL, @@ -26,7 +26,7 @@ CREATE INDEX IF NOT EXISTS insertion_events_next_batch_id ON insertion_events(ne -- Re-create the chunk_events table since SQLite doesn't support better renames -- for columns (chunk_id -> batch_id) -DROP TABLE chunk_events +DROP TABLE chunk_events; CREATE TABLE IF NOT EXISTS batch_events( event_id TEXT NOT NULL, room_id TEXT NOT NULL,