Exemplo n.º 1
0
        private long BulkLoadData(ITableDefinition tableDefinition, string fileName)
        {
            for (var i = 0; i < 30; i++)
            {
                var bulkCopy = _dbContext.PowerPlant.CreateFastCopy();
                if (BatchSize > 0)
                {
                    bulkCopy.BatchSize = BatchSize;
                }
                try
                {
                    using (var reader = ADataReaderFactory.CreateInstance(fileName, tableDefinition, bulkCopy.LargeBlobSize))
                    {
                        return(bulkCopy.LoadData(reader, fileName, tableDefinition));
                    }
                }
                catch (Exception ex)
                {
                    if (_dbContext.DbType == DbTypeName.SqlServer && ADatabaseException.ShouldThrottle(ex))
                    {
                        _logger.Write($"Throttling down when load table {tableDefinition.Name}, round {i}");
                        _logger.Write("Error causing throttle:");
                        _logger.Write(ex);
                        Thread.Sleep(10000 + i * i * i * 1000);
                    }
                    else
                    {
                        _logger.Write($"ERROR when load table {tableDefinition.Name}, round {i}");
                        throw;
                    }
                }
            }

            throw new ADatabaseException("Failed throttling down when loading " + tableDefinition.Name);
        }
Exemplo n.º 2
0
        public static T Execute <T>(IDbContext dbContext, string sql, Func <InternalSqlServerCommand, T> func)
        {
            for (int i = 0; i < _maxTries; i++)
            {
                try
                {
                    return(InternalSqlServerConnection.ExecuteInConnectionScope(dbContext, sql, func));
                }
                catch (Exception ex)
                {
                    if (ADatabaseException.ShouldThrottle(ex))
                    {
                        dbContext.Logger.Write(string.Format("Throttling down \"{0}...\", round {1}", sql.Substring(0, Math.Min(sql.Length, 40)), i));
                        Thread.Sleep(10000 + i * i * i * 1000);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(InternalSqlServerConnection.ExecuteInConnectionScope(dbContext, sql, func));
        }