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

Commit 51e2db3

Browse files
Rename MSC2716 things from chunk to batch to match /batch_send endpoint (#10838)
See matrix-org/matrix-spec-proposals#2716 (comment) Dropping support for older MSC2716 room versions so we don't have to worry about supporting both chunk and batch events.
1 parent 4054dfa commit 51e2db3

File tree

13 files changed

+162
-117
lines changed

13 files changed

+162
-117
lines changed

changelog.d/10838.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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.

synapse/api/constants.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class EventTypes:
121121
SpaceParent = "m.space.parent"
122122

123123
MSC2716_INSERTION = "org.matrix.msc2716.insertion"
124-
MSC2716_CHUNK = "org.matrix.msc2716.chunk"
124+
MSC2716_BATCH = "org.matrix.msc2716.batch"
125125
MSC2716_MARKER = "org.matrix.msc2716.marker"
126126

127127

@@ -209,11 +209,11 @@ class EventContentFields:
209209

210210
# Used on normal messages to indicate they were historically imported after the fact
211211
MSC2716_HISTORICAL = "org.matrix.msc2716.historical"
212-
# For "insertion" events to indicate what the next chunk ID should be in
212+
# For "insertion" events to indicate what the next batch ID should be in
213213
# order to connect to it
214-
MSC2716_NEXT_CHUNK_ID = "org.matrix.msc2716.next_chunk_id"
215-
# Used on "chunk" events to indicate which insertion event it connects to
216-
MSC2716_CHUNK_ID = "org.matrix.msc2716.chunk_id"
214+
MSC2716_NEXT_BATCH_ID = "org.matrix.msc2716.next_batch_id"
215+
# Used on "batch" events to indicate which insertion event it connects to
216+
MSC2716_BATCH_ID = "org.matrix.msc2716.batch_id"
217217
# For "marker" events
218218
MSC2716_MARKER_INSERTION = "org.matrix.msc2716.marker.insertion"
219219

synapse/api/room_versions.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -244,24 +244,8 @@ class RoomVersions:
244244
msc2716_historical=False,
245245
msc2716_redactions=False,
246246
)
247-
MSC2716 = RoomVersion(
248-
"org.matrix.msc2716",
249-
RoomDisposition.UNSTABLE,
250-
EventFormatVersions.V3,
251-
StateResolutionVersions.V2,
252-
enforce_key_validity=True,
253-
special_case_aliases_auth=False,
254-
strict_canonicaljson=True,
255-
limit_notifications_power_levels=True,
256-
msc2176_redaction_rules=False,
257-
msc3083_join_rules=False,
258-
msc3375_redaction_rules=False,
259-
msc2403_knocking=True,
260-
msc2716_historical=True,
261-
msc2716_redactions=False,
262-
)
263-
MSC2716v2 = RoomVersion(
264-
"org.matrix.msc2716v2",
247+
MSC2716v3 = RoomVersion(
248+
"org.matrix.msc2716v3",
265249
RoomDisposition.UNSTABLE,
266250
EventFormatVersions.V3,
267251
StateResolutionVersions.V2,
@@ -289,9 +273,9 @@ class RoomVersions:
289273
RoomVersions.V6,
290274
RoomVersions.MSC2176,
291275
RoomVersions.V7,
292-
RoomVersions.MSC2716,
293276
RoomVersions.V8,
294277
RoomVersions.V9,
278+
RoomVersions.MSC2716v3,
295279
)
296280
}
297281

