-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change INDEX_SEARCHER threadpool to resizable to support task resourc…
…e tracking Signed-off-by: Jay Deng <jayd0104@gmail.com>
- Loading branch information
Jay Deng
committed
May 10, 2023
1 parent
6ac3317
commit cd88594
Showing
5 changed files
with
191 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
...sterTest/java/org/opensearch/action/admin/cluster/node/tasks/ConcurrentSearchTasksIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.action.admin.cluster.node.tasks; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.opensearch.action.search.SearchAction; | ||
import org.opensearch.action.search.SearchTransportService; | ||
import org.opensearch.action.support.WriteRequest; | ||
import org.opensearch.cluster.ClusterState; | ||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.common.collect.Tuple; | ||
import org.opensearch.common.regex.Regex; | ||
import org.opensearch.common.settings.FeatureFlagSettings; | ||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.FeatureFlags; | ||
import org.opensearch.common.xcontent.XContentType; | ||
import org.opensearch.index.query.QueryBuilders; | ||
import org.opensearch.tasks.TaskInfo; | ||
import org.opensearch.tasks.ThreadResourceInfo; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.hamcrest.Matchers.startsWith; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse; | ||
|
||
/** | ||
* Integration tests for task management API | ||
* <p> | ||
* We need at least 2 nodes so we have a cluster-manager node a non-cluster-manager node | ||
*/ | ||
public class ConcurrentSearchTasksIT extends TasksIT { | ||
|
||
private static final int INDEX_SEARCHER_THREADS = 3; | ||
|
||
@Override | ||
protected Settings nodeSettings(int nodeOrdinal) { | ||
return Settings.builder() | ||
.put(super.nodeSettings(nodeOrdinal)) | ||
.put("thread_pool.index_searcher.size", INDEX_SEARCHER_THREADS) | ||
.put("thread_pool.index_searcher.queue_size", INDEX_SEARCHER_THREADS) | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected Settings featureFlagSettings() { | ||
Settings.Builder featureSettings = Settings.builder(); | ||
for (Setting builtInFlag : FeatureFlagSettings.BUILT_IN_FEATURE_FLAGS) { | ||
featureSettings.put(builtInFlag.getKey(), builtInFlag.getDefaultRaw(Settings.EMPTY)); | ||
} | ||
featureSettings.put(FeatureFlags.CONCURRENT_SEGMENT_SEARCH, true); | ||
return featureSettings.build(); | ||
} | ||
|
||
public void testConcurrentSearchTaskTracking() { | ||
final String INDEX_NAME = "test"; | ||
final int NUM_SHARDS = 1; | ||
final int NUM_DOCS = 7; | ||
|
||
registerTaskManagerListeners(SearchAction.NAME); // coordinator task | ||
registerTaskManagerListeners(SearchAction.NAME + "[*]"); // shard task | ||
ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); | ||
|
||
createIndex( | ||
INDEX_NAME, | ||
Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, NUM_SHARDS) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
.build() | ||
); | ||
ensureGreen(INDEX_NAME); // Make sure all shards are allocated to catch replication tasks | ||
indexDocumentsWithRefresh(INDEX_NAME, NUM_DOCS); // Concurrent search requires >5 segments or >250,000 docs to have concurrency, so we index 7 docs each in a different segment. | ||
assertSearchResponse(client().prepareSearch(INDEX_NAME).setQuery(QueryBuilders.matchAllQuery()).get()); | ||
|
||
// the search operation should produce one coordinator task | ||
List<TaskInfo> mainTask = findEvents(SearchAction.NAME, Tuple::v1); | ||
assertEquals(1, mainTask.size()); | ||
TaskInfo mainTaskInfo = mainTask.get(0); | ||
MatcherAssert.assertThat(mainTaskInfo.getDescription(), startsWith("indices[test], search_type[")); | ||
MatcherAssert.assertThat(mainTaskInfo.getDescription(), containsString("\"query\":{\"match_all\"")); | ||
|
||
// check that if we have any shard-level requests they all have non-zero length description | ||
List<TaskInfo> shardTasks = findEvents(SearchAction.NAME + "[*]", Tuple::v1); | ||
assertEquals(NUM_SHARDS, shardTasks.size()); // We should only have 1 shard search task per shard | ||
for (TaskInfo taskInfo : shardTasks) { | ||
MatcherAssert.assertThat(taskInfo.getParentTaskId(), notNullValue()); | ||
assertEquals(mainTaskInfo.getTaskId(), taskInfo.getParentTaskId()); | ||
switch (taskInfo.getAction()) { | ||
case SearchTransportService.QUERY_ACTION_NAME: | ||
case SearchTransportService.DFS_ACTION_NAME: | ||
case SearchTransportService.QUERY_CAN_MATCH_NAME: | ||
assertTrue(taskInfo.getDescription(), Regex.simpleMatch("shardId[[test][*]]", taskInfo.getDescription())); | ||
break; | ||
case SearchTransportService.QUERY_ID_ACTION_NAME: | ||
assertTrue(taskInfo.getDescription(), Regex.simpleMatch("id[*], indices[test]", taskInfo.getDescription())); | ||
break; | ||
case SearchTransportService.FETCH_ID_ACTION_NAME: | ||
assertTrue( | ||
taskInfo.getDescription(), | ||
Regex.simpleMatch("id[*], size[1], lastEmittedDoc[null]", taskInfo.getDescription()) | ||
); | ||
break; | ||
default: | ||
fail("Unexpected action [" + taskInfo.getAction() + "] with description [" + taskInfo.getDescription() + "]"); | ||
} | ||
|
||
Map<Long, List<ThreadResourceInfo>> threadStats = getThreadStats(SearchAction.NAME + "[*]", taskInfo.getTaskId()); | ||
assertEquals(2, threadStats.size()); // Confirm that more than 1 thread worked on this task and recorded stats | ||
|
||
// assert that all task descriptions have non-zero length | ||
MatcherAssert.assertThat(taskInfo.getDescription().length(), greaterThan(0)); | ||
} | ||
} | ||
|
||
private void indexDocumentsWithRefresh(String indexName, int numDocs) { | ||
for (int i = 0; i < numDocs; i++) { | ||
client().prepareIndex(indexName) | ||
.setId(String.format("test_id_%d", i)) | ||
.setSource(String.format("{\"foo_%d\": \"bar_%d\"}", i, i), XContentType.JSON) | ||
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) | ||
.get(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters