private void Retry(AerospikeException ae)
        {
            // Prepare for retry.
            if (!PrepareRetry(ae.Result != ResultCode.SERVER_NOT_AVAILABLE))
            {
                // Batch may be retried in separate commands.
                if (RetryBatch())
                {
                    // Batch was retried in separate commands.  Complete this command.
                    return;
                }
            }

            AsyncCommand command = CloneCommand();

            if (command != null)
            {
                if (policy.totalTimeout > 0)
                {
                    AsyncTimeoutQueue.Instance.Add(command, policy.totalTimeout);
                }
                else if (policy.socketTimeout > 0)
                {
                    command.watch = Stopwatch.StartNew();
                    AsyncTimeoutQueue.Instance.Add(command, policy.socketTimeout);
                }
                command.ExecuteCommand();
            }
            else
            {
                FailCommand(ae);
            }
        }
        private bool RetryOnInit()
        {
            if (iterations < policy.maxRetries && (policy.retryOnTimeout || watch == null || watch.ElapsedMilliseconds < policy.timeout))
            {
                int status = Interlocked.CompareExchange(ref state, RETRY, IN_PROGRESS);

                if (status == IN_PROGRESS)
                {
                    // Prepare for retry.
                    AsyncCommand command = CloneCommand();

                    if (command != null)
                    {
                        CloseConnection();

                        if (policy.timeout > 0)
                        {
                            if (policy.retryOnTimeout)
                            {
                                command.watch = Stopwatch.StartNew();
                            }
                            else
                            {
                                command.watch = this.watch;
                            }
                            AsyncTimeoutQueue.Instance.Add(command, policy.timeout);
                        }
                        command.ExecuteCommand();
                        return(true);
                    }
                    else
                    {
                        CloseOnError();
                        return(false);
                    }
                }
                else
                {
                    AlreadyCompleted(status);
                    return(true);
                }
            }
            else
            {
                int status = Interlocked.CompareExchange(ref state, FAIL_NETWORK_INIT, IN_PROGRESS);

                if (status == IN_PROGRESS)
                {
                    CloseOnError();
                    return(false);
                }
                else
                {
                    AlreadyCompleted(status);
                    return(true);
                }
            }
        }
        private void Retry(AerospikeException ae)
        {
            // Prepare for retry.
            if (!PrepareRetry(ae.Result != ResultCode.SERVER_NOT_AVAILABLE))
            {
                try
                {
                    // Batch may be retried in separate commands.
                    if (RetryBatch())
                    {
                        // Batch was retried in separate commands.  Complete this command.
                        return;
                    }
                }
                catch (Exception e)
                {
                    NotifyFailure(new AerospikeException("Batch split retry failed", e));
                    return;
                }
            }

            AsyncCommand command = CloneCommand();

            if (command != null)
            {
                // Command should only be added to AsyncTimeoutQueue once.
                // CheckTimeout() will verify both socketTimeout and totalTimeout.
                if (socketTimeout > 0)
                {
                    command.socketWatch = Stopwatch.StartNew();
                    AsyncTimeoutQueue.Instance.Add(command, socketTimeout);
                }
                else if (totalTimeout > 0)
                {
                    int remain = (int)(totalTimeout - totalWatch.ElapsedMilliseconds);
                    AsyncTimeoutQueue.Instance.Add(command, remain);
                }
                command.ExecuteCommand();
            }
            else
            {
                FailCommand(ae);
            }
        }
Пример #4
0
        protected internal virtual void Retry(AerospikeException ae)
        {
            // Prepare for retry.
            AsyncCommand command = CloneCommand();

            if (command != null)
            {
                if (policy.totalTimeout > 0)
                {
                    AsyncTimeoutQueue.Instance.Add(command, policy.totalTimeout);
                }
                else if (policy.socketTimeout > 0)
                {
                    command.watch = Stopwatch.StartNew();
                    AsyncTimeoutQueue.Instance.Add(command, policy.socketTimeout);
                }
                command.ExecuteCommand();
            }
            else
            {
                FailCommand(ae);
            }
        }
        private void Retry(AerospikeException ae)
        {
            // Prepare for retry.
            AsyncCommand command = CloneCommand();

            if (command != null)
            {
                if (policy.totalTimeout > 0)
                {
                    AsyncTimeoutQueue.Instance.Add(command, policy.totalTimeout);
                }
                else if (policy.socketTimeout > 0)
                {
                    command.watch = Stopwatch.StartNew();
                    AsyncTimeoutQueue.Instance.Add(command, policy.socketTimeout);
                }
                command.ExecuteCommand();
            }
            else
            {
                PutBackArgsOnError();
                NotifyFailure(ae);
            }
        }
        private void RetryAfterInit(AerospikeException ae)
        {
            if (iterations < policy.maxRetries && (policy.retryOnTimeout || watch == null || watch.ElapsedMilliseconds < policy.timeout))
            {
                int status = Interlocked.CompareExchange(ref state, RETRY, IN_PROGRESS);

                if (status == IN_PROGRESS)
                {
                    // Prepare for retry.
                    AsyncCommand command = CloneCommand();

                    if (command != null)
                    {
                        CloseConnection();

                        if (policy.timeout > 0)
                        {
                            if (policy.retryOnTimeout)
                            {
                                command.watch = Stopwatch.StartNew();
                            }
                            else
                            {
                                command.watch = this.watch;
                            }
                            AsyncTimeoutQueue.Instance.Add(command, policy.timeout);
                        }

                        try
                        {
                            command.ExecuteCommand();
                        }
                        catch (Exception)
                        {
                            // Command has already been cleaned up.
                            // Notify user of original exception.
                            OnFailure(ae);
                        }
                    }
                    else
                    {
                        CloseOnError();
                        OnFailure(ae);
                    }
                }
                else
                {
                    AlreadyCompleted(status);
                }
            }
            else
            {
                int status = Interlocked.CompareExchange(ref state, FAIL_NETWORK_ERROR, IN_PROGRESS);

                if (status == IN_PROGRESS)
                {
                    CloseOnError();
                    OnFailure(ae);
                }
                else
                {
                    AlreadyCompleted(status);
                }
            }
        }