4848import org .elasticsearch .common .util .concurrent .ConcurrentCollections ;
4949import org .elasticsearch .common .util .concurrent .EsExecutors ;
5050import org .elasticsearch .common .util .concurrent .EsRejectedExecutionException ;
51+ import org .elasticsearch .common .util .concurrent .TaskExecutionTimeTrackingPerIndexEsThreadPoolExecutor ;
5152import org .elasticsearch .core .IOUtils ;
5253import org .elasticsearch .core .RefCounted ;
5354import org .elasticsearch .core .Releasable ;
@@ -620,7 +621,7 @@ private <T extends RefCounted> void ensureAfterSeqNoRefreshed(
620621 final Executor executor = getExecutor (shard );
621622 try {
622623 if (waitForCheckpoint <= UNASSIGNED_SEQ_NO ) {
623- runAsync (executor , executable , listener );
624+ runAsync (executor , executable , listener , shard );
624625 return ;
625626 }
626627 if (shard .indexSettings ().getRefreshInterval ().getMillis () <= 0 ) {
@@ -696,7 +697,7 @@ private void searchReady() {
696697 if (timeoutTask != null ) {
697698 timeoutTask .cancel ();
698699 }
699- runAsync (executor , executable , listener );
700+ runAsync (executor , executable , listener , shard );
700701 }
701702 }
702703 });
@@ -719,9 +720,14 @@ private IndexShard getShard(ShardSearchRequest request) {
719720 private static <T extends RefCounted > void runAsync (
720721 Executor executor ,
721722 CheckedSupplier <T , Exception > executable ,
722- ActionListener <T > listener
723+ ActionListener <T > listener ,
724+ IndexShard shard
723725 ) {
724- executor .execute (ActionRunnable .supplyAndDecRef (listener , executable ));
726+ Runnable r = ActionRunnable .supplyAndDecRef (listener , executable );
727+ if (executor instanceof TaskExecutionTimeTrackingPerIndexEsThreadPoolExecutor perIndexExecutor ) {
728+ perIndexExecutor .registerIndexNameForRunnable (shard .shardId ().getIndexName (), r );
729+ }
730+ executor .execute (r );
725731 }
726732
727733 /**
@@ -798,7 +804,7 @@ public void executeRankFeaturePhase(RankFeatureShardRequest request, SearchShard
798804 // we handle the failure in the failure listener below
799805 throw e ;
800806 }
801- }, wrapFailureListener (listener , readerContext , markAsUsed ));
807+ }, wrapFailureListener (listener , readerContext , markAsUsed ), readerContext . indexShard () );
802808 }
803809
804810 private QueryFetchSearchResult executeFetchPhase (ReaderContext reader , SearchContext context , long afterQueryTime ) {
@@ -850,7 +856,7 @@ public void executeQueryPhase(
850856 // we handle the failure in the failure listener below
851857 throw e ;
852858 }
853- }, wrapFailureListener (listener , readerContext , markAsUsed ));
859+ }, wrapFailureListener (listener , readerContext , markAsUsed ), readerContext . indexShard () );
854860 }
855861
856862 /**
@@ -899,7 +905,7 @@ public void executeQueryPhase(
899905 // we handle the failure in the failure listener below
900906 throw e ;
901907 }
902- }, wrapFailureListener (l , readerContext , markAsUsed ));
908+ }, wrapFailureListener (l , readerContext , markAsUsed ), readerContext . indexShard () );
903909 }));
904910 }
905911
@@ -950,7 +956,7 @@ public void executeFetchPhase(
950956 // we handle the failure in the failure listener below
951957 throw e ;
952958 }
953- }, wrapFailureListener (listener , readerContext , markAsUsed ));
959+ }, wrapFailureListener (listener , readerContext , markAsUsed ), readerContext . indexShard () );
954960 }
955961
956962 public void executeFetchPhase (ShardFetchRequest request , SearchShardTask task , ActionListener <FetchSearchResult > listener ) {
@@ -987,7 +993,7 @@ public void executeFetchPhase(ShardFetchRequest request, SearchShardTask task, A
987993 // we handle the failure in the failure listener below
988994 throw e ;
989995 }
990- }, wrapFailureListener (l , readerContext , markAsUsed ));
996+ }, wrapFailureListener (l , readerContext , markAsUsed ), readerContext . indexShard () );
991997 }));
992998 }
993999
0 commit comments