synapse/event_auth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def check(
213213

214214
if (
215215
event.type == EventTypes.MSC2716_INSERTION
216-
or event.type == EventTypes.MSC2716_CHUNK
216+
or event.type == EventTypes.MSC2716_BATCH
217217
or event.type == EventTypes.MSC2716_MARKER
218218
):
219219
check_historical(room_version_obj, event, auth_events)
@@ -552,14 +552,14 @@ def check_historical(
552552
auth_events: StateMap[EventBase],
553553
) -> None:
554554
"""Check whether the event sender is allowed to send historical related
555-
events like "insertion", "chunk", and "marker".
555+
events like "insertion", "batch", and "marker".
556556
557557
Returns:
558558
None
559559
560560
Raises:
561561
AuthError if the event sender is not allowed to send historical related events
562-
("insertion", "chunk", and "marker").
562+
("insertion", "batch", and "marker").
563563
"""
564564
# Ignore the auth checks in room versions that do not support historical
565565
# events
@@ -573,7 +573,7 @@ def check_historical(
573573
if user_level < historical_level:
574574
raise AuthError(
575575
403,
576-
'You don\'t have permission to send send historical related events ("insertion", "chunk", and "marker")',
576+
'You don\'t have permission to send send historical related events ("insertion", "batch", and "marker")',
577577
)
578578

579579

synapse/events/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ def add_fields(*fields):
141141
elif event_type == EventTypes.Redaction and room_version.msc2176_redaction_rules:
142142
add_fields("redacts")
143143
elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_INSERTION:
144-
add_fields(EventContentFields.MSC2716_NEXT_CHUNK_ID)
145-
elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_CHUNK:
146-
add_fields(EventContentFields.MSC2716_CHUNK_ID)
144+
add_fields(EventContentFields.MSC2716_NEXT_BATCH_ID)
145+
elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_BATCH:
146+
add_fields(EventContentFields.MSC2716_BATCH_ID)
147147
elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_MARKER:
148148
add_fields(EventContentFields.MSC2716_MARKER_INSERTION)
149149

synapse/handlers/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ async def persist_and_notify_client_event(
14251425
# structural protocol level).
14261426
is_msc2716_event = (
14271427
original_event.type == EventTypes.MSC2716_INSERTION
1428-
or original_event.type == EventTypes.MSC2716_CHUNK
1428+
or original_event.type == EventTypes.MSC2716_BATCH
14291429
or original_event.type == EventTypes.MSC2716_MARKER
14301430
)
14311431
if not room_version_obj.msc2716_historical and is_msc2716_event:

synapse/rest/client/room_batch.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,25 @@
4343

4444
class RoomBatchSendEventRestServlet(RestServlet):
4545
"""
46-
API endpoint which can insert a chunk of events historically back in time
46+
API endpoint which can insert a batch of events historically back in time
4747
next to the given `prev_event`.
4848
49-
`chunk_id` comes from `next_chunk_id `in the response of the batch send
50-
endpoint and is derived from the "insertion" events added to each chunk.
49+
`batch_id` comes from `next_batch_id `in the response of the batch send
50+
endpoint and is derived from the "insertion" events added to each batch.
5151
It's not required for the first batch send.
5252
5353
`state_events_at_start` is used to define the historical state events
5454
needed to auth the events like join events. These events will float
5555
outside of the normal DAG as outlier's and won't be visible in the chat
56-
history which also allows us to insert multiple chunks without having a bunch
57-
of `@mxid joined the room` noise between each chunk.
56+
history which also allows us to insert multiple batches without having a bunch
57+
of `@mxid joined the room` noise between each batch.
5858
59-
`events` is chronological chunk/list of events you want to insert.
60-
There is a reverse-chronological constraint on chunks so once you insert
59+
`events` is chronological list of events you want to insert.
60+
There is a reverse-chronological constraint on batches so once you insert
6161
some messages, you can only insert older ones after that.
62-
tldr; Insert chunks from your most recent history -> oldest history.
62+
tldr; Insert batches from your most recent history -> oldest history.
6363
64-
POST /_matrix/client/unstable/org.matrix.msc2716/rooms/<roomID>/batch_send?prev_event_id=<eventID>&chunk_id=<chunkID>
64+
POST /_matrix/client/unstable/org.matrix.msc2716/rooms/<roomID>/batch_send?prev_event_id=<eventID>&batch_id=<batchID>
6565
{
6666
"events": [ ... ],
6767
"state_events_at_start": [ ... ]
@@ -129,7 +129,7 @@ def _create_insertion_event_dict(
129129
self, sender: str, room_id: str, origin_server_ts: int
130130
) -> JsonDict:
131131
"""Creates an event dict for an "insertion" event with the proper fields
132-
and a random chunk ID.
132+
and a random batch ID.
133133
134134
Args:
135135
sender: The event author MXID
@@ -140,13 +140,13 @@ def _create_insertion_event_dict(
140140
The new event dictionary to insert.
141141
"""
142142

143-
next_chunk_id = random_string(8)
143+
next_batch_id = random_string(8)
144144
insertion_event = {
145145
"type": EventTypes.MSC2716_INSERTION,
146146
"sender": sender,
147147
"room_id": room_id,
148148
"content": {
149-
EventContentFields.MSC2716_NEXT_CHUNK_ID: next_chunk_id,
149+
EventContentFields.MSC2716_NEXT_BATCH_ID: next_batch_id,
150150
EventContentFields.MSC2716_HISTORICAL: True,
151151
},
152152
"origin_server_ts": origin_server_ts,
@@ -191,7 +191,7 @@ async def on_POST(
191191
prev_event_ids_from_query = parse_strings_from_args(
192192
request.args, "prev_event_id"
193193
)
194-
chunk_id_from_query = parse_string(request, "chunk_id")
194+
batch_id_from_query = parse_string(request, "batch_id")
195195

196196
if prev_event_ids_from_query is None:
197197
raise SynapseError(
@@ -291,27 +291,27 @@ async def on_POST(
291291
prev_event_ids_from_query
292292
)
293293

294-
# Figure out which chunk to connect to. If they passed in
295-
# chunk_id_from_query let's use it. The chunk ID passed in comes
296-
# from the chunk_id in the "insertion" event from the previous chunk.
297-
last_event_in_chunk = events_to_create[-1]
298-
chunk_id_to_connect_to = chunk_id_from_query
294+
# Figure out which batch to connect to. If they passed in
295+
# batch_id_from_query let's use it. The batch ID passed in comes
296+
# from the batch_id in the "insertion" event from the previous batch.
297+
last_event_in_batch = events_to_create[-1]
298+
batch_id_to_connect_to = batch_id_from_query
299299
base_insertion_event = None
300-
if chunk_id_from_query:
300+
if batch_id_from_query:
301301
# All but the first base insertion event should point at a fake
302302
# event, which causes the HS to ask for the state at the start of
303-
# the chunk later.
303+
# the batch later.
304304
prev_event_ids = [fake_prev_event_id]
305305

306-
# Verify the chunk_id_from_query corresponds to an actual insertion event
307-
# and have the chunk connected.
306+
# Verify the batch_id_from_query corresponds to an actual insertion event
307+
# and have the batch connected.
308308
corresponding_insertion_event_id = (
309-
await self.store.get_insertion_event_by_chunk_id(chunk_id_from_query)
309+
await self.store.get_insertion_event_by_batch_id(batch_id_from_query)
310310
)
311311
if corresponding_insertion_event_id is None:
312312
raise SynapseError(
313313
400,
314-
"No insertion event corresponds to the given ?chunk_id",
314+
"No insertion event corresponds to the given ?batch_id",
315315
errcode=Codes.INVALID_PARAM,
316316
)
317317
pass
@@ -328,7 +328,7 @@ async def on_POST(
328328
base_insertion_event_dict = self._create_insertion_event_dict(
329329
sender=requester.user.to_string(),
330330
room_id=room_id,
331-
origin_server_ts=last_event_in_chunk["origin_server_ts"],
331+
origin_server_ts=last_event_in_batch["origin_server_ts"],
332332
)
333333
base_insertion_event_dict["prev_events"] = prev_event_ids.copy()
334334

@@ -347,38 +347,38 @@ async def on_POST(
347347
depth=inherited_depth,
348348
)
349349

350-
chunk_id_to_connect_to = base_insertion_event["content"][
351-
EventContentFields.MSC2716_NEXT_CHUNK_ID
350+
batch_id_to_connect_to = base_insertion_event["content"][
351+
EventContentFields.MSC2716_NEXT_BATCH_ID
352352
]
353353

354-
# Connect this current chunk to the insertion event from the previous chunk
355-
chunk_event = {
356-
"type": EventTypes.MSC2716_CHUNK,
354+
# Connect this current batch to the insertion event from the previous batch
355+
batch_event = {
356+
"type": EventTypes.MSC2716_BATCH,
357357
"sender": requester.user.to_string(),
358358
"room_id": room_id,
359359
"content": {
360-
EventContentFields.MSC2716_CHUNK_ID: chunk_id_to_connect_to,
360+
EventContentFields.MSC2716_BATCH_ID: batch_id_to_connect_to,
361361
EventContentFields.MSC2716_HISTORICAL: True,
362362
},
363-
# Since the chunk event is put at the end of the chunk,
363+
# Since the batch event is put at the end of the batch,
364364
# where the newest-in-time event is, copy the origin_server_ts from
365365
# the last event we're inserting
366-
"origin_server_ts": last_event_in_chunk["origin_server_ts"],
366+
"origin_server_ts": last_event_in_batch["origin_server_ts"],
367367
}
368-
# Add the chunk event to the end of the chunk (newest-in-time)
369-
events_to_create.append(chunk_event)
368+
# Add the batch event to the end of the batch (newest-in-time)
369+
events_to_create.append(batch_event)
370370

371-
# Add an "insertion" event to the start of each chunk (next to the oldest-in-time
372-
# event in the chunk) so the next chunk can be connected to this one.
371+
# Add an "insertion" event to the start of each batch (next to the oldest-in-time
372+
# event in the batch) so the next batch can be connected to this one.
373373
insertion_event = self._create_insertion_event_dict(
374374
sender=requester.user.to_string(),
375375
room_id=room_id,
376-
# Since the insertion event is put at the start of the chunk,
376+
# Since the insertion event is put at the start of the batch,
377377
# where the oldest-in-time event is, copy the origin_server_ts from
378378
# the first event we're inserting
379379
origin_server_ts=events_to_create[0]["origin_server_ts"],
380380
)
381-
# Prepend the insertion event to the start of the chunk (oldest-in-time)
381+
# Prepend the insertion event to the start of the batch (oldest-in-time)
382382
events_to_create = [insertion_event] + events_to_create
383383

384384
event_ids = []
@@ -439,17 +439,17 @@ async def on_POST(
439439
)
440440

441441
insertion_event_id = event_ids[0]
442-
chunk_event_id = event_ids[-1]
442+
batch_event_id = event_ids[-1]
443443
historical_event_ids = event_ids[1:-1]
444444

445445
response_dict = {
446446
"state_event_ids": state_event_ids_at_start,
447447
"event_ids": historical_event_ids,
448-
"next_chunk_id": insertion_event["content"][
449-
EventContentFields.MSC2716_NEXT_CHUNK_ID
448+
"next_batch_id": insertion_event["content"][
449+
EventContentFields.MSC2716_NEXT_BATCH_ID
450450
],
451451
"insertion_event_id": insertion_event_id,
452-
"chunk_event_id": chunk_event_id,
452+
"batch_event_id": batch_event_id,
453453
}
454454
if base_insertion_event is not None:
455455
response_dict["base_insertion_event_id"] = base_insertion_event.event_id

synapse/storage/databases/main/event_federation.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,13 +1034,13 @@ def _get_backfill_events(self, txn, room_id, event_list, limit):
10341034
LIMIT ?
10351035
"""
10361036

1037-
# Find any chunk connections of a given insertion event
1038-
chunk_connection_query = """
1037+
# Find any batch connections of a given insertion event
1038+
batch_connection_query = """
10391039
SELECT e.depth, c.event_id FROM insertion_events AS i
1040-
/* Find the chunk that connects to the given insertion event */
1041-
INNER JOIN chunk_events AS c
1042-
ON i.next_chunk_id = c.chunk_id
1043-
/* Get the depth of the chunk start event from the events table */
1040+
/* Find the batch that connects to the given insertion event */
1041+
INNER JOIN batch_events AS c
1042+
ON i.next_batch_id = c.batch_id
1043+
/* Get the depth of the batch start event from the events table */
10441044
INNER JOIN events AS e USING (event_id)
10451045
/* Find an insertion event which matches the given event_id */
10461046
WHERE i.event_id = ?
@@ -1077,12 +1077,12 @@ def _get_backfill_events(self, txn, room_id, event_list, limit):
10771077

10781078
event_results.add(event_id)
10791079

1080-
# Try and find any potential historical chunks of message history.
1080+
# Try and find any potential historical batches of message history.
10811081
#
10821082
# First we look for an insertion event connected to the current
10831083
# event (by prev_event). If we find any, we need to go and try to
1084-
# find any chunk events connected to the insertion event (by
1085-
# chunk_id). If we find any, we'll add them to the queue and
1084+
# find any batch events connected to the insertion event (by
1085+
# batch_id). If we find any, we'll add them to the queue and
10861086
# navigate up the DAG like normal in the next iteration of the loop.
10871087
txn.execute(
10881088
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):
10971097
connected_insertion_event = row[1]
10981098
queue.put((-connected_insertion_event_depth, connected_insertion_event))
10991099

1100-
# Find any chunk connections for the given insertion event
1100+
# Find any batch connections for the given insertion event
11011101
txn.execute(
1102-
chunk_connection_query,
1102+
batch_connection_query,
11031103
(connected_insertion_event, limit - len(event_results)),
11041104
)
1105-
chunk_start_event_id_results = txn.fetchall()
1105+
batch_start_event_id_results = txn.fetchall()
11061106
logger.debug(
1107-
"_get_backfill_events: chunk_start_event_id_results %s",
1108-
chunk_start_event_id_results,
1107+
"_get_backfill_events: batch_start_event_id_results %s",
1108+
batch_start_event_id_results,
11091109
)
1110-
for row in chunk_start_event_id_results:
1110+
for row in batch_start_event_id_results:
11111111
if row[1] not in event_results:
11121112
queue.put((-row[0], row[1]))
11131113

0 commit comments

Comments
 (0)