|
54 | 54 | import org.opensearch.action.support.IndicesOptions;
|
55 | 55 | import org.opensearch.action.support.PlainActionFuture;
|
56 | 56 | import org.opensearch.action.support.WriteRequest;
|
| 57 | +import org.opensearch.cluster.service.ClusterService; |
57 | 58 | import org.opensearch.common.UUIDs;
|
58 | 59 | import org.opensearch.common.settings.Settings;
|
59 | 60 | import org.opensearch.common.settings.SettingsException;
|
@@ -1413,6 +1414,106 @@ public void testConcurrentSegmentSearchSearchContext() throws IOException {
|
1413 | 1414 | .get();
|
1414 | 1415 | }
|
1415 | 1416 |
|
| 1417 | + /** |
| 1418 | + * Tests that the slice count is calculated correctly when concurrent search is enabled |
| 1419 | + * If concurrent search enabled - |
| 1420 | + * pick index level slice count setting if index level setting is set |
| 1421 | + * else pick default cluster level slice count setting |
| 1422 | + * @throws IOException |
| 1423 | + */ |
| 1424 | + public void testConcurrentSegmentSearchSliceCount() throws IOException { |
| 1425 | + |
| 1426 | + String index = randomAlphaOfLengthBetween(5, 10).toLowerCase(Locale.ROOT); |
| 1427 | + IndexService indexService = createIndex(index); |
| 1428 | + final SearchService service = getInstanceFromNode(SearchService.class); |
| 1429 | + ClusterService clusterService = getInstanceFromNode(ClusterService.class); |
| 1430 | + ShardId shardId = new ShardId(indexService.index(), 0); |
| 1431 | + long nowInMillis = System.currentTimeMillis(); |
| 1432 | + String clusterAlias = randomBoolean() ? null : randomAlphaOfLengthBetween(3, 10); |
| 1433 | + SearchRequest searchRequest = new SearchRequest(); |
| 1434 | + searchRequest.allowPartialSearchResults(randomBoolean()); |
| 1435 | + ShardSearchRequest request = new ShardSearchRequest( |
| 1436 | + OriginalIndices.NONE, |
| 1437 | + searchRequest, |
| 1438 | + shardId, |
| 1439 | + indexService.numberOfShards(), |
| 1440 | + AliasFilter.EMPTY, |
| 1441 | + 1f, |
| 1442 | + nowInMillis, |
| 1443 | + clusterAlias, |
| 1444 | + Strings.EMPTY_ARRAY |
| 1445 | + ); |
| 1446 | + // enable concurrent search |
| 1447 | + client().admin() |
| 1448 | + .cluster() |
| 1449 | + .prepareUpdateSettings() |
| 1450 | + .setTransientSettings(Settings.builder().put(SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING.getKey(), true)) |
| 1451 | + .get(); |
| 1452 | + |
| 1453 | + Integer[][] scenarios = { |
| 1454 | + // cluster setting, index setting, expected slice count |
| 1455 | + // expected value null will pick up default value from settings |
| 1456 | + { null, null, clusterService.getClusterSettings().get(SearchService.CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_SETTING) }, |
| 1457 | + { 4, null, 4 }, |
| 1458 | + { null, 3, 3 }, |
| 1459 | + { 4, 3, 3 }, }; |
| 1460 | + |
| 1461 | + for (Integer[] sliceCounts : scenarios) { |
| 1462 | + Integer clusterSliceCount = sliceCounts[0]; |
| 1463 | + Integer indexSliceCount = sliceCounts[1]; |
| 1464 | + Integer targetSliceCount = sliceCounts[2]; |
| 1465 | + |
| 1466 | + if (clusterSliceCount != null) { |
| 1467 | + client().admin() |
| 1468 | + .cluster() |
| 1469 | + .prepareUpdateSettings() |
| 1470 | + .setTransientSettings( |
| 1471 | + Settings.builder() |
| 1472 | + .put(SearchService.CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_SETTING.getKey(), clusterSliceCount) |
| 1473 | + ) |
| 1474 | + .get(); |
| 1475 | + } else { |
| 1476 | + client().admin() |
| 1477 | + .cluster() |
| 1478 | + .prepareUpdateSettings() |
| 1479 | + .setTransientSettings( |
| 1480 | + Settings.builder().putNull(SearchService.CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_SETTING.getKey()) |
| 1481 | + ) |
| 1482 | + .get(); |
| 1483 | + } |
| 1484 | + if (indexSliceCount != null) { |
| 1485 | + client().admin() |
| 1486 | + .indices() |
| 1487 | + .prepareUpdateSettings(index) |
| 1488 | + .setSettings( |
| 1489 | + Settings.builder().put(IndexSettings.INDEX_CONCURRENT_SEGMENT_SEARCH_MAX_SLICE_COUNT.getKey(), indexSliceCount) |
| 1490 | + ) |
| 1491 | + .get(); |
| 1492 | + } else { |
| 1493 | + client().admin() |
| 1494 | + .indices() |
| 1495 | + .prepareUpdateSettings(index) |
| 1496 | + .setSettings(Settings.builder().putNull(IndexSettings.INDEX_CONCURRENT_SEGMENT_SEARCH_MAX_SLICE_COUNT.getKey())) |
| 1497 | + .get(); |
| 1498 | + } |
| 1499 | + |
| 1500 | + try (DefaultSearchContext searchContext = service.createSearchContext(request, new TimeValue(System.currentTimeMillis()))) { |
| 1501 | + searchContext.evaluateRequestShouldUseConcurrentSearch(); |
| 1502 | + assertEquals(targetSliceCount.intValue(), searchContext.getTargetMaxSliceCount()); |
| 1503 | + } |
| 1504 | + } |
| 1505 | + // cleanup |
| 1506 | + client().admin() |
| 1507 | + .cluster() |
| 1508 | + .prepareUpdateSettings() |
| 1509 | + .setTransientSettings( |
| 1510 | + Settings.builder() |
| 1511 | + .putNull(SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING.getKey()) |
| 1512 | + .putNull(SearchService.CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_SETTING.getKey()) |
| 1513 | + ) |
| 1514 | + .get(); |
| 1515 | + } |
| 1516 | + |
1416 | 1517 | /**
|
1417 | 1518 | * Test that the Search Context for concurrent segment search enabled is set correctly at the time of construction.
|
1418 | 1519 | * The same is used throughout the context object lifetime even if cluster setting changes before the request completion.
|
|
0 commit comments