Skip to content

Commit

Permalink
Merge branch 'release/v6.3' of https://github.com/zealofzebras/AzureS…
Browse files Browse the repository at this point in the history
…torageTable into release/v6.3
  • Loading branch information
petero-dk committed Jan 12, 2024
2 parents 66155c7 + 855ffc0 commit c0fd698
Showing 1 changed file with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,34 @@ public static async Task<Response<IReadOnlyList<Response>>> SubmitTransactionWit
// check the exception
if (allowAutoCreate && ex.ErrorCode.Equals("TableNotFound"))
{
// try to create the table
await tc.CreateAsync();

// This is a double check pattern to ensure that two independent processes
// who are trying to create the table in parallel do not end up in an unhandled
// situation.
try
{
// try to create the table
await tc.CreateAsync();
}
catch (TableTransactionFailedException doubleCheckEx)
{
// check if we have an errorCode if not the system throws the exception
// to the caller
if (String.IsNullOrEmpty(doubleCheckEx.ErrorCode))
{
ExceptionDispatchInfo.Capture(ex).Throw();
return null;
}

// Every error except the TableAlreadyExists is thrown to the caller but
// in the case the system is trying to create the table in parallel we
// ignore the error and execute the transaction!
if (!doubleCheckEx.ErrorCode.Equals("TableAlreadyExists"))
{
ExceptionDispatchInfo.Capture(ex).Throw();
return null;
}
}

// retry
return await tc.SubmitTransactionAsync(transactionActions, cancellationToken);
Expand Down

0 comments on commit c0fd698

Please sign in to comment.