@@ -1498,17 +1498,6 @@ public void testConcurrentSegmentSearchWithRandomizedModeSettings() throws IOExc
1498
1498
String clusterMode = randomFrom (modeSettings );
1499
1499
String indexMode = randomFrom (modeSettings );
1500
1500
1501
- // default to false in case mode setting is not set
1502
- boolean concurrentSearchEnabled = false ;
1503
-
1504
- boolean aggregationSupportsConcurrent = randomBoolean ();
1505
-
1506
- if (indexMode != null ) {
1507
- concurrentSearchEnabled = !indexMode .equals ("none" ) && aggregationSupportsConcurrent ;
1508
- } else if (clusterMode != null ) {
1509
- concurrentSearchEnabled = !clusterMode .equals ("none" ) && aggregationSupportsConcurrent ;
1510
- }
1511
-
1512
1501
// Set the cluster setting for mode
1513
1502
if (clusterMode == null ) {
1514
1503
client ().admin ()
@@ -1539,46 +1528,76 @@ public void testConcurrentSegmentSearchWithRandomizedModeSettings() throws IOExc
1539
1528
.get ();
1540
1529
}
1541
1530
1542
- try (DefaultSearchContext searchContext = service .createSearchContext (request , new TimeValue (System .currentTimeMillis ()))) {
1543
- assertEquals (
1544
- clusterMode ,
1545
- client ().admin ()
1546
- .cluster ()
1547
- .prepareState ()
1548
- .get ()
1549
- .getState ()
1550
- .getMetadata ()
1551
- .transientSettings ()
1552
- .get (SearchService .CLUSTER_CONCURRENT_SEGMENT_SEARCH_MODE .getKey ())
1553
- );
1554
- assertEquals (
1555
- indexMode ,
1556
- client ().admin ()
1557
- .indices ()
1558
- .prepareGetSettings (index )
1559
- .get ()
1560
- .getSetting (index , IndexSettings .INDEX_CONCURRENT_SEGMENT_SEARCH_MODE .getKey ())
1561
- );
1562
- SearchContextAggregations mockAggregations = mock (SearchContextAggregations .class );
1563
- when (mockAggregations .factories ()).thenReturn (mock (AggregatorFactories .class ));
1564
- when (mockAggregations .factories ().allFactoriesSupportConcurrentSearch ()).thenReturn (aggregationSupportsConcurrent );
1565
-
1566
- // set the aggregations for context
1567
- searchContext .aggregations (mockAggregations );
1568
-
1569
- searchContext .evaluateRequestShouldUseConcurrentSearch ();
1570
- // check concurrentSearchenabled based on mode and supportedAggregation is computed correctly
1571
- assertEquals (concurrentSearchEnabled , searchContext .shouldUseConcurrentSearch ());
1572
- assertThat (searchContext .searcher ().getTaskExecutor (), is (notNullValue ()));
1573
- } finally {
1574
- // Cleanup
1531
+ assertEquals (
1532
+ clusterMode ,
1575
1533
client ().admin ()
1576
1534
.cluster ()
1577
- .prepareUpdateSettings ()
1578
- .setTransientSettings (Settings .builder ().putNull (SearchService .CLUSTER_CONCURRENT_SEGMENT_SEARCH_MODE .getKey ()))
1579
- .get ();
1535
+ .prepareState ()
1536
+ .get ()
1537
+ .getState ()
1538
+ .getMetadata ()
1539
+ .transientSettings ()
1540
+ .get (SearchService .CLUSTER_CONCURRENT_SEGMENT_SEARCH_MODE .getKey ())
1541
+ );
1542
+ assertEquals (
1543
+ indexMode ,
1544
+ client ().admin ()
1545
+ .indices ()
1546
+ .prepareGetSettings (index )
1547
+ .get ()
1548
+ .getSetting (index , IndexSettings .INDEX_CONCURRENT_SEGMENT_SEARCH_MODE .getKey ())
1549
+ );
1550
+
1551
+ boolean concurrentSearchEnabled ;
1552
+ // with aggregations.
1553
+ {
1554
+ boolean aggregationSupportsConcurrent = randomBoolean ();
1555
+ // Default concurrent search mode is auto, which enables concurrent segment search when aggregations are present.
1556
+ // aggregationSupportsConcurrent determines if the present aggregation type supports concurrent segment search.
1557
+ concurrentSearchEnabled = aggregationSupportsConcurrent ;
1558
+ if (indexMode != null ) {
1559
+ concurrentSearchEnabled = !indexMode .equals ("none" ) && aggregationSupportsConcurrent ;
1560
+ } else if (clusterMode != null ) {
1561
+ concurrentSearchEnabled = !clusterMode .equals ("none" ) && aggregationSupportsConcurrent ;
1562
+ }
1563
+
1564
+ try (DefaultSearchContext searchContext = service .createSearchContext (request , new TimeValue (System .currentTimeMillis ()))) {
1565
+ SearchContextAggregations mockAggregations = mock (SearchContextAggregations .class );
1566
+ when (mockAggregations .factories ()).thenReturn (mock (AggregatorFactories .class ));
1567
+ when (mockAggregations .factories ().allFactoriesSupportConcurrentSearch ()).thenReturn (aggregationSupportsConcurrent );
1568
+
1569
+ // set the aggregations for context
1570
+ searchContext .aggregations (mockAggregations );
1571
+
1572
+ searchContext .evaluateRequestShouldUseConcurrentSearch ();
1573
+ // check concurrentSearchenabled based on mode and supportedAggregation is computed correctly
1574
+ assertEquals (concurrentSearchEnabled , searchContext .shouldUseConcurrentSearch ());
1575
+ assertThat (searchContext .searcher ().getTaskExecutor (), is (notNullValue ()));
1576
+ }
1577
+ }
1580
1578
1579
+ // without aggregations.
1580
+ {
1581
+ // Default concurrent search mode is auto, without aggregations, concurrent search will be disabled.
1582
+ concurrentSearchEnabled = false ;
1583
+ if (indexMode != null ) {
1584
+ concurrentSearchEnabled = indexMode .equals ("all" );
1585
+ } else if (clusterMode != null ) {
1586
+ concurrentSearchEnabled = clusterMode .equals ("all" );
1587
+ }
1588
+ try (DefaultSearchContext searchContext = service .createSearchContext (request , new TimeValue (System .currentTimeMillis ()))) {
1589
+ searchContext .evaluateRequestShouldUseConcurrentSearch ();
1590
+ assertEquals (concurrentSearchEnabled , searchContext .shouldUseConcurrentSearch ());
1591
+ assertThat (searchContext .searcher ().getTaskExecutor (), is (notNullValue ()));
1592
+ }
1581
1593
}
1594
+
1595
+ // Cleanup
1596
+ client ().admin ()
1597
+ .cluster ()
1598
+ .prepareUpdateSettings ()
1599
+ .setTransientSettings (Settings .builder ().putNull (SearchService .CLUSTER_CONCURRENT_SEGMENT_SEARCH_MODE .getKey ()))
1600
+ .get ();
1582
1601
}
1583
1602
1584
1603
/**
0 commit comments