From e0b777805126d7f62a11b86a9c09641f1b4f9bc3 Mon Sep 17 00:00:00 2001 From: Sergey Galuzo Date: Thu, 18 Apr 2024 12:50:52 -0700 Subject: [PATCH] Added abilty to disable retries --- .../Features/Storage/SqlQueueClient.cs | 2 +- .../Features/Storage/SqlRetry/ISqlRetryService.cs | 2 +- .../Features/Storage/SqlRetry/SqlCommandExtensions.cs | 4 ++-- .../Features/Storage/SqlRetry/SqlRetryService.cs | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlQueueClient.cs b/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlQueueClient.cs index 810c227bc9..7fc752f9b1 100644 --- a/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlQueueClient.cs +++ b/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlQueueClient.cs @@ -206,7 +206,7 @@ public async Task PutJobHeartbeatAsync(JobInfo jobInfo, CancellationToken cmd.Parameters.AddWithValue("@Version", jobInfo.Version); var cancelParam = new SqlParameter("@CancelRequested", SqlDbType.Bit) { Direction = ParameterDirection.Output }; cmd.Parameters.Add(cancelParam); - await cmd.ExecuteNonQueryAsync(_sqlRetryService, _logger, cancellationToken); + await cmd.ExecuteNonQueryAsync(_sqlRetryService, _logger, cancellationToken, disableRetries: true); // this should be fire and forget cancel = (bool)cancelParam.Value; } catch (Exception ex) diff --git a/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlRetry/ISqlRetryService.cs b/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlRetry/ISqlRetryService.cs index 8430bb3791..e2181dac90 100644 --- a/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlRetry/ISqlRetryService.cs +++ b/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlRetry/ISqlRetryService.cs @@ -18,7 +18,7 @@ public interface ISqlRetryService Task ExecuteSql(Func action, CancellationToken cancellationToken, bool isReadOnly = false); - Task ExecuteSql(SqlCommand sqlCommand, Func action, ILogger logger, string logMessage, CancellationToken cancellationToken, bool isReadOnly = false); + Task ExecuteSql(SqlCommand sqlCommand, Func action, ILogger logger, string logMessage, CancellationToken cancellationToken, bool isReadOnly = false, bool disableRetries = false); Task> ExecuteReaderAsync(SqlCommand sqlCommand, Func readerToResult, ILogger logger, string logMessage, CancellationToken cancellationToken, bool isReadOnly = false); } diff --git a/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlRetry/SqlCommandExtensions.cs b/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlRetry/SqlCommandExtensions.cs index fb952405a4..d39a899066 100644 --- a/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlRetry/SqlCommandExtensions.cs +++ b/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlRetry/SqlCommandExtensions.cs @@ -14,9 +14,9 @@ namespace Microsoft.Health.Fhir.SqlServer.Features.Storage { public static class SqlCommandExtensions { - public static async Task ExecuteNonQueryAsync(this SqlCommand cmd, ISqlRetryService retryService, ILogger logger, CancellationToken cancellationToken, string logMessage = null, bool isReadOnly = false) + public static async Task ExecuteNonQueryAsync(this SqlCommand cmd, ISqlRetryService retryService, ILogger logger, CancellationToken cancellationToken, string logMessage = null, bool isReadOnly = false, bool disableRetries = false) { - await retryService.ExecuteSql(cmd, async (sql, cancel) => await sql.ExecuteNonQueryAsync(cancel), logger, logMessage, cancellationToken, isReadOnly); + await retryService.ExecuteSql(cmd, async (sql, cancel) => await sql.ExecuteNonQueryAsync(cancel), logger, logMessage, cancellationToken, isReadOnly, disableRetries); } public static async Task> ExecuteReaderAsync(this SqlCommand cmd, ISqlRetryService retryService, Func readerToResult, ILogger logger, CancellationToken cancellationToken, string logMessage = null, bool isReadOnly = false) diff --git a/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlRetry/SqlRetryService.cs b/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlRetry/SqlRetryService.cs index 5957d3118d..514927982e 100644 --- a/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlRetry/SqlRetryService.cs +++ b/src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlRetry/SqlRetryService.cs @@ -248,9 +248,10 @@ public async Task ExecuteSql(FuncMessage to be logged on error. /// Cancellation token. /// "Flag indicating whether connection to read only replica can be used." + /// "Flag indicating whether retries are disabled." /// A task representing the asynchronous operation. /// When executing this method, if exception is thrown that is not retriable or if last retry fails, then same exception is thrown by this method. - public async Task ExecuteSql(SqlCommand sqlCommand, Func action, ILogger logger, string logMessage, CancellationToken cancellationToken, bool isReadOnly = false) + public async Task ExecuteSql(SqlCommand sqlCommand, Func action, ILogger logger, string logMessage, CancellationToken cancellationToken, bool isReadOnly = false, bool disableRetries = false) { EnsureArg.IsNotNull(sqlCommand, nameof(sqlCommand)); EnsureArg.IsNotNull(action, nameof(action)); @@ -283,7 +284,7 @@ public async Task ExecuteSql(SqlCommand sqlCommand, Func