Repository navigation
Commit bf56d89
authored
feat(search): remove a deleted community's messages from OpenSearch (#9999)
## Summary
Deleting a community now removes its messages from the OpenSearch index.
Before this PR they stayed there, and that was the main reason real data
was kept off OpenSearch behind `BUZZ_OPENSEARCH_PREVIEW`.
The relay indexes chat messages into OpenSearch beside Postgres.
Community deletion (`buzz-admin deletions run`) walks a request through
fixed stages: it fences the community, purges Postgres, purges Redis,
then verifies that nothing is left. It never touched OpenSearch, so a
deleted community's text stayed in the index for good. Search never
showed it, because every hit is re-read from Postgres, but the words
stayed on disk.
This PR adds OpenSearch to the purge and to the final verification:
- **Before fencing (`Approved`):** the executor checks that it can reach
OpenSearch. If Postgres shows an index is maintained but
`BUZZ_OPENSEARCH_URL` is unset, the deletion stops and retries rather
than skipping the index.
- **Purge (`PostgresPurged`):** the executor pages through the
community's documents with `_search` and `search_after`, 500 at a time.
It deletes each page with a versioned `_bulk` request, taking versions
from the same `search_index_version` sequence the indexer uses. It does
not use `_delete_by_query`, which OpenSearch Serverless does not offer.
- **Verification (`CachePurged`):** the executor waits a
lease-heartbeated 90-second settle window (covering `BULK_TIMEOUT` = 60
s plus margin and Serverless write-to-searchable lag), refreshes on
clusters that support `_refresh`, and runs a second purge pass before
counting. If that pass deletes any stragglers, the stage fails
transiently and retries so zero only counts after a full quiet window.
Other changes:
- The relay and the deletion executor share
`OpenSearchConfig::parse_parts` and `OpenSearchConfig::with_aws_sigv4`
(with `OpenSearchConfig::from_env` used by `buzz-deletion`).
- The Helm `operatorJobs.deletionDrain` CronJob wires the five optional
`BUZZ_OPENSEARCH_*` Secret keys (`BUZZ_OPENSEARCH_URL`,
`BUZZ_OPENSEARCH_USERNAME`, `BUZZ_OPENSEARCH_PASSWORD`,
`BUZZ_OPENSEARCH_AWS_SIGV4_SERVICE`, `BUZZ_OPENSEARCH_AWS_REGION`) via
`optional: true` `secretKeyRef`.
- The deployment and deletion docs cover passing OpenSearch settings to
`buzz-admin deletions`, pausing indexing vs. permanently decommissioning
OpenSearch, and the residual late-write retention gap.
- `BUZZ_OPENSEARCH_PREVIEW` stays required. Its error text and doc now
name the gaps that remain: late writes and Postgres failover.
**Risk:** OpenSearch is not deployed anywhere yet and stays behind the
preview flag, so this affects no live search. A deployment that never
ran the indexer skips the OpenSearch steps. Before turning OpenSearch on
anywhere: the deletion executor needs the same OpenSearch settings (and
IAM identity when using SigV4) and mapping version as the relays, and
each deletion takes at least 90 s longer (plus 30 s + 90 s per straggler
retry, well inside the CronJob's 3600 s deadline). Rollback is the older
executor, which leaves docs in the index as before.
### Related issue
N/A. No existing issue or PR found.
### Testing
Ran locally on `5cba5c7d02` against Postgres, Redis, and OpenSearch
2.19:
- `./scripts/postgres-test-run.sh -p buzz-deletion -j 4 -E
'test(community_purge_deletes) | test(execute_stage_wires_opensearch)'`:
2 of 2 passed.
- `community_purge_deletes_and_verifies_opensearch_documents`: verifies
fail-closed when `BUZZ_OPENSEARCH_URL` is unset, purges target while
keeping bystander intact, plants a late straggler and verifies retryable
error + cleanup + clean second pass.
- `execute_stage_wires_opensearch_preflight_purge_and_verification`:
exercises `execute_stage` end-to-end across `Approved` (unreachable
OpenSearch fails closed and leaves community unfenced), `PostgresPurged`
(purges target docs and records `deleted_search_documents: 2`), and
`CachePurged` (verifies absence and records `"search_index": true`).
- `cargo clippy -p buzz-deletion --all-targets -- -D warnings` and
`cargo fmt --check`: passed.
- Helm `templates/deletion-drain-cronjob.yaml` render check and CI `lint
+ unittest + render matrix`: passed.
Not tested:
- Running against a real Amazon OpenSearch Serverless (`aoss`)
collection.
---------
Signed-off-by: Salman Mohammed <smohammed@squareup.com>1 parent 0f51a74 commit bf56d89
12 files changed
Lines changed: 1078 additions & 112 deletions
File tree
- crates
- buzz-db/src/store
- buzz-deletion
- src
- buzz-relay/src
- buzz-search/src
- deploy/charts/buzz
- templates
- tests
- docs
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
923 | 923 | | |
924 | 924 | | |
925 | 925 | | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
926 | 938 | | |
927 | 939 | | |
928 | 940 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
144 | 164 | | |
145 | 165 | | |
146 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
0 commit comments