|
21 | 21 | import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; |
22 | 22 | import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; |
23 | 23 | import org.elasticsearch.action.bulk.FailureStoreMetrics; |
| 24 | +import org.elasticsearch.action.bulk.IndexDocFailureStoreStatus; |
24 | 25 | import org.elasticsearch.action.bulk.TransportBulkAction; |
25 | 26 | import org.elasticsearch.action.index.IndexRequest; |
26 | 27 | import org.elasticsearch.action.ingest.DeletePipelineRequest; |
@@ -721,12 +722,34 @@ void validatePipeline(Map<DiscoveryNode, IngestInfo> ingestInfos, String pipelin |
721 | 722 | ExceptionsHelper.rethrowAndSuppress(exceptions); |
722 | 723 | } |
723 | 724 |
|
724 | | - private record IngestPipelinesExecutionResult(boolean success, boolean shouldKeep, Exception exception, String failedIndex) { |
| 725 | + private record IngestPipelinesExecutionResult( |
| 726 | + boolean success, |
| 727 | + boolean shouldKeep, |
| 728 | + Exception exception, |
| 729 | + String failedIndex, |
| 730 | + IndexDocFailureStoreStatus failureStoreStatus |
| 731 | + ) { |
725 | 732 |
|
726 | | - private static final IngestPipelinesExecutionResult SUCCESSFUL_RESULT = new IngestPipelinesExecutionResult(true, true, null, null); |
727 | | - private static final IngestPipelinesExecutionResult DISCARD_RESULT = new IngestPipelinesExecutionResult(true, false, null, null); |
| 733 | + private static final IngestPipelinesExecutionResult SUCCESSFUL_RESULT = new IngestPipelinesExecutionResult( |
| 734 | + true, |
| 735 | + true, |
| 736 | + null, |
| 737 | + null, |
| 738 | + IndexDocFailureStoreStatus.NOT_APPLICABLE_OR_UNKNOWN |
| 739 | + ); |
| 740 | + private static final IngestPipelinesExecutionResult DISCARD_RESULT = new IngestPipelinesExecutionResult( |
| 741 | + true, |
| 742 | + false, |
| 743 | + null, |
| 744 | + null, |
| 745 | + IndexDocFailureStoreStatus.NOT_APPLICABLE_OR_UNKNOWN |
| 746 | + ); |
728 | 747 | private static IngestPipelinesExecutionResult failAndStoreFor(String index, Exception e) { |
729 | | - return new IngestPipelinesExecutionResult(false, true, e, index); |
| 748 | + return new IngestPipelinesExecutionResult(false, true, e, index, IndexDocFailureStoreStatus.USED); |
| 749 | + } |
| 750 | + |
| 751 | + private static IngestPipelinesExecutionResult failWithoutStoringIn(String index, Exception e) { |
| 752 | + return new IngestPipelinesExecutionResult(false, true, e, index, IndexDocFailureStoreStatus.NOT_ENABLED); |
730 | 753 | } |
731 | 754 | } |
732 | 755 |
|
@@ -756,7 +779,7 @@ public void executeBulkRequest( |
756 | 779 | final IntConsumer onDropped, |
757 | 780 | final Function<String, Boolean> resolveFailureStore, |
758 | 781 | final TriConsumer<Integer, String, Exception> onStoreFailure, |
759 | | - final BiConsumer<Integer, Exception> onFailure, |
| 782 | + final TriConsumer<Integer, Exception, IndexDocFailureStoreStatus> onFailure, |
760 | 783 | final BiConsumer<Thread, Exception> onCompletion, |
761 | 784 | final Executor executor |
762 | 785 | ) { |
@@ -816,18 +839,26 @@ public void onResponse(IngestPipelinesExecutionResult result) { |
816 | 839 | firstPipeline.getMetrics().postIngestBytes(indexRequest.ramBytesUsed()); |
817 | 840 | } |
818 | 841 | } else { |
819 | | - // We were given a failure result in the onResponse method, so we must store the failure |
820 | | - // Recover the original document state, track a failed ingest, and pass it along |
821 | | - updateIndexRequestMetadata(indexRequest, originalDocumentMetadata); |
822 | 842 | totalMetrics.ingestFailed(); |
823 | | - onStoreFailure.apply(slot, result.failedIndex, result.exception); |
| 843 | + if (IndexDocFailureStoreStatus.NOT_ENABLED.equals(result.failureStoreStatus)) { |
| 844 | + // A failure result, but despite the target being a data stream, it does not have failure |
| 845 | + // storage enabled currently. Capture the status in the onFailure call and skip any further |
| 846 | + // processing |
| 847 | + onFailure.apply(slot, result.exception, result.failureStoreStatus); |
| 848 | + } else { |
| 849 | + // We were given a failure result in the onResponse method, so we must store the failure |
| 850 | + // Recover the original document state, track a failed ingest, and pass it along |
| 851 | + updateIndexRequestMetadata(indexRequest, originalDocumentMetadata); |
| 852 | + onStoreFailure.apply(slot, result.failedIndex, result.exception); |
| 853 | + } |
824 | 854 | } |
825 | 855 | } |
826 | 856 |
|
827 | 857 | @Override |
828 | 858 | public void onFailure(Exception e) { |
| 859 | + // The target of the request does not allow failure storage, or failed for unforeseen reason |
829 | 860 | totalMetrics.ingestFailed(); |
830 | | - onFailure.accept(slot, e); |
| 861 | + onFailure.apply(slot, e, IndexDocFailureStoreStatus.NOT_APPLICABLE_OR_UNKNOWN); |
831 | 862 | } |
832 | 863 | }, |
833 | 864 | () -> { |
@@ -949,15 +980,15 @@ private void executePipelines( |
949 | 980 | if (failureStoreResolution != null && failureStoreResolution) { |
950 | 981 | failureStoreMetrics.incrementFailureStore(originalIndex, errorType, FailureStoreMetrics.ErrorLocation.PIPELINE); |
951 | 982 | listener.onResponse(IngestPipelinesExecutionResult.failAndStoreFor(originalIndex, e)); |
| 983 | + } else if (failureStoreResolution != null) { |
| 984 | + // If this document targeted a data stream that didn't have the failure store enabled, we increment |
| 985 | + // the rejected counter. |
| 986 | + // We also increment the total counter because this request will not reach the code that increments |
| 987 | + // the total counter for non-rejected documents. |
| 988 | + failureStoreMetrics.incrementTotal(originalIndex); |
| 989 | + failureStoreMetrics.incrementRejected(originalIndex, errorType, FailureStoreMetrics.ErrorLocation.PIPELINE, false); |
| 990 | + listener.onResponse(IngestPipelinesExecutionResult.failWithoutStoringIn(originalIndex, e)); |
952 | 991 | } else { |
953 | | - if (failureStoreResolution != null) { |
954 | | - // If this document targeted a data stream that didn't have the failure store enabled, we increment |
955 | | - // the rejected counter. |
956 | | - // We also increment the total counter because this request will not reach the code that increments |
957 | | - // the total counter for non-rejected documents. |
958 | | - failureStoreMetrics.incrementTotal(originalIndex); |
959 | | - failureStoreMetrics.incrementRejected(originalIndex, errorType, FailureStoreMetrics.ErrorLocation.PIPELINE, false); |
960 | | - } |
961 | 992 | listener.onFailure(e); |
962 | 993 | } |
963 | 994 | }; |
|
0 commit comments