Repository navigation
Start a client in more than 32,767 rooms, by matching its rooms as one array (CHOO-3667) - #1238
Closed
abeldantas wants to merge 2 commits into
Closed
abeldantas wants to merge 2 commits into
abeldantas wants to merge 2 commits into
Conversation
…e array (CHOO-3667) The reads a client makes as it starts receiving (its memberships, the rooms' heads, its stored cursors) matched the rooms with one bind parameter each, and Postgres refuses more than 32,767. Switch's own client is in every room of its workspace, archived ones included, so past that many its reader failed at start, was retried as a transient error, and failed again, re-adopting rooms one at a time in between. A load test environment reached it with 41,461 rooms, and that process sat at 56% CPU while idle. The three reads now bind the rooms as one text array (db/id_lists.any_of).
abeldantas
requested review from
agent-runner353,
amaudruz,
christian-mcdermott,
lbangalosbt,
massimo-sandboxaq,
niall-sandboxaq,
petr-sandbox,
raullopez-sandbox and
simonflk-sb
as code owners
October 31, 2026 18:46
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The implementation updates all affected room-list queries to use PostgreSQL array matching and includes regression coverage for 40,000 room IDs, with no remaining active review issues indicated.
No open issues 🎉
What changed in this PR
This PR fixes client startup for workspaces with more than 32,767 rooms by binding room IDs as a single PostgreSQL array instead of individual parameters.
Changes:
- Adds the reusable
db.id_lists.any_ofarray-matching helper. - Updates membership, message-head, and delivery-cursor queries to use array matching.
- Adds regression coverage for 40,000 room IDs.
- Documents the fix in the changelog.
| File | Change | Review note |
|---|---|---|
core/tests/switch_core/db/stores/test_long_room_lists.py |
Adds regression coverage for large room lists. | The cursor assertion should verify the expected room-to-cursor mapping rather than allowing an empty result. |
core/switch_core/db/stores/room_store.py |
Uses array matching for client room memberships. | — |
core/switch_core/db/stores/message_store.py |
Uses array matching for room-head lookup. | — |
core/switch_core/db/stores/delivery_cursor_store.py |
Uses array matching for stored delivery cursors. | — |
core/switch_core/db/id_lists.py |
Adds the PostgreSQL ANY array predicate helper. |
— |
CHANGELOG.md |
Documents the startup failure fix. | — |
This pull request requires changes.
Review effort: Lite
Collaborator
Author
|
Combined into #1307 with the other scaling PRs. |
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.
When a client starts reading its rooms, three reads (its memberships, the rooms' heads, its stored cursors) matched the rooms with one bind parameter each, and Postgres refuses a statement with more than 32,767. Switch's own client is in every room of its workspace, archived ones included, so in a workspace past that many rooms its reader failed at start, was retried as a transient error, and failed again for as long as the process ran, taking up rooms one at a time in between. A load-test environment reached it with 41,461 rooms, and the process holding that reader sat at 56% CPU while idle.
In this PR we bind the rooms as one array in those three reads (
db/id_lists.any_of).