Skip to content

Commit

Permalink
renaming sandbox to querygroup and adjusting code based on merged PRs
Browse files Browse the repository at this point in the history
Signed-off-by: Kiran Prakash <[email protected]>
  • Loading branch information
kiranprakash154 committed Jul 18, 2024
1 parent 3766b32 commit 3e953a1
Show file tree
Hide file tree
Showing 46 changed files with 967 additions and 1,061 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.opensearch.core.tasks.TaskId;
import org.opensearch.search.fetch.ShardFetchSearchRequest;
import org.opensearch.search.internal.ShardSearchRequest;
import org.opensearch.search.sandboxing.SandboxTask;
import org.opensearch.search.querygroup.QueryGroupTask;
import org.opensearch.tasks.CancellableTask;
import org.opensearch.tasks.SearchBackpressureTask;

Expand All @@ -51,10 +51,10 @@
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public class SearchShardTask extends CancellableTask implements SearchBackpressureTask, SandboxTask {
public class SearchShardTask extends CancellableTask implements SearchBackpressureTask, QueryGroupTask {
// generating metadata in a lazy way since source can be quite big
private final MemoizedSupplier<String> metadataSupplier;
private String sandboxId;
private String queryGroupId;

public SearchShardTask(long id, String type, String action, String description, TaskId parentTaskId, Map<String, String> headers) {
this(id, type, action, description, parentTaskId, headers, () -> "");
Expand Down Expand Up @@ -88,12 +88,12 @@ public boolean shouldCancelChildrenOnCancellation() {
}

@Override
public void setSandboxId(String sandboxId) {
this.sandboxId = sandboxId;
public void setQueryGroupId(String queryGroupId) {
this.queryGroupId = queryGroupId;
}

@Override
public String getSandboxId() {
return "sandboxId";
public String getQueryGroupId() {
return "queryGroupId";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.tasks.TaskId;
import org.opensearch.search.sandboxing.SandboxTask;
import org.opensearch.search.querygroup.QueryGroupTask;
import org.opensearch.tasks.CancellableTask;
import org.opensearch.tasks.SearchBackpressureTask;

Expand All @@ -50,11 +50,11 @@
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public class SearchTask extends CancellableTask implements SearchBackpressureTask, SandboxTask {
public class SearchTask extends CancellableTask implements SearchBackpressureTask, QueryGroupTask {
// generating description in a lazy way since source can be quite big
private final Supplier<String> descriptionSupplier;
private SearchProgressListener progressListener = SearchProgressListener.NOOP;
private String sandboxId;
private String queryGroupId;

public SearchTask(
long id,
Expand Down Expand Up @@ -109,12 +109,12 @@ public boolean shouldCancelChildrenOnCancellation() {
return true;
}

public void setSandboxId(String sandboxId) {
this.sandboxId = sandboxId;
public void setQueryGroupId(String queryGroupId) {
this.queryGroupId = queryGroupId;
}

@Override
public String getSandboxId() {
return "sandboxId";
public String getQueryGroupId() {
return "queryGroupId";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public boolean isSegmentReplicationEnabled(String indexName) {
.orElse(false);
}

public Map<String, Sandbox> sandboxes() {
public Map<String, QueryGroup> queryGroups() {
// stub
return Collections.emptyMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.search.ResourceType;
import org.opensearch.search.resourcetypes.ResourceType;
import org.joda.time.Instant;

import java.io.IOException;
Expand Down Expand Up @@ -227,6 +227,17 @@ public String get_id() {
return _id;
}

/**
* Converts the threshold percentage for the given resource type to a long value.
*
* @param resourceType The resource type for which the threshold is to be converted
* @return The threshold value in long format
*/
public long getThresholdInLong(ResourceType resourceType) {
Double thresholdInPercentage = (Double) resourceLimits.get(resourceType);
return resourceType.convertThresholdPercentageToLong(thresholdInPercentage);
}

public long getUpdatedAtInMillis() {
return updatedAtInMillis;
}
Expand Down
109 changes: 0 additions & 109 deletions server/src/main/java/org/opensearch/cluster/metadata/Sandbox.java

This file was deleted.

51 changes: 0 additions & 51 deletions server/src/main/java/org/opensearch/search/ResourceType.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.opensearch.common.settings.Setting;
import org.opensearch.monitor.jvm.JvmStats;
import org.opensearch.monitor.process.ProcessProbe;
import org.opensearch.search.ResourceType;
import org.opensearch.search.backpressure.settings.SearchBackpressureMode;
import org.opensearch.search.backpressure.settings.SearchBackpressureSettings;
import org.opensearch.search.backpressure.settings.SearchShardTaskSettings;
Expand All @@ -34,6 +33,7 @@
import org.opensearch.search.backpressure.trackers.TaskResourceUsageTrackerType;
import org.opensearch.search.backpressure.trackers.TaskResourceUsageTrackers;
import org.opensearch.search.backpressure.trackers.TaskResourceUsageTrackers.TaskResourceUsageTracker;
import org.opensearch.search.resourcetypes.ResourceType;
import org.opensearch.tasks.CancellableTask;
import org.opensearch.tasks.SearchBackpressureTask;
import org.opensearch.tasks.Task;
Expand All @@ -47,7 +47,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -69,9 +68,9 @@ public class SearchBackpressureService extends AbstractLifecycleComponent implem
private static final Logger logger = LogManager.getLogger(SearchBackpressureService.class);
private static final Map<TaskResourceUsageTrackerType, Function<NodeDuressTrackers, Boolean>> trackerApplyConditions = Map.of(
TaskResourceUsageTrackerType.CPU_USAGE_TRACKER,
(nodeDuressTrackers) -> nodeDuressTrackers.isResourceInDuress(ResourceType.CPU),
(nodeDuressTrackers) -> nodeDuressTrackers.isResourceInDuress(ResourceType.fromName("cpu")),
TaskResourceUsageTrackerType.HEAP_USAGE_TRACKER,
(nodeDuressTrackers) -> isHeapTrackingSupported() && nodeDuressTrackers.isResourceInDuress(ResourceType.MEMORY),
(nodeDuressTrackers) -> isHeapTrackingSupported() && nodeDuressTrackers.isResourceInDuress(ResourceType.fromName("jvm")),
TaskResourceUsageTrackerType.ELAPSED_TIME_TRACKER,
(nodeDuressTrackers) -> true
);
Expand All @@ -94,18 +93,18 @@ public SearchBackpressureService(
ThreadPool threadPool,
TaskManager taskManager
) {
this(settings, taskResourceTrackingService, threadPool, System::nanoTime, new NodeDuressTrackers(new EnumMap<>(ResourceType.class) {
this(settings, taskResourceTrackingService, threadPool, System::nanoTime, new NodeDuressTrackers(new HashMap<>() {
{
put(
ResourceType.CPU,
ResourceType.fromName("cpu"),
new NodeDuressTracker(
() -> ProcessProbe.getInstance().getProcessCpuPercent() / 100.0 >= settings.getNodeDuressSettings()
.getCpuThreshold(),
() -> settings.getNodeDuressSettings().getNumSuccessiveBreaches()
)
);
put(
ResourceType.MEMORY,
ResourceType.fromName("jvm"),
new NodeDuressTracker(
() -> JvmStats.jvmStats().getMem().getHeapUsedPercent() / 100.0 >= settings.getNodeDuressSettings()
.getHeapThreshold(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package org.opensearch.search.backpressure.trackers;

import org.opensearch.common.util.Streak;
import org.opensearch.search.ResourceType;
import org.opensearch.search.resourcetypes.ResourceType;

import java.util.Map;
import java.util.function.BooleanSupplier;
Expand Down
Loading

0 comments on commit 3e953a1

Please sign in to comment.