Skip to content

fix(persistence): bound the paged _has hop by its references, not its sources - #3334

Open
angela-helios wants to merge 2 commits into
mainfrom
fix/3201-has-paged-source-read
Open

angela-helios wants to merge 2 commits into
mainfrom
fix/3201-has-paged-source-read

Conversation

@angela-helios

Copy link
Copy Markdown
Contributor

Closes #3201

Stacked on #3321 (#3203): both change the chain resolver. This branch contains that PR's commit; review the last commit here, or merge #3321 first.

Behaviour change to review

  • On a backend that resolves _has by paging through the source resources (PostgreSQL outside its native shape, S3), a _has search is no longer refused with 422 once more than 100,000 source resources match. It is refused when those sources refer to more than 300,000 distinct resources, the ceiling SQLite, Elasticsearch and MongoDB already apply.
  • A search that used to fail fast at 100,000 sources now runs to the end. Its memory is bounded, its duration is not: it still issues one search per 1,000 source resources. Bounding that work is search: one chained search can issue thousands of backend searches (1,200 per parent type for a 300,000-reference hop) #3203.
  • The 422 of a too-wide paged hop reports the number of distinct references, not of source resources.

Summary

The paged _has path of the chain resolver collected every matching source resource, bodies included, and only then read one reference parameter from each. #2949 capped that at 100,000 resources, which refused ordinary searches (Patient?_has:Observation:subject:status=final on a tenant with more than 100,000 final Observations) and still allowed a large allocation per request.

  • search_all_pages is replaced by HopPages, which hands over one page at a time with the same paging rules (cursor first, offset fallback, errors on an empty page with more results and on a repeated cursor).
  • resolve_reverse_chain_references extracts the references of each page and drops the page before reading the next, so it holds at most one page (1,000 resources) of bodies.
  • It keeps the distinct references seen and applies the hop's id ceiling (MAX_HOP_IDS, 300,000) to them, counting what search_reference_values would return, so the paged path is refused at the same point and with the same count as the indexed one.
  • MAX_HOP_RESOURCES is removed.
  • The paged path now yields each referenced id once instead of once per source resource.

Not in this change: search_reference_values for PostgreSQL from its reference index, which the issue suggests as the better fix for that backend.

Tests

Results:

  • cargo test -p helios-persistence --lib search::: 657 passed, including the four new _has tests and the fan-out tests of fix(persistence): bound the searches one chained search may issue #3321.
  • cargo test -p helios-rest --test search_integration: RESULT.
  • PostgreSQL and S3 are the backends the issue names; the change was run on SQLite only. I did not run clippy locally; CI runs it.

These ran on this branch, which is stacked on #3321.

The chain resolver searches a hop's references 250 at a time, once per
candidate parent type, so a hop at the 300,000-id ceiling ran 1,200
searches per type. Each chained parameter now has a budget of 400 such
searches across all its hops and parent types; a hop that does not fit
is refused with 422 before any of its searches runs. The liveness check
of a forward chain ending in _has spends from the same budget.

Closes #3203
… sources

The paged `_has` path of the chain resolver collected every matching
source resource before reading one reference from each, and refused the
search past 100,000 of them. It now extracts the references page by page,
drops each page, and applies the hop's id ceiling to the distinct
references kept, as the reference-index read does. MAX_HOP_RESOURCES is
removed.

Closes #3201

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

search: the paged _has path holds every source resource body, so PostgreSQL and S3 refuse _has past 100,000 matches

2 participants