Repository navigation
fix(persistence): bound the searches one chained search may issue - #3321
Open
angela-helios wants to merge 2 commits into
Open
angela-helios wants to merge 2 commits into
angela-helios wants to merge 2 commits into
Conversation
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
This branch has not been deployed
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.
Closes #3203
Behaviour change to review
A chained search is now refused with
422when its reference hops together would need more than 400 backend searches. For a typed one-hop chain such asObservation?subject:Patient.gender=femalethat is a terminal match of more than 100,000 resources; until now the only limit was the 300,000-id ceiling of #2949. Multi-hop chains and untyped hops with several candidate parent types share the same 400 and reach it sooner. Bulk export_typeFilterresolution goes through the same resolver and is refused the same way.The number 400 is a judgement, not a measurement: the issue asks for timings of a 300,000-reference hop on SQLite and PostgreSQL first, and those were not taken. Please confirm or change the value.
Summary
The chain resolver searches each hop's references 250 at a time, once per candidate parent type. #2949 bounded the ids a hop may hold, but not the searches it issues: a 300,000-reference hop is 1,200 searches per parent type, run in sequence by one request.
This adds a search budget per chained parameter in
crates/persistence/src/search/chain_resolver.rs:MAX_CHAIN_FAN_OUT = 400searches, shared by every hop and candidate parent type of one chained parameter.ceil(references / 250) * parent types) is taken from the budget. A hop that does not fit is refused before any of its searches runs, with the existingTooManyResultserror (422), carrying the hop's width and the widest hop the remaining budget allowed._has(existing_ids) chunks the same way and spends from the same budget.Not in this change: no deadline is checked between chunk searches, a wide hop is still resolved by several
ORsearches rather than one statement, the budget is per chained parameter rather than per request, and the_haspath (#3201) is untouched.Tests
New unit tests in
chain_resolver.rs:fan_out_budget_counts_one_search_per_chunk_and_type: the cost arithmetic, and that a refused hop takes nothing from the budget.fan_out_default_budget_is_below_what_the_id_ceiling_allows: the default admits 100,000 references through one type and refuses 300,000.a_hop_needing_more_searches_than_the_fan_out_ceiling_is_refused: 600 references (three chunks) on SQLite are refused with a ceiling of 2 and resolve with 3.the_fan_out_ceiling_is_shared_by_the_hops_of_a_chain: a two-hop chain needing 2 + 2 searches is refused with a ceiling of 3 and resolves with 4.Results:
cargo test -p helios-persistence --lib: 2087 passed.These ran on a branch that also carried thirteen other pending fixes, so the suites were verified in combination, not on this branch alone. That branch also compiled with the
postgres,mongodb,s3andelasticsearchfeatures.