-
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.
Add query group level rejection logic (#15428)
* add rejection listener Signed-off-by: Kaushal Kumar <[email protected]> * add rejection listener unit test Signed-off-by: Kaushal Kumar <[email protected]> * add rejection logic for shard level requests Signed-off-by: Kaushal Kumar <[email protected]> * add changelog entry Signed-off-by: Kaushal Kumar <[email protected]> * apply spotless check Signed-off-by: Kaushal Kumar <[email protected]> * remove unused files and fix precommit Signed-off-by: Kaushal Kumar <[email protected]> * refactor code Signed-off-by: Kaushal Kumar <[email protected]> * add package info file Signed-off-by: Kaushal Kumar <[email protected]> * remove unused method from QueryGroupService stub Signed-off-by: Kaushal Kumar <[email protected]> --------- Signed-off-by: Kaushal Kumar <[email protected]>
- Loading branch information
1 parent
0a10aca
commit c11d275
Showing
9 changed files
with
180 additions
and
9 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
32 changes: 32 additions & 0 deletions
32
server/src/main/java/org/opensearch/wlm/QueryGroupService.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,32 @@ | ||
/* | ||
* 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.wlm; | ||
|
||
import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; | ||
|
||
/** | ||
* This is stub at this point in time and will be replace by an acutal one in couple of days | ||
*/ | ||
public class QueryGroupService { | ||
/** | ||
* | ||
* @param queryGroupId query group identifier | ||
*/ | ||
public void rejectIfNeeded(String queryGroupId) { | ||
if (queryGroupId == null) return; | ||
boolean reject = false; | ||
final StringBuilder reason = new StringBuilder(); | ||
// TODO: At this point this is dummy and we need to decide whether to cancel the request based on last | ||
// reported resource usage for the queryGroup. We also need to increment the rejection count here for the | ||
// query group | ||
if (reject) { | ||
throw new OpenSearchRejectedExecutionException("QueryGroup " + queryGroupId + " is already contended." + reason.toString()); | ||
} | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
...c/main/java/org/opensearch/wlm/listeners/QueryGroupRequestRejectionOperationListener.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,39 @@ | ||
/* | ||
* 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.wlm.listeners; | ||
|
||
import org.opensearch.action.search.SearchRequestContext; | ||
import org.opensearch.action.search.SearchRequestOperationsListener; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.wlm.QueryGroupService; | ||
import org.opensearch.wlm.QueryGroupTask; | ||
|
||
/** | ||
* This listener is used to perform the rejections for incoming requests into a queryGroup | ||
*/ | ||
public class QueryGroupRequestRejectionOperationListener extends SearchRequestOperationsListener { | ||
|
||
private final QueryGroupService queryGroupService; | ||
private final ThreadPool threadPool; | ||
|
||
public QueryGroupRequestRejectionOperationListener(QueryGroupService queryGroupService, ThreadPool threadPool) { | ||
this.queryGroupService = queryGroupService; | ||
this.threadPool = threadPool; | ||
} | ||
|
||
/** | ||
* This method assumes that the queryGroupId is already populated in the thread context | ||
* @param searchRequestContext SearchRequestContext instance | ||
*/ | ||
@Override | ||
protected void onRequestStart(SearchRequestContext searchRequestContext) { | ||
final String queryGroupId = threadPool.getThreadContext().getHeader(QueryGroupTask.QUERY_GROUP_ID_HEADER); | ||
queryGroupService.rejectIfNeeded(queryGroupId); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
server/src/main/java/org/opensearch/wlm/listeners/package-info.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,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* WLM related listener constructs | ||
*/ | ||
package org.opensearch.wlm.listeners; |
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
53 changes: 53 additions & 0 deletions
53
...t/java/org/opensearch/wlm/listeners/QueryGroupRequestRejectionOperationListenerTests.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,53 @@ | ||
/* | ||
* 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.wlm.listeners; | ||
|
||
import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
import org.opensearch.threadpool.TestThreadPool; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.wlm.QueryGroupService; | ||
import org.opensearch.wlm.QueryGroupTask; | ||
|
||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class QueryGroupRequestRejectionOperationListenerTests extends OpenSearchTestCase { | ||
ThreadPool testThreadPool; | ||
QueryGroupService queryGroupService; | ||
QueryGroupRequestRejectionOperationListener sut; | ||
|
||
public void setUp() throws Exception { | ||
super.setUp(); | ||
testThreadPool = new TestThreadPool("RejectionTestThreadPool"); | ||
queryGroupService = mock(QueryGroupService.class); | ||
sut = new QueryGroupRequestRejectionOperationListener(queryGroupService, testThreadPool); | ||
} | ||
|
||
public void tearDown() throws Exception { | ||
super.tearDown(); | ||
testThreadPool.shutdown(); | ||
} | ||
|
||
public void testRejectionCase() { | ||
final String testQueryGroupId = "asdgasgkajgkw3141_3rt4t"; | ||
testThreadPool.getThreadContext().putHeader(QueryGroupTask.QUERY_GROUP_ID_HEADER, testQueryGroupId); | ||
doThrow(OpenSearchRejectedExecutionException.class).when(queryGroupService).rejectIfNeeded(testQueryGroupId); | ||
assertThrows(OpenSearchRejectedExecutionException.class, () -> sut.onRequestStart(null)); | ||
} | ||
|
||
public void testNonRejectionCase() { | ||
final String testQueryGroupId = "asdgasgkajgkw3141_3rt4t"; | ||
testThreadPool.getThreadContext().putHeader(QueryGroupTask.QUERY_GROUP_ID_HEADER, testQueryGroupId); | ||
doNothing().when(queryGroupService).rejectIfNeeded(testQueryGroupId); | ||
|
||
sut.onRequestStart(null); | ||
} | ||
} |