예제 #1
0
        private async Task <BulkAllResponse> HandleBulkRequest(IList <T> buffer, long page, int backOffRetries, BulkResponse response)
        {
            var clientException = response.ApiCall.OriginalException as OpenSearchClientException;
            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})"
                                     );
            }
        }
예제 #2
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");
            }
        }