Esempio n. 1
0
        private async Task <BulkAllResponse> HandleBulkRequest(IList <T> buffer, long page, int backOffRetries, BulkResponse response)
        {
            var clientException = response.ApiCall.OriginalException as TransportException;
            var failureReason   = clientException?.FailureReason;
            var reason          = failureReason?.GetStringValue() ?? nameof(PipelineFailure.BadRequest);

            switch (failureReason)
            {
            case PipelineFailure.MaxRetriesReached:
                if (response.ApiCall.AuditTrail.Last().Event == AuditEvent.FailedOverAllNodes)
                {
                    throw ThrowOnBadBulk(response, $"{nameof(BulkAll)} halted after attempted bulk failed over all the active nodes");
                }

                ThrowOnExhaustedRetries();
                return(await RetryDocuments(page, ++backOffRetries, buffer).ConfigureAwait(false));

            case PipelineFailure.CouldNotStartSniffOnStartup:
            case PipelineFailure.BadAuthentication:
            case PipelineFailure.NoNodesAttempted:
            case PipelineFailure.SniffFailure:
            case PipelineFailure.Unexpected:
                throw ThrowOnBadBulk(response, $"{nameof(BulkAll)} halted after {nameof(PipelineFailure)}.{reason} from _bulk");

            case PipelineFailure.BadResponse:
            case PipelineFailure.PingFailure:
            case PipelineFailure.MaxTimeoutReached:
            case PipelineFailure.BadRequest:
            default:
                ThrowOnExhaustedRetries();
                return(await RetryDocuments(page, ++backOffRetries, buffer).ConfigureAwait(false));
            }

            void ThrowOnExhaustedRetries()
            {
                if (backOffRetries < _backOffRetries)
                {
                    return;
                }

                throw ThrowOnBadBulk(response,
                                     $"{nameof(BulkAll)} halted after {nameof(PipelineFailure)}.{reason} from _bulk and exhausting retries ({backOffRetries})"
                                     );
            }
        }
Esempio n. 2
0
 public BulkResponse(Nest.BulkResponse resp) : base(resp) => _resp = resp;
Esempio n. 3
0
        private void HandleDroppedDocuments(List <Tuple <BulkResponseItemBase, T> > droppedDocuments, BulkResponse response)
        {
            if (droppedDocuments.Count <= 0)
            {
                return;
            }

            foreach (var dropped in droppedDocuments)
            {
                _droppedDocumentCallBack(dropped.Item1, dropped.Item2);
            }
            if (!_partitionedBulkRequest.ContinueAfterDroppedDocuments)
            {
                throw ThrowOnBadBulk(response, $"{nameof(BulkAll)} halted after receiving failures that can not be retried from _bulk");
            }
        }
        private async Task <BulkAllResponse> HandleBulkRequest(IList <T> buffer, long page, int backOffRetries, BulkResponse response)
        {
            var clientException = response.ApiCall.OriginalException as ElasticsearchClientException;
            //TODO expose this on IAPiCallDetails as RetryLater in 7.0?
            var failureReason = clientException?.FailureReason.GetValueOrDefault(PipelineFailure.Unexpected);

            switch (failureReason)
            {
            case PipelineFailure.MaxRetriesReached:
                //TODO move this to its own PipelineFailure classification in 7.0
                if (response.ApiCall.AuditTrail.Last().Event == AuditEvent.FailedOverAllNodes)
                {
                    throw ThrowOnBadBulk(response, $"BulkAll halted after attempted bulk failed over all the active nodes");
                }

                return(await RetryDocuments(page, ++backOffRetries, buffer));

            case PipelineFailure.CouldNotStartSniffOnStartup:
            case PipelineFailure.BadAuthentication:
            case PipelineFailure.NoNodesAttempted:
            case PipelineFailure.SniffFailure:
            case PipelineFailure.Unexpected:
                throw ThrowOnBadBulk(response,
                                     $"BulkAll halted after {nameof(PipelineFailure)}{failureReason.GetStringValue()} from _bulk");

            default:
                return(await RetryDocuments(page, ++backOffRetries, buffer).ConfigureAwait(false));
            }
        }