Allocate device list stream IDs per batch - #20151
Draft
sandhose wants to merge 1 commit into
Draft
Conversation
`add_device_change_to_streams` chunks `device_ids` into batches of 1000, but the transaction allocated `len(device_ids)` stream IDs on every batch instead of `len(batch_device_ids)`. Both `_add_device_change_to_stream_txn` and `_add_device_outbound_room_poke_txn` zip the IDs against the batch they were handed, so the surplus was silently discarded. For a user with N devices this allocated N * ceil(N / 1000) IDs to write N rows, so the `device_lists` stream ID space advanced quadratically in the number of devices a user has. Accounts holding ~1.1M devices burned over a billion IDs per change, pushing the stream head far enough ahead that readers could not catch up -- the catch-up path in `get_all_device_list_changes_for_remotes` fetches 100 rows at a time and advances only as far as the last row's stream ID.
sandhose
force-pushed
the
quenting/device-list-stream-ids-per-batch
branch
from
August 26, 2026 13:41
cf87187 to
ddc00d7
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
add_device_change_to_streamschunksdevice_idsinto batches of 1000, but allocatedlen(device_ids)stream IDs for every batch instead oflen(batch_device_ids). Both_add_device_change_to_stream_txnand_add_device_outbound_room_poke_txnzip the IDs against the batch they were handed, so the surplus was silently discarded.This was particularly a problem when deleting devices on m.org on accounts with >1M devices, as every batch would allocate millions of stream IDs, making it impossible for consumers to ever catch up. This fix is currently deployed on m.org