1616import org .elasticsearch .action .ActionListenerResponseHandler ;
1717import org .elasticsearch .action .ActionResponse ;
1818import org .elasticsearch .action .UnavailableShardsException ;
19- import org .elasticsearch .action .bulk .BulkShardRequest ;
20- import org .elasticsearch .action .bulk .BulkShardResponse ;
2119import org .elasticsearch .action .support .ActionFilters ;
2220import org .elasticsearch .action .support .ActiveShardCount ;
2321import org .elasticsearch .action .support .ChannelActionListener ;
24- import org .elasticsearch .action .support .CountDownActionListener ;
25- import org .elasticsearch .action .support .GroupedActionListener ;
2622import org .elasticsearch .action .support .TransportAction ;
2723import org .elasticsearch .action .support .TransportActions ;
2824import org .elasticsearch .client .internal .transport .NoNodeAvailableException ;
8177import org .elasticsearch .transport .TransportService ;
8278
8379import java .io .IOException ;
84- import java .util .ArrayList ;
8580import java .util .Collections ;
8681import java .util .Map ;
8782import java .util .Objects ;
8883import java .util .Optional ;
8984import java .util .concurrent .ConcurrentHashMap ;
9085import java .util .concurrent .Executor ;
9186import java .util .concurrent .atomic .AtomicBoolean ;
92- import java .util .concurrent .atomic .AtomicReference ;
93- import java .util .concurrent .atomic .AtomicReferenceArray ;
9487
9588import static org .elasticsearch .core .Strings .format ;
9689
@@ -498,10 +491,6 @@ void runWithPrimaryShardReference(final PrimaryShardReference primaryShardRefere
498491 }
499492
500493 SplitShardCountSummary reshardSplitShardCountSummary = primaryRequest .getRequest ().reshardSplitShardCountSummary ();
501- assert reshardSplitShardCountSummary .isUnset ()
502- || reshardSplitShardCountSummary .equals (
503- SplitShardCountSummary .forIndexing (indexMetadata , primaryRequest .getRequest ().shardId ().getId ())
504- );
505494 if (primaryShardReference .isRelocated ()) {
506495 primaryShardReference .close (); // release shard operation lock as soon as possible
507496 setPhase (replicationTask , "primary_delegation" );
@@ -511,7 +500,31 @@ void runWithPrimaryShardReference(final PrimaryShardReference primaryShardRefere
511500 final ShardRouting primary = primaryShardReference .routingEntry ();
512501 assert primary .relocating () : "indexShard is marked as relocated but routing isn't" + primary ;
513502 DiscoveryNode relocatingNode = clusterState .nodes ().get (primary .relocatingNodeId ());
514- delegate (relocatingNode , primary .allocationId ().getRelocationId (), onCompletionListener );
503+ String allocationID = primary .allocationId ().getRelocationId ();
504+ transportService .sendRequest (
505+ relocatingNode ,
506+ transportPrimaryAction ,
507+ new ConcreteShardRequest <>(primaryRequest .getRequest (), allocationID , primaryRequest .getPrimaryTerm ()),
508+ transportOptions ,
509+ new ActionListenerResponseHandler <>(
510+ onCompletionListener ,
511+ TransportReplicationAction .this ::newResponseInstance ,
512+ TransportResponseHandler .TRANSPORT_WORKER
513+ ) {
514+
515+ @ Override
516+ public void handleResponse (Response response ) {
517+ setPhase (replicationTask , "finished" );
518+ super .handleResponse (response );
519+ }
520+
521+ @ Override
522+ public void handleException (TransportException exp ) {
523+ setPhase (replicationTask , "finished" );
524+ super .handleException (exp );
525+ }
526+ }
527+ );
515528 } else if (reshardSplitShardCountSummary .isUnset ()
516529 || reshardSplitShardCountSummary .equals (
517530 SplitShardCountSummary .forIndexing (indexMetadata , primaryRequest .getRequest ().shardId ().getId ())
@@ -541,7 +554,34 @@ void runWithPrimaryShardReference(final PrimaryShardReference primaryShardRefere
541554 final ShardRouting target = targetShard .routingEntry ();
542555 DiscoveryNode targetNode = clusterState .nodes ().get (target .currentNodeId ());
543556 String allocationID = target .allocationId ().getId ();
544- delegate (targetNode , allocationID , onCompletionListener );
557+ transportService .sendRequest (
558+ targetNode ,
559+ transportPrimaryAction ,
560+ new ConcreteShardRequest <>(
561+ primaryRequest .getRequest (),
562+ allocationID ,
563+ indexMetadata .primaryTerm (targetShardId .id ())
564+ ),
565+ transportOptions ,
566+ new ActionListenerResponseHandler <>(
567+ onCompletionListener ,
568+ TransportReplicationAction .this ::newResponseInstance ,
569+ TransportResponseHandler .TRANSPORT_WORKER
570+ ) {
571+
572+ @ Override
573+ public void handleResponse (Response response ) {
574+ setPhase (replicationTask , "finished" );
575+ super .handleResponse (response );
576+ }
577+
578+ @ Override
579+ public void handleException (TransportException exp ) {
580+ setPhase (replicationTask , "finished" );
581+ super .handleException (exp );
582+ }
583+ }
584+ );
545585 }
546586 } else {
547587 Map <ShardId , Tuple <Response , Exception >> results = new ConcurrentHashMap <>(splitRequests .size ());
@@ -584,7 +624,30 @@ private void finish() {
584624 final ShardRouting target = targetShard .routingEntry ();
585625 DiscoveryNode targetNode = clusterState .nodes ().get (target .currentNodeId ());
586626 String allocationID = target .allocationId ().getId ();
587- delegate (targetNode , allocationID , listener );
627+ transportService .sendRequest (
628+ targetNode ,
629+ transportPrimaryAction ,
630+ new ConcreteShardRequest <>(splitRequest .getValue (), allocationID , primaryRequest .getPrimaryTerm ()),
631+ transportOptions ,
632+ new ActionListenerResponseHandler <>(
633+ listener ,
634+ TransportReplicationAction .this ::newResponseInstance ,
635+ TransportResponseHandler .TRANSPORT_WORKER
636+ ) {
637+
638+ @ Override
639+ public void handleResponse (Response response ) {
640+ setPhase (replicationTask , "finished" );
641+ super .handleResponse (response );
642+ }
643+
644+ @ Override
645+ public void handleException (TransportException exp ) {
646+ setPhase (replicationTask , "finished" );
647+ super .handleException (exp );
648+ }
649+ }
650+ );
588651 }
589652 }
590653 }
@@ -597,33 +660,6 @@ private void finish() {
597660 }
598661 }
599662
600- private void delegate (DiscoveryNode targetNode , String allocationID , ActionListener <Response > listener ) {
601- transportService .sendRequest (
602- targetNode ,
603- transportPrimaryAction ,
604- new ConcreteShardRequest <>(primaryRequest .getRequest (), allocationID , primaryRequest .getPrimaryTerm ()),
605- transportOptions ,
606- new ActionListenerResponseHandler <>(
607- listener ,
608- TransportReplicationAction .this ::newResponseInstance ,
609- TransportResponseHandler .TRANSPORT_WORKER
610- ) {
611-
612- @ Override
613- public void handleResponse (Response response ) {
614- setPhase (replicationTask , "finished" );
615- super .handleResponse (response );
616- }
617-
618- @ Override
619- public void handleException (TransportException exp ) {
620- setPhase (replicationTask , "finished" );
621- super .handleException (exp );
622- }
623- }
624- );
625- }
626-
627663 private void executePrimaryRequest (
628664 final PrimaryShardReference primaryShardReference ,
629665 String phase ,
0 commit comments