Skip to content

Commit a53e229

Browse files
Gankris96dk2k
authored andcommitted
Add support for index level slice count setting (opensearch-project#15336)
Signed-off-by: Ganesh Ramadurai <[email protected]>
1 parent 107f17f commit a53e229

File tree

5 files changed

+120
-1
lines changed

5 files changed

+120
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2323
- Support filtering on a large list encoded by bitmap ([#14774](https://github.com/opensearch-project/OpenSearch/pull/14774))
2424
- Add slice execution listeners to SearchOperationListener interface ([#15153](https://github.com/opensearch-project/OpenSearch/pull/15153))
2525
- Adding access to noSubMatches and noOverlappingMatches in Hyphenation ([#13895](https://github.com/opensearch-project/OpenSearch/pull/13895))
26+
- Add support for index level max slice count setting for concurrent segment search ([#15336](https://github.com/opensearch-project/OpenSearch/pull/15336))
2627

2728
### Dependencies
2829
- Bump `netty` from 4.1.111.Final to 4.1.112.Final ([#15081](https://github.com/opensearch-project/OpenSearch/pull/15081))

server/src/main/java/org/opensearch/common/settings/IndexScopedSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
238238

239239
// Settings for concurrent segment search
240240
IndexSettings.INDEX_CONCURRENT_SEGMENT_SEARCH_SETTING,
241+
IndexSettings.INDEX_CONCURRENT_SEGMENT_SEARCH_MAX_SLICE_COUNT,
241242
IndexSettings.ALLOW_DERIVED_FIELDS,
242243

243244
// Settings for star tree index

server/src/main/java/org/opensearch/index/IndexSettings.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import static org.opensearch.index.mapper.MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING;
7777
import static org.opensearch.index.mapper.MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING;
7878
import static org.opensearch.index.store.remote.directory.RemoteSnapshotDirectory.SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_MINIMUM_VERSION;
79+
import static org.opensearch.search.SearchService.CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_DEFAULT_VALUE;
7980

8081
/**
8182
* This class encapsulates all index level settings and handles settings updates.
@@ -691,6 +692,14 @@ public static IndexMergePolicy fromString(String text) {
691692
Property.Dynamic
692693
);
693694

695+
public static final Setting<Integer> INDEX_CONCURRENT_SEGMENT_SEARCH_MAX_SLICE_COUNT = Setting.intSetting(
696+
"index.search.concurrent.max_slice_count",
697+
CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_DEFAULT_VALUE,
698+
CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_DEFAULT_VALUE,
699+
Property.Dynamic,
700+
Property.IndexScope
701+
);
702+
694703
public static final Setting<Boolean> INDEX_DOC_ID_FUZZY_SET_ENABLED_SETTING = Setting.boolSetting(
695704
"index.optimize_doc_id_lookup.fuzzy_set.enabled",
696705
false,

server/src/main/java/org/opensearch/search/DefaultSearchContext.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,14 @@ public int getTargetMaxSliceCount() {
991991
if (shouldUseConcurrentSearch() == false) {
992992
throw new IllegalStateException("Target slice count should not be used when concurrent search is disabled");
993993
}
994-
return clusterService.getClusterSettings().get(SearchService.CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_SETTING);
994+
995+
return indexService.getIndexSettings()
996+
.getSettings()
997+
.getAsInt(
998+
IndexSettings.INDEX_CONCURRENT_SEGMENT_SEARCH_MAX_SLICE_COUNT.getKey(),
999+
clusterService.getClusterSettings().get(SearchService.CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_SETTING)
1000+
);
1001+
9951002
}
9961003

9971004
@Override

server/src/test/java/org/opensearch/search/SearchServiceTests.java

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.opensearch.action.support.IndicesOptions;
5555
import org.opensearch.action.support.PlainActionFuture;
5656
import org.opensearch.action.support.WriteRequest;
57+
import org.opensearch.cluster.service.ClusterService;
5758
import org.opensearch.common.UUIDs;
5859
import org.opensearch.common.settings.Settings;
5960
import org.opensearch.common.settings.SettingsException;
@@ -1413,6 +1414,106 @@ public void testConcurrentSegmentSearchSearchContext() throws IOException {
14131414
.get();
14141415
}
14151416

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+
14161517
/**
14171518
* Test that the Search Context for concurrent segment search enabled is set correctly at the time of construction.
14181519
* The same is used throughout the context object lifetime even if cluster setting changes before the request completion.

0 commit comments

Comments
 (0)