|
@@ -22,6 +22,7 @@ import org.elasticsearch.action.bulk.TransportBulkAction;
|
|
|
import org.elasticsearch.action.index.IndexRequest;
|
|
|
import org.elasticsearch.action.ingest.DeletePipelineRequest;
|
|
|
import org.elasticsearch.action.ingest.PutPipelineRequest;
|
|
|
+import org.elasticsearch.action.support.CountDownActionListener;
|
|
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
|
|
import org.elasticsearch.client.internal.Client;
|
|
|
import org.elasticsearch.cluster.ClusterChangedEvent;
|
|
@@ -72,7 +73,6 @@ import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Set;
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.function.BiConsumer;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.function.IntConsumer;
|
|
@@ -687,15 +687,16 @@ public class IngestService implements ClusterStateApplier, ReportingService<Inge
|
|
|
@Override
|
|
|
protected void doRun() {
|
|
|
final Thread originalThread = Thread.currentThread();
|
|
|
- final AtomicInteger counter = new AtomicInteger(numberOfActionRequests);
|
|
|
+ final ActionListener<Void> onFinished = new CountDownActionListener(
|
|
|
+ numberOfActionRequests,
|
|
|
+ () -> onCompletion.accept(originalThread, null)
|
|
|
+ );
|
|
|
+
|
|
|
int i = 0;
|
|
|
for (DocWriteRequest<?> actionRequest : actionRequests) {
|
|
|
IndexRequest indexRequest = TransportBulkAction.getIndexWriteRequest(actionRequest);
|
|
|
if (indexRequest == null) {
|
|
|
- if (counter.decrementAndGet() == 0) {
|
|
|
- onCompletion.accept(originalThread, null);
|
|
|
- }
|
|
|
- assert counter.get() >= 0;
|
|
|
+ onFinished.onResponse(null);
|
|
|
i++;
|
|
|
continue;
|
|
|
}
|
|
@@ -715,25 +716,12 @@ public class IngestService implements ClusterStateApplier, ReportingService<Inge
|
|
|
} else if (IngestService.NOOP_PIPELINE_NAME.equals(finalPipelineId) == false) {
|
|
|
pipelines = List.of(finalPipelineId);
|
|
|
} else {
|
|
|
- if (counter.decrementAndGet() == 0) {
|
|
|
- onCompletion.accept(originalThread, null);
|
|
|
- }
|
|
|
- assert counter.get() >= 0;
|
|
|
+ onFinished.onResponse(null);
|
|
|
i++;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- executePipelines(
|
|
|
- i,
|
|
|
- pipelines.iterator(),
|
|
|
- hasFinalPipeline,
|
|
|
- indexRequest,
|
|
|
- onDropped,
|
|
|
- onFailure,
|
|
|
- counter,
|
|
|
- onCompletion,
|
|
|
- originalThread
|
|
|
- );
|
|
|
+ executePipelines(i, pipelines.iterator(), hasFinalPipeline, indexRequest, onDropped, onFailure, onFinished);
|
|
|
|
|
|
i++;
|
|
|
}
|
|
@@ -748,9 +736,7 @@ public class IngestService implements ClusterStateApplier, ReportingService<Inge
|
|
|
final IndexRequest indexRequest,
|
|
|
final IntConsumer onDropped,
|
|
|
final BiConsumer<Integer, Exception> onFailure,
|
|
|
- final AtomicInteger counter,
|
|
|
- final BiConsumer<Thread, Exception> onCompletion,
|
|
|
- final Thread originalThread
|
|
|
+ final ActionListener<Void> onFinished
|
|
|
) {
|
|
|
assert it.hasNext();
|
|
|
final String pipelineId = it.next();
|
|
@@ -778,6 +764,9 @@ public class IngestService implements ClusterStateApplier, ReportingService<Inge
|
|
|
e
|
|
|
);
|
|
|
onFailure.accept(slot, e);
|
|
|
+ // document failed! no further processing of this doc
|
|
|
+ onFinished.onResponse(null);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
Iterator<String> newIt = it;
|
|
@@ -791,6 +780,9 @@ public class IngestService implements ClusterStateApplier, ReportingService<Inge
|
|
|
slot,
|
|
|
new IllegalStateException("final pipeline [" + pipelineId + "] can't change the target index")
|
|
|
);
|
|
|
+ // document failed! no further processing of this doc
|
|
|
+ onFinished.onResponse(null);
|
|
|
+ return;
|
|
|
} else {
|
|
|
indexRequest.isPipelineResolved(false);
|
|
|
resolvePipelines(null, indexRequest, state.metadata());
|
|
@@ -804,22 +796,9 @@ public class IngestService implements ClusterStateApplier, ReportingService<Inge
|
|
|
}
|
|
|
|
|
|
if (newIt.hasNext()) {
|
|
|
- executePipelines(
|
|
|
- slot,
|
|
|
- newIt,
|
|
|
- newHasFinalPipeline,
|
|
|
- indexRequest,
|
|
|
- onDropped,
|
|
|
- onFailure,
|
|
|
- counter,
|
|
|
- onCompletion,
|
|
|
- originalThread
|
|
|
- );
|
|
|
+ executePipelines(slot, newIt, newHasFinalPipeline, indexRequest, onDropped, onFailure, onFinished);
|
|
|
} else {
|
|
|
- if (counter.decrementAndGet() == 0) {
|
|
|
- onCompletion.accept(originalThread, null);
|
|
|
- }
|
|
|
- assert counter.get() >= 0;
|
|
|
+ onFinished.onResponse(null);
|
|
|
}
|
|
|
});
|
|
|
} catch (Exception e) {
|
|
@@ -828,10 +807,7 @@ public class IngestService implements ClusterStateApplier, ReportingService<Inge
|
|
|
e
|
|
|
);
|
|
|
onFailure.accept(slot, e);
|
|
|
- if (counter.decrementAndGet() == 0) {
|
|
|
- onCompletion.accept(originalThread, null);
|
|
|
- }
|
|
|
- assert counter.get() >= 0;
|
|
|
+ onFinished.onResponse(null);
|
|
|
}
|
|
|
}
|
|
|
|