Skip to content

WPB-28665: add PostGreSQL support for query user search - #5539

Open
blackheaven wants to merge 11 commits into
developfrom
gdifolco/WPB-28655-migrate-user-search-postgresql
Open

blackheaven wants to merge 11 commits into
developfrom
gdifolco/WPB-28655-migrate-user-search-postgresql

Conversation

@blackheaven

@blackheaven blackheaven commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

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

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 September 11, 2026 17:47
@zebot zebot added the ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist label Sep 11, 2026
@blackheaven blackheaven changed the title feat(brig): remove ElasticSearch; query user search from Postgres WPB-28665: remove ElasticSearch; query user search from Postgres Sep 11, 2026

@fisx fisx 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.

This would be awesome, but the ticket doesn't really say anything about re-architecting anything? Also, shouldn't we do some load testing before we merge this? Or maybe after, before the next release?

@blackheaven

Copy link
Copy Markdown
Contributor Author

@fisx as discussed during the meeting this morning, we are not ready yet for load testing, instead, we should support both for a little while, I'll rework my PR in this direction.

@blackheaven
blackheaven force-pushed the gdifolco/WPB-28655-migrate-user-search-postgresql branch from e2fa56a to 7cd6d34 Compare September 24, 2026 14:38
@blackheaven
blackheaven requested a review from fisx September 24, 2026 14:41
@blackheaven
blackheaven force-pushed the gdifolco/WPB-28655-migrate-user-search-postgresql branch from 7cd6d34 to 6e7477f Compare September 24, 2026 15:08
@blackheaven blackheaven changed the title WPB-28665: remove ElasticSearch; query user search from Postgres WPB-28665: add PostGreSQL support for query user search Sep 25, 2026
@blackheaven
blackheaven force-pushed the gdifolco/WPB-28655-migrate-user-search-postgresql branch 3 times, most recently from 82189a8 to 260c1f1 Compare November 5, 2026 13:19
@blackheaven
blackheaven force-pushed the gdifolco/WPB-28655-migrate-user-search-postgresql branch from 260c1f1 to dbb0ef2 Compare November 10, 2026 09:24
@blackheaven

Copy link
Copy Markdown
Contributor Author

Fair points on both counts — thanks @fisx.

Re-architecture: agreed, the ticket doesn't call for one, and this PR isn't one — it's a straight ES→Postgres backend swap behind searchBackend: postgres, keeping the same UserSearchStore effect surface. (The one structural addition is the name_normalized column + one-off backfill that the SQL search predicate needs.) If the ticket/PR description reads otherwise anywhere, we'll tighten the wording.

Load testing: yes — explicitly planned after merge, before the next release that turns searchBackend: postgres on for real traffic. Concretely: run the existing brig search load scenarios against a staging backend with searchBackend: postgres and compare p50/p95/p99 against the ES baseline (in particular the %tok% LIKE fallback path and the unbounded role/SAML sort paths are the known seq-scan suspects), and gate the config flip on those numbers. The default remains elasticsearch until that gate passes.

Meanwhile, in dbb0ef2: the keyset pagination null-cursor restart bug is fixed (branch on the null flag before decoding, so NULL sort values no longer restart pages), the name_normalized backfill is batched (UPDATE … FROM unnest per page), and brig now fails fast at startup if searchBackend: postgres is configured while the user store is still on Cassandra.

…fault, Postgres optional)

Rebased onto develop; restores the ElasticSearch stack removed by the original PR. Keeps the UserSearchStore effect with its Postgres interpreter and adds a thin ElasticSearch adapter delegating to IndexedUserStore, so all search reads (local search, team browse, team size, search-visibility) go through one interface. In Postgres mode the ES index write path is neutralized via a no-op IndexedUserStore interpreter; brig's Postgres user store now maintains wire_user.name_normalized on insert/update. brig-index regains the ES tooling plus a new backfill-normalized-names subcommand. ES backend is deprecated; migration steps documented.
CREATE INDEX CONCURRENTLY cannot run inside a transaction; the migration runner only exempts scripts listed in nonTransactionMigrations. Move the three index statements to their own script registered there, keeping the transactional DDL (ALTER TABLE wire_user, CREATE TABLE team_search_visibility) in the original file. Fixes the brig/galley PostgresMigrationUsageError crashloop in the integration environment.
Hasql.Session.script sends a whole script as one simple-query message, and Postgres runs multiple statements of one message in a single implicit transaction - so a script containing several CREATE INDEX CONCURRENTLY statements still fails with SQLSTATE 25001 even on the non-transactional path. Split the user-search index migration into three single-statement scripts, all registered in nonTransactionMigrations.
…fast on search/user-store mismatch

- keysetPredicate: branch on the cursor null-flag BEFORE decoding the sort
  value. A cursor for a row whose sort value was NULL stores a
  non-decodable placeholder; decoding it made the predicate Nothing and
  silently RESTARTED the next page from the beginning (duplicate rows).
  Null-flagged cursors now continue within the NULL-valued block by id
  alone; the dead 'or (col is null and false and ...)' arm is gone.
- runBackfillNormalizedNames: one batched UPDATE ... FROM unnest per page
  instead of one UPDATE per row.
- newEnv: reject searchBackend=postgres with the user store still on
  Cassandra at startup instead of a lazy error in the CanonicalInterpreter
  chain that surfaced only on the first search.
@blackheaven
blackheaven force-pushed the gdifolco/WPB-28655-migrate-user-search-postgresql branch from dbb0ef2 to 83f7781 Compare November 13, 2026 11:17

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

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