in src/TriggersBinding/MySqlTriggerListener.cs [241:273]
private async Task<long> CreateSchemaAsync(MySqlConnection connection, MySqlTransaction transaction, CancellationToken cancellationToken)
{
string createSchemaQuery = $@"CREATE DATABASE IF NOT EXISTS {SchemaName};";
using (var createSchemaCommand = new MySqlCommand(createSchemaQuery, connection, transaction))
{
var stopwatch = Stopwatch.StartNew();
try
{
await createSchemaCommand.ExecuteNonQueryAsyncWithLogging(this._logger, cancellationToken);
}
catch (Exception ex)
{
// TelemetryInstance.TrackException(TelemetryErrorName.CreateSchema, ex, this._telemetryProps);
var mysqlEx = ex as MySqlException;
if (mysqlEx?.Number == 1007) // https://mysqlconnector.net/api/mysqlconnector/mysqlerrorcodetype/
{
// This generally shouldn't happen since we check for its existence in the statement but occasionally
// a race condition can make it so that multiple instances will try and create the schema at once.
// In that case we can just ignore the error since all we care about is that the schema exists at all.
this._logger.LogWarning($"Failed to create schema '{SchemaName}'. Exception message: {ex.Message} This is informational only, function startup will continue as normal.");
}
else
{
this._logger.LogError($"Exception encountered while creating schema for global state table and leases tables. Message: {ex.Message}");
throw;
}
}
return stopwatch.ElapsedMilliseconds;
}
}