Consider disabling conditional interactions when remote indexing is enabled #3817
Description
Describe the bug
When remote (async) indexing is enabled, the server accepts and stores resources in a transaction prior to writing the corresponding search parameters.
This speeds up ingestion at the cost of data consistency.
Specifically, there is a window of time between data ingestion and the storing of search parameters such that a resource may exist but not be searchable.
The specification [loosely] defines a fully asynchronous mechanism for ingestion, but unless I'm mistaken it doesn't even mention the possibility servers being "eventually consistent" in this manner wrt search.
Therefor it should be considered experimental at this time.
Relatedly, the specification defines (and we implement) a flavor of the normal REST interactions that is based on FHIR search and may assume data consistency.
The LinuxForHealth FHIR server (and most others') implementation for these interactions already cannot provide guarantees on uniqueness when multiple requests are processed in parallel (#2051).
However, when remote indexing is enabled, this issue is exacerbated by this additional window of time between 'ingested' and 'searchable'.
Environment
main
To Reproduce
Steps to reproduce the behavior:
- configure the server for remote indexing but do not run the remote indexing agent
- POST a resource with an identifier value of "xyz123"
- perform a conditional create (e.g. POST with If-None-Exist: identifier=xyz123)
Expected behavior
In an ideal implementation, it would be strongly consistent and the conditional create would not succeed.
However, since we've traded that consistency away, it would be nice if we either prevent this from happening or at least provide a warning in the response.
Additional context
In the case of an update, when remote indexing is enabled, I believe the current implementation removes the existing search parameters and they are not added back until the remote indexing is completed for this resource.
An alternative we considered is leaving the stale search parameters around. However, unless we make a major change to the way those are stored, that would result in certain searches retrieving the new version of the resource when it should not (i.e. version 1 of the resource matched the query, but version 2 does not and yet we return it anyway).