@@ -31,10 +31,18 @@ public virtual async Task WriteAsync(Database sourceDb, Database targetDb, Kusto
3131 }
3232 }
3333
34+ /// <summary>
35+ /// Iteratively generates and applies changes to the primary database until it stops making forward progress.
36+ /// </summary>
37+ /// <param name="sourceDb"></param>
38+ /// <param name="targetDb"></param>
39+ /// <param name="client"></param>
40+ /// <param name="logger"></param>
41+ /// <returns></returns>
3442 internal virtual async Task < List < ScriptExecuteCommandResult > > UpdatePrimary ( Database sourceDb , Database targetDb , KustoClient client , ILogger logger )
3543 {
3644 // Some changes will be dependent upon each other, causing a race condition when attempting to apply them.
37- // As long as the write made some forward progress, keep looping until it stalls .
45+ // As long as the write made some forward progress, keep looping until there are no more successes .
3846 logger . LogInformation ( $ "Updating primary database { targetDb . Name } ") ;
3947 var keepGoing = false ;
4048 var iterationCount = 0 ;
@@ -56,17 +64,19 @@ internal virtual async Task<List<ScriptExecuteCommandResult>> UpdatePrimary(Data
5664 keepGoing = successes . Count < results . Count && successes . Count > 0 ;
5765 if ( ! keepGoing )
5866 {
59- // add remaining results to the list.
67+ // if we're stopping, add remaining (failure) results to the list.
6068 allResults . AddRange ( results ) ;
6169 }
6270 } while ( keepGoing ) ;
6371
6472 // Final status
65- Console . WriteLine ( $ "Successfully applied { allResults . Count ( r => r . Result != "Failed" ) } out of { allResults . Count } changes to { targetDb . Name } ") ;
73+ Console . WriteLine ( "---------------------------------------------------------------------------" ) ;
74+ Console . WriteLine ( $ "Database update complete: Successfully applied { allResults . Count ( r => r . Result != "Failed" ) } out of { allResults . Count } changes to { targetDb . Name } after { iterationCount } iterations.") ;
6675 foreach ( var result in allResults )
6776 {
6877 Console . WriteLine ( $ "{ result . CommandType } ({ result . OperationId } ): { result . Result } => { result . Reason } ({ result . CommandText } )") ;
6978 }
79+ Console . WriteLine ( "---------------------------------------------------------------------------" ) ;
7080
7181 return allResults ;
7282 }
@@ -161,7 +171,7 @@ internal virtual async Task<List<ScriptExecuteCommandResult>> ApplyChangesToData
161171 return results ;
162172 }
163173
164- internal virtual async Task < ScriptExecuteCommandResult > ExecuteAsyncCommand ( string databaseName , KustoClient client , ILogger logger , DatabaseScriptContainer sc )
174+ private static async Task < ScriptExecuteCommandResult > ExecuteAsyncCommand ( string databaseName , KustoClient client , ILogger logger , DatabaseScriptContainer sc )
165175 {
166176 var interval = TimeSpan . FromSeconds ( 5 ) ;
167177 var iterations = ( int ) ( TimeSpan . FromHours ( 1 ) / interval ) ;
@@ -193,11 +203,13 @@ internal virtual async Task<ScriptExecuteCommandResult> ExecuteAsyncCommand(stri
193203 throw new Exception ( "Operation did not complete in a reasonable time" ) ;
194204 }
195205
196- internal virtual async Task < List < ScriptExecuteCommandResult > > ExecutePendingSync (
206+ /// <summary>
207+ /// This function will build a single .execute script with(ContinueOnErrors = true) using all the scripts provided.
208+ /// Execute script is defined here: https://learn.microsoft.com/en-us/kusto/management/execute-database-script?view=azure-data-explorer
209+ /// </summary>
210+ private static async Task < List < ScriptExecuteCommandResult > > ExecutePendingSync (
197211 string databaseName , KustoClient client , ILogger logger , List < DatabaseScriptContainer > scripts )
198212 {
199- // this function will build a single .execute script from all the small scripts provided.
200- // Execute script is defined here: https://learn.microsoft.com/en-us/kusto/management/execute-database-script?view=azure-data-explorer
201213 if ( scripts . Count == 0 )
202214 {
203215 return [ ] ;
@@ -215,8 +227,7 @@ internal virtual async Task<List<ScriptExecuteCommandResult>> ExecutePendingSync
215227 logger . LogDebug ( $ "Script content:\n { script } ") ;
216228
217229 var result = await client . AdminClient . ExecuteControlCommandAsync ( databaseName , script ) ;
218- var resultsList = result . As < ScriptExecuteCommandResult > ( ) ;
219- return resultsList ;
230+ return result . As < ScriptExecuteCommandResult > ( ) ;
220231 }
221232 }
222233}
0 commit comments