Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Hugot committed Jan 27, 2023
1 parent bd34e24 commit 1bb76f4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 50 deletions.
8 changes: 4 additions & 4 deletions src/DurableTask.SqlServer/SqlOrchestrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ await SqlUtils.ExecuteNonQueryAsync(
IList<HistoryEvent> history;
if (await reader.NextResultAsync(cancellationToken))
{
history = await ReadHistoryEventsAsync(reader, executionIdFilter: null, cancellationToken);
history = ReadHistoryEvents(reader, executionIdFilter: null, cancellationToken);
}
else
{
Expand Down Expand Up @@ -615,17 +615,17 @@ public override async Task<string> GetOrchestrationHistoryAsync(string instanceI

using DbDataReader reader = await SqlUtils.ExecuteReaderAsync(command, this.traceHelper, instanceId);

List<HistoryEvent> history = await ReadHistoryEventsAsync(reader, executionIdFilter);
List<HistoryEvent> history = ReadHistoryEvents(reader, executionIdFilter);
return JsonConvert.SerializeObject(history);
}

static async Task<List<HistoryEvent>> ReadHistoryEventsAsync(
static List<HistoryEvent> ReadHistoryEvents(
DbDataReader reader,
string? executionIdFilter = null,
CancellationToken cancellationToken = default)
{
var history = new List<HistoryEvent>(capacity: 128);
while (!cancellationToken.IsCancellationRequested && reader.Read())
while (!cancellationToken.IsCancellationRequested && reader.Read())
{
string executionId = SqlUtils.GetExecutionId(reader)!;
HistoryEvent e = reader.GetHistoryEvent(isOrchestrationHistory: true);
Expand Down
44 changes: 0 additions & 44 deletions src/DurableTask.SqlServer/SqlUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,50 +529,6 @@ static async Task<T> WithRetry<T>(Func<Task<T>> func, SprocExecutionContext cont
}
}

static async Task<T> WithRetry<T>(Func<T> func, SprocExecutionContext context, LogHelper traceHelper, string? instanceId, int maxRetries = 5)
{
context.RetryCount = 0;

while (true)
{
try
{
return func();
}
catch (Exception e)
{
if (!IsTransient(e))
{
// Not a retriable exception
throw;
}

if (context.RetryCount >= maxRetries)
{
// Maxed out on retries. The layer above may do its own retries later.
throw;
}

// Linear backoff where we add 1 second each time, so for retryCount = 5
// we could delay as long as 0 + 1 + 2 + 3 + 4 = 10 total seconds.
TimeSpan delay = TimeSpan.FromSeconds(context.RetryCount);
lock (random)
{
// Add a small amount of random delay to distribute concurrent retries
delay += TimeSpan.FromMilliseconds(random.Next(100));
}

// Log a warning so that these issues can be properly investigated
traceHelper.TransientDatabaseFailure(e, instanceId, context.RetryCount);

await Task.Delay(delay);

context.RetryCount++;
}
}
}


static bool IsTransient(Exception exception)
{
if (exception is SqlException sqlException)
Expand Down
4 changes: 2 additions & 2 deletions test/DurableTask.SqlServer.Tests/Integration/StressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public StressTests(ITestOutputHelper output)
Task IAsyncLifetime.InitializeAsync() => this.testService.InitializeAsync();

Task IAsyncLifetime.DisposeAsync() => this.testService.DisposeAsync();
static string bigString = string.Join("", Enumerable.Range(0, 1024 * 1024 * 10).Select(x => "1"));
static readonly string BigString = string.Join("", Enumerable.Range(0, 1024 * 1024 * 10).Select(x => "1"));
// This test has previously been used to uncover various deadlock issues by stressing the code paths
// related to foreign keys that point to the Instances and Payloads tables.
// Example: https://github.com/microsoft/durabletask-mssql/issues/45
Expand Down Expand Up @@ -101,7 +101,7 @@ public async Task ParallelWithBigPayload(int subOrchestrationCount)
name: SubOrchestrationName,
version: "",
instanceId: $"suborchestration[{i}]",
input: $"{i}-{bigString}");
input: $"{i}-{BigString}");
listInstances.Add(instance);
}
Expand Down

0 comments on commit 1bb76f4

Please sign in to comment.