Example #1
0
        private Task <ElasticsearchResponse <T> > FinishOrRetryRequestAsync <T>(TransportRequestState <T> requestState)
        {
            var rq = requestState.InitiateRequest(RequestType.ElasticsearchCall);

            return(CallIntoConnectionAsync(requestState)
                   .ContinueWith(t => HandleStreamResponse(t, rq, requestState))
                   .Unwrap());
        }
Example #2
0
        private Task <ElasticsearchResponse <T> > FinishOrRetryRequestAsync <T>(TransportRequestState <T> requestState)
        {
            var rq = requestState.InitiateRequest(RequestType.ElasticsearchCall);

            return(CallIntoConnectionAsync(requestState)
                   .ContinueWith(t =>
            {
                var retried = requestState.Retried;
                if (t.IsCanceled)
                {
                    return null;
                }
                var maxRetries = this.GetMaximumRetries(requestState.RequestConfiguration);
                if (t.IsFaulted)
                {
                    rq.Dispose();
                    if (maxRetries == 0 && retried == 0)
                    {
                        throw t.Exception;
                    }
                    requestState.SeenExceptions.Add(t.Exception);
                    return this.RetryRequestAsync <T>(requestState);
                }

                if (t.Result.SuccessOrKnownError ||
                    (
                        maxRetries == 0 && retried == 0 && !SniffOnFaultDiscoveredMoreNodes(requestState, retried, t.Result))
                    )
                {
                    rq.Finish(t.Result.Success, t.Result.HttpStatusCode);
                    rq.Dispose();
                    var error = ThrowOrGetErrorFromStreamResponse(requestState, t.Result);
                    return this.StreamToTypedResponseAsync <T>(t.Result, requestState)
                    .ContinueWith(tt =>
                    {
                        this.SetErrorDiagnosticsAndPatchSuccess(requestState, error, tt.Result, t.Result);


                        if (tt.Result.SuccessOrKnownError)
                        {
                            this._connectionPool.MarkAlive(requestState.CurrentNode);
                        }
                        return tt;
                    }).Unwrap();
                }
                if (t.Result != null)
                {
                    rq.Finish(t.Result.Success, t.Result.HttpStatusCode);
                }
                rq.Dispose();
                return this.RetryRequestAsync <T>(requestState);
            }).Unwrap());
        }
Example #3
0
        private ElasticsearchResponse <Stream> DoElasticsearchCall <T>(TransportRequestState <T> requestState)
        {
            // Do the actual request by calling into IConnection
            // We wrap it in a IRequestTimings to audit the request
            ElasticsearchResponse <Stream> streamResponse;

            using (var requestAudit = requestState.InitiateRequest(RequestType.ElasticsearchCall))
            {
                streamResponse = this.CallInToConnection(requestState);
                requestAudit.Finish(streamResponse.Success, streamResponse.HttpStatusCode);
            }
            return(streamResponse);
        }
Example #4
0
        private OrientdbResponse <Stream> DoOrientdbCall <T>(TransportRequestState <T> requestState)
        {
            // Do the actual request by calling into IConnection
            // We wrap it in a IRequestTimings to audit the request
            OrientdbResponse <Stream> streamResponse;

            using (IRequestTimings requestAudit = requestState.InitiateRequest(RequestType.OrientdbCall))
            {
                streamResponse = CallInToConnection(requestState);
                requestAudit.Finish(streamResponse.Success, streamResponse.HttpStatusCode);
            }
            return(streamResponse);
        }
Example #5
0
        private ElasticsearchResponse <T> DoRequest <T>(TransportRequestState <T> requestState)
        {
            var retried = requestState.Retried;

            this.SniffIfInformationIsTooOld(requestState);

            var aliveResponse = false;

            var nodeRequiresPinging = this.SelectNextNode(requestState);

            var seenError  = false;
            var maxRetries = this.GetMaximumRetries(requestState.RequestConfiguration);

            try
            {
                if (nodeRequiresPinging)
                {
                    var pingSuccess = this.Ping(requestState);
                    if (!pingSuccess)
                    {
                        return(RetryRequest <T>(requestState));
                    }
                }

                ElasticsearchResponse <Stream> streamResponse;
                using (var rq = requestState.InitiateRequest(RequestType.ElasticsearchCall))
                {
                    streamResponse = this.CallInToConnection(requestState);
                    rq.Finish(streamResponse.Success, streamResponse.HttpStatusCode);
                }

                if (streamResponse.SuccessOrKnownError ||
                    (
                        maxRetries == 0 && retried == 0 && !SniffOnFaultDiscoveredMoreNodes(requestState, retried, streamResponse))
                    )
                {
                    var error = ThrowOrGetErrorFromStreamResponse(requestState, streamResponse);

                    var typedResponse = this.StreamToTypedResponse <T>(streamResponse, requestState);
                    this.SetErrorDiagnosticsAndPatchSuccess(requestState, error, typedResponse, streamResponse);
                    aliveResponse = typedResponse.SuccessOrKnownError;
                    return(typedResponse);
                }
            }
            catch (MaxRetryException)
            {
                throw;
            }
            catch (ElasticsearchServerException)
            {
                throw;
            }
            catch (Exception e)
            {
                requestState.SeenExceptions.Add(e);
                if (maxRetries == 0 && retried == 0)
                {
                    if (_throwMaxRetry)
                    {
                        new MaxRetryException(e);
                    }
                    else
                    {
                        throw;
                    }
                }
                seenError = true;
                return(RetryRequest <T>(requestState));
            }
            finally
            {
                //make sure we always call markalive on the uri if the connection was succesful
                if (!seenError && aliveResponse)
                {
                    this._connectionPool.MarkAlive(requestState.CurrentNode);
                }
            }
            return(RetryRequest <T>(requestState));
        }