File tree Expand file tree Collapse file tree 1 file changed +28
-2
lines changed
CoreHelpers.WindowsAzure.Storage.Table/Extensions Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -49,8 +49,34 @@ public static async Task<Response<IReadOnlyList<Response>>> SubmitTransactionWit
49
49
// check the exception
50
50
if ( allowAutoCreate && ex . ErrorCode . Equals ( "TableNotFound" ) )
51
51
{
52
- // try to create the table
53
- await tc . CreateAsync ( ) ;
52
+
53
+ // This is a double check pattern to ensure that two independent processes
54
+ // who are trying to create the table in parallel do not end up in an unhandled
55
+ // situation.
56
+ try
57
+ {
58
+ // try to create the table
59
+ await tc . CreateAsync ( ) ;
60
+ }
61
+ catch ( TableTransactionFailedException doubleCheckEx )
62
+ {
63
+ // check if we have an errorCode if not the system throws the exception
64
+ // to the caller
65
+ if ( String . IsNullOrEmpty ( doubleCheckEx . ErrorCode ) )
66
+ {
67
+ ExceptionDispatchInfo . Capture ( ex ) . Throw ( ) ;
68
+ return null ;
69
+ }
70
+
71
+ // Every error except the TableAlreadyExists is thrown to the caller but
72
+ // in the case the system is trying to create the table in parallel we
73
+ // ignore the error and execute the transaction!
74
+ if ( ! doubleCheckEx . ErrorCode . Equals ( "TableAlreadyExists" ) )
75
+ {
76
+ ExceptionDispatchInfo . Capture ( ex ) . Throw ( ) ;
77
+ return null ;
78
+ }
79
+ }
54
80
55
81
// retry
56
82
return await tc . SubmitTransactionAsync ( transactionActions , cancellationToken ) ;
You can’t perform that action at this time.
0 commit comments