@@ -496,67 +496,61 @@ private void executePipelines(
496
496
final BiConsumer <Thread , Exception > onCompletion ,
497
497
final Thread originalThread
498
498
) {
499
- while (it .hasNext ()) {
500
- final String pipelineId = it .next ();
501
- try {
502
- PipelineHolder holder = pipelines .get (pipelineId );
503
- if (holder == null ) {
504
- throw new IllegalArgumentException ("pipeline with id [" + pipelineId + "] does not exist" );
499
+ assert it .hasNext ();
500
+ final String pipelineId = it .next ();
501
+ try {
502
+ PipelineHolder holder = pipelines .get (pipelineId );
503
+ if (holder == null ) {
504
+ throw new IllegalArgumentException ("pipeline with id [" + pipelineId + "] does not exist" );
505
+ }
506
+ Pipeline pipeline = holder .pipeline ;
507
+ String originalIndex = indexRequest .indices ()[0 ];
508
+ innerExecute (slot , indexRequest , pipeline , onDropped , e -> {
509
+ if (e != null ) {
510
+ logger .debug (() -> new ParameterizedMessage ("failed to execute pipeline [{}] for document [{}/{}]" ,
511
+ pipelineId , indexRequest .index (), indexRequest .id ()), e );
512
+ onFailure .accept (slot , e );
505
513
}
506
- Pipeline pipeline = holder .pipeline ;
507
- String originalIndex = indexRequest .indices ()[0 ];
508
- innerExecute (slot , indexRequest , pipeline , onDropped , e -> {
509
- if (e != null ) {
510
- logger .debug (() -> new ParameterizedMessage ("failed to execute pipeline [{}] for document [{}/{}]" ,
511
- pipelineId , indexRequest .index (), indexRequest .id ()), e );
512
- onFailure .accept (slot , e );
513
- }
514
514
515
- Iterator <String > newIt = it ;
516
- boolean newHasFinalPipeline = hasFinalPipeline ;
517
- String newIndex = indexRequest .indices ()[0 ];
515
+ Iterator <String > newIt = it ;
516
+ boolean newHasFinalPipeline = hasFinalPipeline ;
517
+ String newIndex = indexRequest .indices ()[0 ];
518
518
519
- if (Objects .equals (originalIndex , newIndex ) == false ) {
520
- if (hasFinalPipeline && it .hasNext () == false ) {
521
- totalMetrics .ingestFailed ();
522
- onFailure .accept (slot , new IllegalStateException ("final pipeline [" + pipelineId +
523
- "] can't change the target index" ));
519
+ if (Objects .equals (originalIndex , newIndex ) == false ) {
520
+ if (hasFinalPipeline && it .hasNext () == false ) {
521
+ totalMetrics .ingestFailed ();
522
+ onFailure .accept (slot , new IllegalStateException ("final pipeline [" + pipelineId +
523
+ "] can't change the target index" ));
524
+ } else {
525
+ indexRequest .isPipelineResolved (false );
526
+ resolvePipelines (null , indexRequest , state .metadata ());
527
+ if (IngestService .NOOP_PIPELINE_NAME .equals (indexRequest .getFinalPipeline ()) == false ) {
528
+ newIt = Collections .singleton (indexRequest .getFinalPipeline ()).iterator ();
529
+ newHasFinalPipeline = true ;
524
530
} else {
525
-
526
- //Drain old it so it's not looped over
527
- it .forEachRemaining ($ -> {
528
- });
529
- indexRequest .isPipelineResolved (false );
530
- resolvePipelines (null , indexRequest , state .metadata ());
531
- if (IngestService .NOOP_PIPELINE_NAME .equals (indexRequest .getFinalPipeline ()) == false ) {
532
- newIt = Collections .singleton (indexRequest .getFinalPipeline ()).iterator ();
533
- newHasFinalPipeline = true ;
534
- } else {
535
- newIt = Collections .emptyIterator ();
536
- }
531
+ newIt = Collections .emptyIterator ();
537
532
}
538
533
}
534
+ }
539
535
540
- if (newIt .hasNext ()) {
541
- executePipelines (slot , newIt , newHasFinalPipeline , indexRequest , onDropped , onFailure , counter , onCompletion ,
542
- originalThread );
543
- } else {
544
- if (counter .decrementAndGet () == 0 ) {
545
- onCompletion .accept (originalThread , null );
546
- }
547
- assert counter .get () >= 0 ;
536
+ if (newIt .hasNext ()) {
537
+ executePipelines (slot , newIt , newHasFinalPipeline , indexRequest , onDropped , onFailure , counter , onCompletion ,
538
+ originalThread );
539
+ } else {
540
+ if (counter .decrementAndGet () == 0 ) {
541
+ onCompletion .accept (originalThread , null );
548
542
}
549
- });
550
- } catch (Exception e ) {
551
- logger .debug (() -> new ParameterizedMessage ("failed to execute pipeline [{}] for document [{}/{}]" ,
552
- pipelineId , indexRequest .index (), indexRequest .id ()), e );
553
- onFailure .accept (slot , e );
554
- if (counter .decrementAndGet () == 0 ) {
555
- onCompletion .accept (originalThread , null );
543
+ assert counter .get () >= 0 ;
556
544
}
557
- assert counter .get () >= 0 ;
558
- break ;
545
+ });
546
+ } catch (Exception e ) {
547
+ logger .debug (() -> new ParameterizedMessage ("failed to execute pipeline [{}] for document [{}/{}]" ,
548
+ pipelineId , indexRequest .index (), indexRequest .id ()), e );
549
+ onFailure .accept (slot , e );
550
+ if (counter .decrementAndGet () == 0 ) {
551
+ onCompletion .accept (originalThread , null );
559
552
}
553
+ assert counter .get () >= 0 ;
560
554
}
561
555
}
562
556
0 commit comments