Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing SearchBP version to 2_6_0 #6216

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ SearchBackpressureSettings getSettings() {
return settings;
}

SearchBackpressureState getSearchBackpressureStats(Class<? extends SearchBackpressureTask> taskType) {
SearchBackpressureState getSearchBackpressureState(Class<? extends SearchBackpressureTask> taskType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these refactoring? Do we plan to backport this again?

Copy link
Contributor Author

@PritLadani PritLadani Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have already backported this refactoring to 2.x. #6194

return searchBackpressureStates.get(taskType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.opensearch.common.unit.TimeValue;

/**
* Settings related to search backpressure mode and internal
* Settings related to search backpressure mode and interval
*
* @opensearch.internal
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ public SearchTaskSettings(Settings settings, ClusterSettings clusterSettings) {
clusterSettings.addSettingsUpdateConsumer(SETTING_CANCELLATION_BURST, this::setCancellationBurst);
}

/**
* Callback listeners.
*/

public double getTotalHeapPercentThreshold() {
return totalHeapPercentThreshold;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SearchBackpressureStats(
public SearchBackpressureStats(StreamInput in) throws IOException {
searchShardTaskStats = new SearchShardTaskStats(in);
mode = SearchBackpressureMode.fromName(in.readString());
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
if (in.getVersion().onOrAfter(Version.V_2_6_0)) {
searchTaskStats = in.readOptionalWriteable(SearchTaskStats::new);
} else {
searchTaskStats = null;
Expand All @@ -64,7 +64,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
public void writeTo(StreamOutput out) throws IOException {
searchShardTaskStats.writeTo(out);
out.writeString(mode.getName());
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
if (out.getVersion().onOrAfter(Version.V_2_6_0)) {
out.writeOptionalWriteable(searchTaskStats);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void testTrackerStateUpdateOnSearchTaskCompletion() {
// service.onTaskCompleted(new SearchTask(1, "test", "test", () -> "Test", TaskId.EMPTY_TASK_ID, new HashMap<>()));
service.onTaskCompleted(createMockTaskWithResourceStats(SearchTask.class, 100, 200));
}
assertEquals(100, service.getSearchBackpressureStats(SearchTask.class).getCompletionCount());
assertEquals(100, service.getSearchBackpressureState(SearchTask.class).getCompletionCount());
verify(mockTaskResourceUsageTracker, times(100)).update(any());
}

Expand Down Expand Up @@ -182,7 +182,7 @@ public void testTrackerStateUpdateOnSearchShardTaskCompletion() {
for (int i = 0; i < 100; i++) {
service.onTaskCompleted(createMockTaskWithResourceStats(SearchShardTask.class, 100, 200));
}
assertEquals(100, service.getSearchBackpressureStats(SearchShardTask.class).getCompletionCount());
assertEquals(100, service.getSearchBackpressureState(SearchShardTask.class).getCompletionCount());
verify(mockTaskResourceUsageTracker, times(100)).update(any());
}

Expand Down Expand Up @@ -234,19 +234,19 @@ public void testSearchTaskInFlightCancellation() {
// There are 25 SearchTasks eligible for cancellation but only 5 will be cancelled (burst limit).
service.doRun();
verify(mockTaskManager, times(5)).cancelTaskAndDescendants(any(), anyString(), anyBoolean(), any());
assertEquals(1, service.getSearchBackpressureStats(SearchTask.class).getLimitReachedCount());
assertEquals(1, service.getSearchBackpressureState(SearchTask.class).getLimitReachedCount());

// If the clock or completed task count haven't made sufficient progress, we'll continue to be rate-limited.
service.doRun();
verify(mockTaskManager, times(5)).cancelTaskAndDescendants(any(), anyString(), anyBoolean(), any());
assertEquals(2, service.getSearchBackpressureStats(SearchTask.class).getLimitReachedCount());
assertEquals(2, service.getSearchBackpressureState(SearchTask.class).getLimitReachedCount());

// Fast-forward the clock by ten second to replenish some tokens.
// This will add 50 tokens (time delta * rate) to 'rateLimitPerTime' but it will cancel only 5 tasks (burst limit).
mockTime.addAndGet(TimeUnit.SECONDS.toNanos(10));
service.doRun();
verify(mockTaskManager, times(10)).cancelTaskAndDescendants(any(), anyString(), anyBoolean(), any());
assertEquals(3, service.getSearchBackpressureStats(SearchTask.class).getLimitReachedCount());
assertEquals(3, service.getSearchBackpressureState(SearchTask.class).getLimitReachedCount());

// Verify search backpressure stats.
SearchBackpressureStats expectedStats = new SearchBackpressureStats(
Expand Down Expand Up @@ -306,12 +306,12 @@ public void testSearchShardTaskInFlightCancellation() {
// There are 15 SearchShardTasks eligible for cancellation but only 10 will be cancelled (burst limit).
service.doRun();
verify(mockTaskManager, times(10)).cancelTaskAndDescendants(any(), anyString(), anyBoolean(), any());
assertEquals(1, service.getSearchBackpressureStats(SearchShardTask.class).getLimitReachedCount());
assertEquals(1, service.getSearchBackpressureState(SearchShardTask.class).getLimitReachedCount());

// If the clock or completed task count haven't made sufficient progress, we'll continue to be rate-limited.
service.doRun();
verify(mockTaskManager, times(10)).cancelTaskAndDescendants(any(), anyString(), anyBoolean(), any());
assertEquals(2, service.getSearchBackpressureStats(SearchShardTask.class).getLimitReachedCount());
assertEquals(2, service.getSearchBackpressureState(SearchShardTask.class).getLimitReachedCount());

// Simulate task completion to replenish some tokens.
// This will add 2 tokens (task count delta * cancellationRatio) to 'rateLimitPerTaskCompletion'.
Expand All @@ -320,7 +320,7 @@ public void testSearchShardTaskInFlightCancellation() {
}
service.doRun();
verify(mockTaskManager, times(12)).cancelTaskAndDescendants(any(), anyString(), anyBoolean(), any());
assertEquals(3, service.getSearchBackpressureStats(SearchShardTask.class).getLimitReachedCount());
assertEquals(3, service.getSearchBackpressureState(SearchShardTask.class).getLimitReachedCount());

// Verify search backpressure stats.
SearchBackpressureStats expectedStats = new SearchBackpressureStats(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Optional<TaskCancellation.Reason> checkAndMaybeGetCancellationReason(Task
}

@Override
public Stats stats(List<? extends Task> searchShardTasks) {
public Stats stats(List<? extends Task> activeTasks) {
return null;
}
};
Expand Down