93
93
import java .util .function .Function ;
94
94
import java .util .function .Supplier ;
95
95
96
+ import static org .opensearch .index .IndexSettings .INDEX_SEARCH_THROTTLED ;
96
97
import static org .hamcrest .Matchers .equalTo ;
97
98
import static org .hamcrest .Matchers .is ;
98
99
import static org .mockito .Mockito .any ;
@@ -168,6 +169,7 @@ public void testPreProcess() throws Exception {
168
169
IndexSettings indexSettings = new IndexSettings (indexMetadata , Settings .EMPTY );
169
170
when (indexService .getIndexSettings ()).thenReturn (indexSettings );
170
171
when (mapperService .getIndexSettings ()).thenReturn (indexSettings );
172
+ when (indexShard .indexSettings ()).thenReturn (indexSettings );
171
173
172
174
BigArrays bigArrays = new MockBigArrays (new MockPageCacheRecycler (Settings .EMPTY ), new NoneCircuitBreakerService ());
173
175
@@ -486,6 +488,14 @@ public void testClearQueryCancellationsOnClose() throws IOException {
486
488
when (indexService .newQueryShardContext (eq (shardId .id ()), any (), any (), nullable (String .class ), anyBoolean ())).thenReturn (
487
489
queryShardContext
488
490
);
491
+ Settings settings = Settings .builder ()
492
+ .put (IndexMetadata .SETTING_VERSION_CREATED , Version .CURRENT )
493
+ .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 1 )
494
+ .put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 2 )
495
+ .build ();
496
+ IndexMetadata indexMetadata = IndexMetadata .builder ("index" ).settings (settings ).build ();
497
+ IndexSettings indexSettings = new IndexSettings (indexMetadata , Settings .EMPTY );
498
+ when (indexShard .indexSettings ()).thenReturn (indexSettings );
489
499
490
500
BigArrays bigArrays = new MockBigArrays (new MockPageCacheRecycler (Settings .EMPTY ), new NoneCircuitBreakerService ());
491
501
@@ -551,7 +561,7 @@ protected Engine.Searcher acquireSearcherInternal(String source) {
551
561
}
552
562
}
553
563
554
- public void testSearchPathEvaluationUsingSortField () throws Exception {
564
+ public void testSearchPathEvaluation () throws Exception {
555
565
ShardSearchRequest shardSearchRequest = mock (ShardSearchRequest .class );
556
566
when (shardSearchRequest .searchType ()).thenReturn (SearchType .DEFAULT );
557
567
ShardId shardId = new ShardId ("index" , UUID .randomUUID ().toString (), 1 );
@@ -578,9 +588,24 @@ public void testSearchPathEvaluationUsingSortField() throws Exception {
578
588
IndexMetadata indexMetadata = IndexMetadata .builder ("index" ).settings (settings ).build ();
579
589
IndexSettings indexSettings = new IndexSettings (indexMetadata , Settings .EMPTY );
580
590
when (indexService .getIndexSettings ()).thenReturn (indexSettings );
591
+ when (indexShard .indexSettings ()).thenReturn (indexSettings );
581
592
582
593
BigArrays bigArrays = new MockBigArrays (new MockPageCacheRecycler (Settings .EMPTY ), new NoneCircuitBreakerService ());
583
594
595
+ IndexShard systemIndexShard = mock (IndexShard .class );
596
+ when (systemIndexShard .getQueryCachingPolicy ()).thenReturn (queryCachingPolicy );
597
+ when (systemIndexShard .getThreadPool ()).thenReturn (threadPool );
598
+ when (systemIndexShard .isSystem ()).thenReturn (true );
599
+
600
+ IndexShard throttledIndexShard = mock (IndexShard .class );
601
+ when (throttledIndexShard .getQueryCachingPolicy ()).thenReturn (queryCachingPolicy );
602
+ when (throttledIndexShard .getThreadPool ()).thenReturn (threadPool );
603
+ IndexSettings throttledIndexSettings = new IndexSettings (
604
+ indexMetadata ,
605
+ Settings .builder ().put (INDEX_SEARCH_THROTTLED .getKey (), true ).build ()
606
+ );
607
+ when (throttledIndexShard .indexSettings ()).thenReturn (throttledIndexSettings );
608
+
584
609
try (Directory dir = newDirectory (); RandomIndexWriter w = new RandomIndexWriter (random (), dir )) {
585
610
586
611
final Supplier <Engine .SearcherSupplier > searcherSupplier = () -> new Engine .SearcherSupplier (Function .identity ()) {
@@ -697,6 +722,62 @@ protected Engine.Searcher acquireSearcherInternal(String source) {
697
722
}
698
723
assertThrows (SetOnce .AlreadySetException .class , context ::evaluateRequestShouldUseConcurrentSearch );
699
724
725
+ // Case 4: With a system index concurrent segment search is not used
726
+ readerContext = new ReaderContext (
727
+ newContextId (),
728
+ indexService ,
729
+ systemIndexShard ,
730
+ searcherSupplier .get (),
731
+ randomNonNegativeLong (),
732
+ false
733
+ );
734
+ context = new DefaultSearchContext (
735
+ readerContext ,
736
+ shardSearchRequest ,
737
+ target ,
738
+ null ,
739
+ bigArrays ,
740
+ null ,
741
+ null ,
742
+ null ,
743
+ false ,
744
+ Version .CURRENT ,
745
+ false ,
746
+ executor ,
747
+ null
748
+ );
749
+ context .evaluateRequestShouldUseConcurrentSearch ();
750
+ assertFalse (context .shouldUseConcurrentSearch ());
751
+ assertThrows (SetOnce .AlreadySetException .class , context ::evaluateRequestShouldUseConcurrentSearch );
752
+
753
+ // Case 5: When search is throttled concurrent segment search is not used
754
+ readerContext = new ReaderContext (
755
+ newContextId (),
756
+ indexService ,
757
+ throttledIndexShard ,
758
+ searcherSupplier .get (),
759
+ randomNonNegativeLong (),
760
+ false
761
+ );
762
+ context = new DefaultSearchContext (
763
+ readerContext ,
764
+ shardSearchRequest ,
765
+ target ,
766
+ null ,
767
+ bigArrays ,
768
+ null ,
769
+ null ,
770
+ null ,
771
+ false ,
772
+ Version .CURRENT ,
773
+ false ,
774
+ executor ,
775
+ null
776
+ );
777
+ context .evaluateRequestShouldUseConcurrentSearch ();
778
+ assertFalse (context .shouldUseConcurrentSearch ());
779
+ assertThrows (SetOnce .AlreadySetException .class , context ::evaluateRequestShouldUseConcurrentSearch );
780
+
700
781
// shutdown the threadpool
701
782
threadPool .shutdown ();
702
783
}
0 commit comments