-
Notifications
You must be signed in to change notification settings - Fork 581
Atomic Search Param operations #5433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jestradaMS
wants to merge
89
commits into
main
Choose a base branch
from
users/jestrada/atomicsearchparameteroperations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 67 commits
Commits
Show all changes
89 commits
Select commit
Hold shift + click to select a range
acdf1c6
feat: Update schema to version 104 and enhance MergeSearchParams stor…
jestradaMS a76ad96
Merge branch 'main' into users/jestrada/atomicsearchparameteroperations
jestradaMS b9e1733
fixing 104.sql
jestradaMS efc97f3
Enhance reindexing and search parameter operations with retry policie…
jestradaMS ce3d1af
Refactor search parameter operations to consolidate validation logic …
jestradaMS 5d806a2
fixing appsettings that should not have been checked in
jestradaMS ef9b530
fixing white space after comment
jestradaMS 35cd84b
Implement pending search parameter status handling in bundle operatio…
jestradaMS 0d7ca29
Refactor transaction handling in MergeSearchParams to improve concurr…
jestradaMS 64fef20
Clarify comments regarding pending search parameter status handling i…
jestradaMS 3ba9312
Update ADR 2602 to implement atomic SearchParameter CRUD operations, …
jestradaMS fd27c7b
Update schema version to 108 and adjust related constants and conditions
jestradaMS 318591e
ADR 2602: Atomic SearchParameter CRUD Operations
jestradaMS d994a32
Add ADR 2603: Atomic SearchParameter CRUD Operations and Cache Refres…
jestradaMS ea6c08f
Remove ADR 2602: Atomic SearchParameter CRUD Operations document
jestradaMS 59e0acb
Merge branch 'main' into users/jestrada/atomicsearchparameteradr
jestradaMS 0a24ed5
Merge branch 'main' into users/jestrada/atomicsearchparameteroperations
jestradaMS 9b74e37
Update schema versioning to V107
jestradaMS 67bef92
Adding OR ALTER to migration diff file.
jestradaMS 04aa622
Remove redundant search parameter update calls in reindex handlers an…
jestradaMS 999ac0c
Merge branch 'users/jestrada/atomicsearchparameteradr' into users/jes…
jestradaMS c5fe031
removing old 2602 adr for atomic search parameters
jestradaMS f1e5520
adding test for ensuring cache is not mutated when status manager is …
jestradaMS c9957c7
removing 107 files
jestradaMS 7f912b9
Merge branch 'main' into users/jestrada/atomicsearchparameteroperations
jestradaMS 5784146
Bump schema version to 108
jestradaMS b14f3cd
Implement search parameter operations to handle reindexing conflicts …
jestradaMS b00ce93
Refactor GetSearchParametersByUrls method to simplify URL resolution …
jestradaMS be7f304
Improve URL resolution logic from GetSearchParameterByUrls method
jestradaMS 47cc2ac
Fixing SP State update handler tests
jestradaMS 09a1c10
Fixing tests
jestradaMS 7cae0ad
adding logging to reindex failures
jestradaMS 5d83f96
adding Sergey's test for 500 serach parameters
jestradaMS a9239b7
Refactor reindex job to batch update disabled and deleted search para…
jestradaMS 213164c
Updating new test for large custom search params
jestradaMS 82245bb
Refactor ReindexTests to support dynamic search parameter handling an…
jestradaMS d0daa62
skipping flaky test to test run again
jestradaMS ade3cfe
updating to use output in ReindexTests opposed to System Diag
jestradaMS 2734794
Updates per Sergey's comments
jestradaMS 46df45c
removing test
jestradaMS 899dc01
fixing MergeResourcesWrapperAsync
jestradaMS cd0d5c9
testing increased retries for reliability of tests
jestradaMS c4c8bb8
Removing old stored proc per feedback on PR
jestradaMS 8dda219
Enhance search parameter operations with cache refresh cycle handling
jestradaMS a3290ea
Add ADR 2603 to address reindex cache race conditions and improve not…
jestradaMS 58f9b6f
Fixing integration tests
jestradaMS 0f5145b
adding timeout to ensure we don't hang if reresh never signals.
jestradaMS 00d7275
Disposal update in integration tests
jestradaMS 459adee
Ensure proper disposal of timer in SearchParameterCacheRefreshBackgro…
jestradaMS dddee07
fixing refreshtimer disoposal
jestradaMS baedead
fixing tests
jestradaMS 4d97074
Refactor Search Parameter Cache Refresh Logic and Enhance Cache Consi…
jestradaMS 224b41f
Fixing style cop issue
jestradaMS 192e009
Fixing signals to ensure they log even if no changes.
jestradaMS 9b6402c
Testing with LegacyInitializeSearchParameterStatuses
jestradaMS 0f2d317
comment out code
jestradaMS 92e7c98
updating convergence logic in operations
jestradaMS a076be6
trailing space :(
jestradaMS 7583792
adding logging to cache consistency check
jestradaMS 2e31e83
fixing casting in proc
jestradaMS c47c185
fix white space diff
jestradaMS 6d442cc
Changing convergence check time to 30 second delay
jestradaMS 95ddad7
Enhance cache consistency checks with sync timestamps and active host…
jestradaMS 9ad7a76
Refactor cache update logic to ensure accurate timestamp logging and …
jestradaMS 01ea4db
Reducing logging only when there is an active waiter
jestradaMS da818c1
Update syncStartDate to align with active host detection for cache co…
jestradaMS c2033df
Adding back blind wait for Cosmos
jestradaMS a1e6977
Fix: Update resource type check to remove unnecessary whitespace cond…
jestradaMS 218172b
removing 108 on this branch to merge in from main
jestradaMS aebd351
Merge branch 'main' into users/jestrada/atomicsearchparameteroperations
jestradaMS 42a1235
updated to schema 109 post main merge
jestradaMS dd30efc
Refactor transaction handling in MergeSearchParams to simplify rollba…
jestradaMS 2db0796
Distributed search param cache sync (#5485)
SergeyGaluzo fe33165
Merge branch 'main' into users/jestrada/atomicsearchparameteroperations
jestradaMS 489a9f9
Remove redundant search parameter conflict tests from ReindexTests
jestradaMS 8fe83b7
Merge branch 'main' into users/jestrada/atomicsearchparameteroperations
jestradaMS 491d06d
Add missing dependency for IScoped<IFhirOperationDataStore> in search…
jestradaMS 82cb42d
Merge branch 'main' into users/jestrada/atomicsearchparameteroperations
jestradaMS 5bff060
Merge branch 'main' into users/jestrada/atomicsearchparameteroperations
jestradaMS 39eabb4
Add TaskHosting__MaxRunningTaskCount parameter to deployment configur…
jestradaMS 598b004
Refactor bulk delete operations to improve search parameter handling …
jestradaMS b8611eb
Add search service dependency to BulkDeleteControllerTests for improv…
jestradaMS a6ec8d9
Implement ambient bundle SQL transaction context and integrate into b…
jestradaMS fa70e04
Merge branch 'main' into users/jestrada/atomicsearchparameteroperations
jestradaMS a0baeaf
Add BundleSqlTransactionContext and mock scope provider to SqlServerF…
jestradaMS 6869356
adding back GetAndApplySearchParameterUpdates to ReindexSingleResourc…
jestradaMS 385b094
Add flag to track presence of SearchParameter resources in bundles
jestradaMS 23cdcda
Skip processing in DrainPendingSearchParameterStatuses if no SearchPa…
jestradaMS 4c8bbfa
Remove BundleSqlTransactionContext and related interfaces from the co…
jestradaMS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
docs/arch/adr-2603-atomic-searchparameter-crud-and-cache-refresh-ownership.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # ADR 2603: Atomic SearchParameter CRUD Operations | ||
| Labels: [SQL](https://github.com/microsoft/fhir-server/labels/Area-SQL) | [Core](https://github.com/microsoft/fhir-server/labels/Area-Core) | [SearchParameter](https://github.com/microsoft/fhir-server/labels/Area-SearchParameter) | ||
|
|
||
| ## Context | ||
| SearchParameter create, update, and delete operations require two coordinated writes: the SearchParameter status row (`dbo.SearchParam` table) and the resource itself (`dbo.Resource` via `dbo.MergeResources`). Previously, these writes occurred in separate steps in the request pipeline, creating partial-failure windows where one could succeed while the other fails — producing orphaned or inconsistent state. | ||
|
|
||
| Composing these writes into a single atomic SQL operation introduced a new problem for transaction bundles: `dbo.MergeSearchParams` acquires an exclusive lock on `dbo.SearchParam` per entry, and that lock is held by the outer bundle transaction. When the next entry's behavior pipeline calls `GetAllSearchParameterStatus` on a separate connection, it blocks on the same table, causing a timeout. This required a deferred-flush approach for transaction bundles. | ||
|
|
||
| Additionally, SearchParameter CRUD behaviors previously performed direct in-memory cache mutations (`AddNewSearchParameters`, `DeleteSearchParameter`, etc.) during the request pipeline. This duplicated responsibility with the `SearchParameterCacheRefreshBackgroundService`, which already polls the database and applies cache updates across all instances. | ||
|
|
||
| Key considerations: | ||
| - Eliminating partial-commit windows between status and resource persistence. | ||
| - Handling the lock contention on `dbo.SearchParam` introduced by composed writes in transaction bundles. | ||
| - Simplifying cache ownership by removing direct cache mutations from the CRUD request path. | ||
| - Preserving existing behavior for non-SearchParameter resources and Cosmos DB paths. | ||
|
|
||
| ## Decision | ||
| We implement three complementary changes: | ||
|
|
||
| ### 1. Composed writes for single operations (SQL) | ||
| For individual SearchParameter CRUD, behaviors queue pending status updates in request context (`SearchParameter.PendingStatusUpdates`) instead of persisting directly. `SqlServerFhirDataStore` detects pending statuses and calls `dbo.MergeSearchParams` (which internally calls `dbo.MergeResources`) so both writes execute in one stored-procedure-owned transaction. | ||
|
|
||
| ### 2. Deferred flush for transaction bundles | ||
| For transaction bundles, per-entry resource upserts call `dbo.MergeResources` only (no SearchParam table touch), avoiding the exclusive lock. `BundleHandler` accumulates pending statuses across all entries and flushes them in a single `dbo.MergeSearchParams` call at the end of the bundle, still within the outer transaction scope. | ||
|
|
||
| ```mermaid | ||
| graph TD; | ||
| A[SearchParameter Operation] -->|Single operation| B[Behavior queues pending status in request context]; | ||
| B --> C[SqlServerFhirDataStore calls MergeSearchParams]; | ||
| C --> D[MergeSearchParams: status + MergeResources in one transaction]; | ||
| A -->|Transaction bundle| E[Per-entry: Behavior queues status, UpsertAsync calls MergeResources only]; | ||
| E --> F[BundleHandler drains pending statuses after each entry]; | ||
| F --> G[After all entries: single MergeSearchParams flush within outer transaction]; | ||
| G --> H[Transaction commits atomically]; | ||
| ``` | ||
|
|
||
| ### 3. Cache update removal from CRUD path | ||
| SearchParameter CRUD behaviors no longer perform direct in-memory cache mutations. All cache updates (`AddNewSearchParameters`, `DeleteSearchParameter`, `UpdateSearchParameterStatus`) are now solely owned by the `SearchParameterCacheRefreshBackgroundService`, which periodically polls the database via `GetAndApplySearchParameterUpdates`. This simplifies the CRUD path and ensures consistent cache convergence across distributed instances. | ||
|
|
||
| ### Scope | ||
| - **SQL Server**: Full atomic guarantees for create, update, and delete of SearchParameter resources, both single and in transaction bundles. | ||
| - **Cosmos DB**: Pending statuses are flushed after resource upsert (improved sequencing, not a single transactional unit). | ||
| - **Unchanged**: Non-SearchParameter CRUD, existing SearchParameter status lifecycle states, cache convergence model. | ||
|
|
||
| ## Status | ||
| Pending acceptance | ||
|
|
||
| ## Consequences | ||
| - **Positive Impacts:** | ||
| - Eliminates orphaned status/resource records from partial commits. | ||
| - Clarifies ownership: behaviors queue intent, data stores persist atomically, background service owns cache. | ||
| - Deferred-flush approach avoids lock contention introduced by composed writes in transaction bundles. | ||
| - Removing cache mutations from CRUD simplifies the request path and eliminates a class of cache-divergence bugs. | ||
|
|
||
| - **Potential Drawbacks:** | ||
| - Increased complexity in request context, data store, and bundle handler coordination. | ||
| - SQL schema migration required (`MergeSearchParams` expanded to accept resource TVPs). | ||
| - Eventual consistency window: cache may lag behind database until the next background refresh cycle. | ||
| - Cosmos DB path remains best-effort sequencing rather than true atomic commit. | ||
|
|
||
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.