Пример #1
0
        /// <summary>
        /// Checks if the exception is either a Cassandra response error or a socket exception to retry or failover if necessary.
        /// </summary>
        private void HandleException(Exception ex)
        {
            Logger.Info("RequestHandler received exception {0}", ex.ToString());
            if (ex is PreparedQueryNotFoundException && (_parent.Statement is BoundStatement || _parent.Statement is BatchStatement))
            {
                PrepareAndRetry(((PreparedQueryNotFoundException)ex).UnknownId);
                return;
            }
            if (ex is NoHostAvailableException)
            {
                //A NoHostAvailableException when trying to retrieve
                _parent.SetNoMoreHosts((NoHostAvailableException)ex, this);
                return;
            }
            var c = _connection;

            if (c != null)
            {
                _triedHosts[c.Address] = ex;
            }
            if (ex is OperationTimedOutException)
            {
                OnTimeout(ex);
                return;
            }
            if (ex is SocketException)
            {
                Logger.Verbose("Socket error " + ((SocketException)ex).SocketErrorCode);
            }
            var decision = GetRetryDecision(ex, _parent.RetryPolicy, _parent.Statement, _retryCount);

            switch (decision.DecisionType)
            {
            case RetryDecision.RetryDecisionType.Rethrow:
                _parent.SetCompleted(ex);
                break;

            case RetryDecision.RetryDecisionType.Ignore:
                //The error was ignored by the RetryPolicy
                //Try to give a decent response
                if (typeof(T).GetTypeInfo().IsAssignableFrom(typeof(RowSet)))
                {
                    var rs = new RowSet();
                    _parent.SetCompleted(null, FillRowSet(rs, null));
                }
                else
                {
                    _parent.SetCompleted(null, default(T));
                }
                break;

            case RetryDecision.RetryDecisionType.Retry:
                //Retry the Request using the new consistency level
                Retry(decision.RetryConsistencyLevel, decision.UseCurrentHost);
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// Checks if the exception is either a Cassandra response error or a socket exception to retry or failover if necessary.
        /// </summary>
        private void HandleException(Exception ex)
        {
            Logger.Info("RequestHandler received exception {0}", ex.ToString());
            if (ex is PreparedQueryNotFoundException &&
                (_parent.Statement is BoundStatement || _parent.Statement is BatchStatement))
            {
                PrepareAndRetry(((PreparedQueryNotFoundException)ex).UnknownId);
                return;
            }
            if (ex is NoHostAvailableException)
            {
                //A NoHostAvailableException when trying to retrieve
                _parent.SetNoMoreHosts((NoHostAvailableException)ex, this);
                return;
            }
            var c = _connection;

            if (c != null)
            {
                _triedHosts[c.Address] = ex;
            }
            if (ex is OperationTimedOutException)
            {
                Logger.Warning(ex.Message);
                var connection = _connection;
                if (connection == null)
                {
                    Logger.Error("Host and Connection must not be null");
                }
                else
                {
                    // Checks how many timed out operations are in the connection
                    ((Session)_session).CheckHealth(connection);
                }
            }
            var decision = GetRetryDecision(
                ex, _parent.RetryPolicy, _parent.Statement, _session.Cluster.Configuration, _retryCount);

            switch (decision.DecisionType)
            {
            case RetryDecision.RetryDecisionType.Rethrow:
                _parent.SetCompleted(ex);
                break;

            case RetryDecision.RetryDecisionType.Ignore:
                // The error was ignored by the RetryPolicy, return an empty rowset
                _parent.SetCompleted(null, FillRowSet(RowSet.Empty(), null));
                break;

            case RetryDecision.RetryDecisionType.Retry:
                //Retry the Request using the new consistency level
                Retry(decision.RetryConsistencyLevel, decision.UseCurrentHost);
                break;
            }
        }