Example #1
0
        /// <summary>
        /// Creates and returns a default Retry Policy for Schema based connection operations.
        /// </summary>
        /// <remarks>The RetryOccured event is wired to raise an RaiseAmbientRetryMessage message for a connection retry. </remarks>
        /// <returns>An instance of <see cref="RetryPolicy"/> class.</returns>
        internal static RetryPolicy CreateSchemaConnectionRetryPolicy(int retriesPerPhase)
        {
            RetryPolicy policy = new RetryPolicy.ExponentialDelayRetryPolicy(
                RetryPolicy.SqlAzureTemporaryErrorDetectionStrategy.Instance,
                retriesPerPhase,
                RetryPolicyDefaults.DefaultBackoffIntervalFactor,
                RetryPolicyDefaults.DefaultSchemaMinInterval,
                RetryPolicyDefaults.DefaultMaxRetryInterval);

            policy.RetryOccurred += DataConnectionFailureRetry;
            return(policy);
        }
Example #2
0
        /// <summary>
        /// Returns the default retry policy dedicated to handling retryable conditions with data transfer SQL commands.
        /// </summary>
        /// <returns>The RetryPolicy policy</returns>
        public static RetryPolicy CreateDefaultDataSqlCommandRetryPolicy()
        {
            RetryPolicy retryPolicy = new RetryPolicy.ExponentialDelayRetryPolicy(
                RetryPolicy.SqlAzureTemporaryErrorDetectionStrategy.Instance,
                RetryPolicyDefaults.DefaultDataCommandRetryCount,
                RetryPolicyDefaults.DefaultBackoffIntervalFactor,
                RetryPolicyDefaults.DefaultDataMinInterval,
                RetryPolicyDefaults.DefaultMaxRetryInterval);

            retryPolicy.FastFirstRetry = true;
            retryPolicy.RetryOccurred += CommandFailureRetry;
            return(retryPolicy);
        }
Example #3
0
        /// <summary>
        /// Returns the default retry policy dedicated to handling exceptions with SQL connections
        /// </summary>
        /// <returns>The RetryPolicy policy</returns>
        public static RetryPolicy CreateDefaultConnectionRetryPolicy()
        {
            // Note: No longer use Ado.net Connection Pooling and hence do not need TimeBasedRetryPolicy to
            // conform to the backoff requirements in this case
            RetryPolicy retryPolicy = new RetryPolicy.ExponentialDelayRetryPolicy(
                RetryPolicy.NetworkConnectivityErrorDetectionStrategy.Instance,
                RetryPolicyDefaults.DefaultConnectionRetryCount,
                RetryPolicyDefaults.DefaultBackoffIntervalFactor,
                RetryPolicyDefaults.DefaultSchemaMinInterval,
                RetryPolicyDefaults.DefaultMaxRetryInterval);

            retryPolicy.FastFirstRetry = true;
            return(retryPolicy);
        }
Example #4
0
        /// <summary>
        /// Creates and returns an "primary key violation" command Retry Policy.
        /// </summary>
        /// <param name="ignorableErrorNumbers">Errors to ignore if they occur after first retry</param>
        /// <remarks>
        /// The RetryOccured event is wired to raise an RaiseAmbientRetryMessage message for a command retry.
        /// The IgnoreErrorOccurred event is wired to raise an RaiseAmbientIgnoreMessage message for ignore.
        /// </remarks>
        /// <returns>An instance of <see cref="RetryPolicy"/> class.</returns>
        internal static RetryPolicy CreatePrimaryKeyCommandRetryPolicy()
        {
            RetryPolicy.SqlAzureTemporaryAndIgnorableErrorDetectionStrategy errorDetectionStrategy =
                new RetryPolicy.SqlAzureTemporaryAndIgnorableErrorDetectionStrategy(SqlErrorNumbers.PrimaryKeyViolationErrorNumber);

            RetryPolicy policy = new RetryPolicy.ExponentialDelayRetryPolicy(
                errorDetectionStrategy,
                RetryPolicyDefaults.DefaulSchemaRetryCount,
                RetryPolicyDefaults.DefaultBackoffIntervalFactor,
                RetryPolicyDefaults.DefaultSchemaMinInterval,
                RetryPolicyDefaults.DefaultMaxRetryInterval);

            policy.FastFirstRetry       = true;
            policy.RetryOccurred       += CommandFailureRetry;
            policy.IgnoreErrorOccurred += CommandFailureIgnore;

            return(policy);
        }
