-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cancellation of in-flight search requests at coordinator level
Signed-off-by: PritLadani <[email protected]>
- Loading branch information
1 parent
d76adf3
commit 1402ced
Showing
14 changed files
with
565 additions
and
80 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
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
62 changes: 62 additions & 0 deletions
62
server/src/main/java/org/opensearch/search/backpressure/settings/SearchTaskSettings.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,62 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.opensearch.search.backpressure.settings; | ||
|
||
import org.opensearch.common.settings.ClusterSettings; | ||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.monitor.jvm.JvmStats; | ||
|
||
/** | ||
* Defines the settings related to the cancellation of SearchTasks. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
|
||
public class SearchTaskSettings { | ||
private static final long HEAP_SIZE_BYTES = JvmStats.jvmStats().getMem().getHeapMax().getBytes(); | ||
|
||
private static class Defaults { | ||
private static final double TOTAL_HEAP_PERCENT_THRESHOLD = 0.05; | ||
} | ||
|
||
/** | ||
* Defines the heap usage threshold (in percentage) for the sum of heap usages across all search tasks | ||
* before in-flight cancellation is applied. | ||
*/ | ||
private volatile double totalHeapPercentThreshold; | ||
public static final Setting<Double> SETTING_TOTAL_HEAP_PERCENT_THRESHOLD_FOR_SEARCH_QUERY = Setting.doubleSetting( | ||
"search_backpressure.search_task.total_heap_percent_threshold", | ||
Defaults.TOTAL_HEAP_PERCENT_THRESHOLD, | ||
0.0, | ||
1.0, | ||
Setting.Property.Dynamic, | ||
Setting.Property.NodeScope | ||
); | ||
|
||
public SearchTaskSettings(Settings settings, ClusterSettings clusterSettings) { | ||
totalHeapPercentThreshold = SETTING_TOTAL_HEAP_PERCENT_THRESHOLD_FOR_SEARCH_QUERY.get(settings); | ||
clusterSettings.addSettingsUpdateConsumer( | ||
SETTING_TOTAL_HEAP_PERCENT_THRESHOLD_FOR_SEARCH_QUERY, | ||
this::setTotalHeapPercentThreshold | ||
); | ||
} | ||
|
||
public double getTotalHeapPercentThreshold() { | ||
return totalHeapPercentThreshold; | ||
} | ||
|
||
public long getTotalHeapBytesThreshold() { | ||
return (long) (HEAP_SIZE_BYTES * getTotalHeapPercentThreshold()); | ||
} | ||
|
||
private void setTotalHeapPercentThreshold(double totalHeapPercentThreshold) { | ||
this.totalHeapPercentThreshold = totalHeapPercentThreshold; | ||
} | ||
} |
Oops, something went wrong.