Skip to content

Commit 2809f6c

Browse files
committed
$import can handle merge throttling
1 parent e6c01a9 commit 2809f6c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,14 @@ internal async Task<IReadOnlyList<string>> ImportResourcesAsync(IReadOnlyList<Im
436436
catch (Exception e)
437437
{
438438
var sqlEx = (e is SqlException ? e : e.InnerException) as SqlException;
439+
if (sqlEx != null && sqlEx.Number == SqlStoreErrorCodes.MergeResourcesConcurrentCallsIsAboveOptimal)
440+
{
441+
var delayMs = RandomNumberGenerator.GetInt32(1000, 5000);
442+
_logger.LogWarning(e, $"Throttling detected on {nameof(ImportResourcesInternalAsync)}, backing off for {{DelayMs}}ms resources={{Resources}}", delayMs, resources.Count);
443+
await Task.Delay(delayMs, cancellationToken);
444+
continue;
445+
}
446+
439447
if (sqlEx != null && sqlEx.Number == SqlErrorCodes.Conflict && retries++ < maxRetries)
440448
{
441449
_logger.LogWarning(e, $"Error on {nameof(ImportResourcesInternalAsync)} retries={{Retries}} resources={{Resources}}", retries, resources.Count);

0 commit comments

Comments
 (0)