Example #5
0
        /// <summary>
        /// Creates and returns a Retry Policy for database creation operations.
        /// </summary>
        /// <param name="ignorableErrorNumbers">Errors to ignore if they occur after first retry</param>
        /// <remarks>
        /// The RetryOccured event is wired to raise an RaiseAmbientRetryMessage message for a command retry.
        /// The IgnoreErrorOccurred event is wired to raise an RaiseAmbientIgnoreMessage message for ignore.
        /// </remarks>
        /// <returns>An instance of <see cref="RetryPolicy"/> class.</returns>
        internal static RetryPolicy CreateDatabaseCommandRetryPolicy(params int[] ignorableErrorNumbers)
        {
            RetryPolicy.SqlAzureTemporaryAndIgnorableErrorDetectionStrategy errorDetectionStrategy =
                new RetryPolicy.SqlAzureTemporaryAndIgnorableErrorDetectionStrategy(ignorableErrorNumbers);

            // 30, 60, 60, 60, 60 second retries
            RetryPolicy policy = new RetryPolicy.ExponentialDelayRetryPolicy(
                errorDetectionStrategy,
                RetryPolicyDefaults.DefaultCreateDatabaseRetryCount /* maxRetryCount */,
                RetryPolicyDefaults.DefaultBackoffIntervalFactor,
                TimeSpan.FromSeconds(30) /* minInterval */,
                TimeSpan.FromSeconds(60) /* maxInterval */);

            policy.FastFirstRetry       = false;
            policy.RetryOccurred       += CreateDatabaseCommandFailureRetry;
            policy.IgnoreErrorOccurred += CreateDatabaseCommandFailureIgnore;

            return(policy);
        }
Example #6
0
        /// <summary>
        /// Creates and returns an "ignoreable" command Retry Policy.
        /// </summary>
        /// <param name="ignorableErrorNumbers">Errors to ignore if they occur after first retry</param>
        /// <remarks>
        /// The RetryOccured event is wired to raise an RaiseAmbientRetryMessage message for a command retry.
        /// The IgnoreErrorOccurred event is wired to raise an RaiseAmbientIgnoreMessage message for ignore.
        /// </remarks>
        /// <returns>An instance of <see cref="RetryPolicy"/> class.</returns>
        internal static RetryPolicy CreateElementCommandRetryPolicy(params int[] ignorableErrorNumbers)
        {
            Debug.Assert(ignorableErrorNumbers != null);

            RetryPolicy.SqlAzureTemporaryAndIgnorableErrorDetectionStrategy errorDetectionStrategy =
                new RetryPolicy.SqlAzureTemporaryAndIgnorableErrorDetectionStrategy(ignorableErrorNumbers);

            RetryPolicy policy = new RetryPolicy.ExponentialDelayRetryPolicy(
                errorDetectionStrategy,
                RetryPolicyDefaults.DefaulSchemaRetryCount,
                RetryPolicyDefaults.DefaultBackoffIntervalFactor,
                RetryPolicyDefaults.DefaultSchemaMinInterval,
                RetryPolicyDefaults.DefaultMaxRetryInterval);

            policy.FastFirstRetry       = false;
            policy.RetryOccurred       += ElementCommandFailureRetry;
            policy.IgnoreErrorOccurred += ElementCommandFailureIgnore;

            return(policy);
        }
Example #7
0
        /// <summary>
        /// Creates and returns a default Retry Policy for Schema based operations.
        /// </summary>
        /// <returns>An instance of <see cref="RetryPolicy"/> class.</returns>
        internal static RetryPolicy CreateDefaultSchemaCommandRetryPolicy(bool useRetry, int retriesPerPhase = RetryPolicyDefaults.DefaulSchemaRetryCount)
        {
            RetryPolicy policy;

            if (useRetry)
            {
                policy = new RetryPolicy.ExponentialDelayRetryPolicy(
                    RetryPolicy.SqlAzureTemporaryErrorDetectionStrategy.Instance,
                    retriesPerPhase,
                    RetryPolicyDefaults.DefaultBackoffIntervalFactor,
                    RetryPolicyDefaults.DefaultSchemaMinInterval,
                    RetryPolicyDefaults.DefaultMaxRetryInterval);
                policy.FastFirstRetry = false;
            }
            else
            {
                policy = CreateNoRetryPolicy();
            }

            return(policy);
        }