Skip to content

Conversation

jestradaMS
Copy link
Contributor

@jestradaMS jestradaMS commented Aug 15, 2025

Description

Resolves critical race conditions in SearchParameter operations that occurred when multiple concurrent requests attempted to create, update, or delete the same SearchParameter resource simultaneously. This implementation introduces a robust two-layer concurrency control strategy combining application-level pessimistic locking with database-level optimistic concurrency.

Related issues

Addresses race condition issues where concurrent SearchParameter updates would fail unpredictably, particularly in high-load environments with multiple FHIR server instances.

AB#164155

Testing

Describe how this change was tested.

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
  • Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
  • Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
  • When changing or adding behavior, if your code modifies the system design or changes design assumptions, please create and include an ADR.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Feature - New concurrency management capabilities with backward compatibility

…eter

Implemented Datastore level optimistic concurrency for Search Parameter
@jestradaMS jestradaMS requested a review from a team as a code owner August 15, 2025 18:08
@jestradaMS jestradaMS added Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Schema Version backward compatible Bug-Reliability Reliability related bugs. New Feature Label for a new feature in FHIR OSS labels Aug 15, 2025
@jestradaMS jestradaMS added Enhancement Enhancement on existing functionality. and removed New Feature Label for a new feature in FHIR OSS labels Aug 18, 2025
@jestradaMS jestradaMS added this to the CY25Q3/2Wk08 milestone Aug 20, 2025
@jestradaMS jestradaMS removed the Enhancement Enhancement on existing functionality. label Aug 20, 2025
/// <summary>
/// Exception thrown when an optimistic concurrency conflict occurs during search parameter updates.
/// </summary>
public class SearchParameterConcurrencyException : Exception
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this exception used anywhere? I don't see any references to it in this PR.

var tableValuedParameter = new SqlParameter
{
ParameterName = "searchParamStatuses",
SqlDbType = SqlDbType.Structured,
Value = collection,
Direction = ParameterDirection.Input,
TypeName = "dbo.SearchParamTableType_2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be the problem with backwards compatibility. The old code will pass in a type that the new stored procedure isn't expecting as an input.

@@ -353,11 +354,6 @@ object IServiceProvider.GetService(Type serviceType)
return _testHelper;
}

if (serviceType.IsInstanceOfType(this))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this? It doesn't look useful at all, but I'm curious why it caught your attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Bug-Reliability Reliability related bugs. Schema Version backward compatible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants