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