Skip to content

WPB-29583: migrate user client index store to PostGreSQL - #5648

Open
blackheaven wants to merge 4 commits into
gdifolco/WPB-29574-migration-postgres-client-storefrom
gdifolco/WPB-29583-migration-postgres-user-client-index
Open

blackheaven wants to merge 4 commits into
gdifolco/WPB-29574-migration-postgres-client-storefrom
gdifolco/WPB-29583-migration-postgres-user-client-index

Conversation

@blackheaven

@blackheaven blackheaven commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

https://wearezeta.atlassian.net/browse/WPB-29583

Stacked on #5647 (WPB-29574, client store) — both surface the same clients data; merge order enforced by the base branch.

Checklist

  • Add a new entry in an appropriate subdirectory of changelog.d
  • Read and follow the PR guidelines

@blackheaven
blackheaven requested review from a team as code owners October 23, 2026 13:28
@zebot zebot added the ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist label Oct 23, 2026
@blackheaven
blackheaven added this pull request to stack #5650 October 23, 2026 13:35
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch from c4107c7 to a78a8d5 Compare October 29, 2026 11:07
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch from a78a8d5 to 3d515e9 Compare October 29, 2026 18:36
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch from 3d515e9 to 3b8b9e9 Compare November 4, 2026 13:15
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch from 3b8b9e9 to 31ce7c6 Compare November 5, 2026 13:28
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch from 31ce7c6 to 57be34e Compare November 10, 2026 08:40
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch from 57be34e to 1ac3dd2 Compare November 13, 2026 11:54
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch from 1ac3dd2 to b8138dc Compare November 16, 2026 19:56
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch from b8138dc to 9ced570 Compare November 17, 2026 14:07
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch 2 times, most recently from 870d4b0 to f28fbe5 Compare November 27, 2026 23:04
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch from f28fbe5 to 3b9953c Compare November 30, 2026 09:01
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch from 3b9953c to ef4afe7 Compare December 2, 2026 10:16
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch from ef4afe7 to b7010c0 Compare December 3, 2026 09:02

@battermann battermann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, can we think about merging brig and galleys client tables in postgres?

- Read galley/background-worker UserClientIndexStore directly from brig's shared PostgreSQL clients table instead of adding a separate user_client_index table or userClientIndex config key.
- Keep CreateClient, DeleteClient, and DeleteClients as no-ops on PostgreSQL (brig owns all writes to clients, and DeleteClients must not delete rows before brig removes prekeys).
- Add ShouldRemoveClient to UserClientIndexStore (checks Cassandra index for early-exit; returns True on PostgreSQL so async MLS cleanup in rmClient still runs after brig deletes the client row) and add Wire.ConversationSubsystem.ClientsSpec.
- Reject postgresMigration.clients: migration-to-postgresql at startup in galley (validateOptions) and background-worker (mkEnv), and fail loudly in both interpreter switches.
- Update config-options.md, hack/helm_vars/common.yaml.gotmpl comment, and add changelog entry.
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29583-migration-postgres-user-client-index branch from b7010c0 to 9cc16ec Compare December 3, 2026 21:07
@blackheaven

Copy link
Copy Markdown
Contributor Author

Done — reworked #5648 to read galley/background-worker's UserClientIndexStore directly from brig's shared PostgreSQL clients table under postgresMigration.clients (no user_client_index table or userClientIndex flag). Writes are no-ops since brig owns clients, and ShouldRemoveClient preserves Cassandra's early-exit while still running MLS cleanup on PostgreSQL.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A moderate active finding remains because the new PostgreSQL interpreter and its SQL/result grouping lack tests for key cases such as multiple users, duplicate IDs, and users with no rows.

1 open issue
What changed in this PR

Migrates Galley and background-worker user client index reads to Brig’s shared PostgreSQL clients table while preserving Cassandra behavior.

Changes:

  • Adds PostgreSQL support and runtime backend selection.
  • Updates cleanup handling, validation, tests, documentation, Helm configuration, and changelog.
File Description
services/​galley/​src/​Galley/​App.hs Selects the configured user client index backend.
services/​background-worker/​src/​Wire/​Effects.hs Wires the configured PostgreSQL or Cassandra client index interpreter.
services/​background-worker/​src/​Wire/​BackgroundWorker/​Env.hs Validates supported client migration settings.
libs/​wire-subsystems/​wire-subsystems.cabal Registers the new client index module and tests.
libs/​wire-subsystems/​test/​unit/​Wire/​ConversationSubsystem/​ClientsSpec.hs Tests client-removal behavior and migration validation.
libs/​wire-subsystems/​src/​Wire/​UserClientIndexStore/​Postgres.hs Implements PostgreSQL client index queries.
libs/​wire-subsystems/​src/​Wire/​UserClientIndexStore/​Cassandra.hs Adds Cassandra client removal checks.
libs/​wire-subsystems/​src/​Wire/​UserClientIndexStore.hs Extends the client index effect API with removal checks.
libs/​wire-subsystems/​src/​Wire/​ConversationSubsystem/​Clients.hs Uses the client index removal-check operation.
hack/​helm_vars/​common.yaml.gotmpl Configures supported client migration behavior.
docs/​src/​developer/​reference/​config-options.md Documents PostgreSQL client store configuration and behavior.
changelog.d/​5-internal/​WPB-29583-migration-postgres-user-client-index Records the PostgreSQL user client index migration.

Review effort: Lite

Comment on lines +50 to +57
GetClients uids
| null uids -> pure (Clients.fromList [])
| otherwise -> do
rows <- V.toList <$> runStatement uids selectClientIdsBulkStatement
pure . Clients.fromUserClients . UserClients $
Map.fromListWith
Set.union
([(u, Set.empty) | u <- uids] <> [(u, Set.singleton c) | (u, c) <- rows])

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical active issue removes the PostgreSQL deletion idempotency guard, allowing retried events to enqueue duplicate removals and potentially delete conversations for a recreated client.

2 open issues

Review effort: Lite

CreateClient _ _ -> pure ()
DeleteClient _ _ -> pure ()
DeleteClients _ -> pure ()
ShouldRemoveClient _ _ -> pure True

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

easy-to-review ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants