-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Bugfix] Fix IllegalArgumentException thrown when creating a PIT #16781
base: main
Are you sure you want to change the base?
[Bugfix] Fix IllegalArgumentException thrown when creating a PIT #16781
Conversation
Signed-off-by: Peter Alfonsi <[email protected]>
Signed-off-by: Peter Alfonsi <[email protected]>
❌ Gradle check result for 6d35c7e: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Signed-off-by: Peter Alfonsi <[email protected]>
Flaky test: #14293 |
❌ Gradle check result for ea30484: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
server/src/main/java/org/opensearch/action/search/SearchRequestStats.java
Show resolved
Hide resolved
Signed-off-by: Peter Alfonsi <[email protected]>
2ac0920
to
a41f9be
Compare
❌ Gradle check result for a41f9be: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Flaky test: #16576 |
Signed-off-by: Peter Alfonsi <[email protected]>
❕ Gradle check result for e20a4de: UNSTABLE Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #16781 +/- ##
============================================
- Coverage 72.24% 72.19% -0.05%
- Complexity 65334 65346 +12
============================================
Files 5318 5318
Lines 304069 304073 +4
Branches 43995 43995
============================================
- Hits 219678 219529 -149
- Misses 66389 66589 +200
+ Partials 18002 17955 -47 ☔ View full report in Codecov by Sentry. |
@@ -73,20 +73,32 @@ public long getTookMetric() { | |||
|
|||
@Override | |||
protected void onPhaseStart(SearchPhaseContext context) { | |||
phaseStatsMap.get(context.getCurrentPhase().getSearchPhaseName()).current.inc(); | |||
try { | |||
phaseStatsMap.get(context.getCurrentPhase().getSearchPhaseName()).current.inc(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I count 4 method calls in this line. The problem with this try-catch is that any one of them in theory could throw an IllegalArgumentException, and you probably don't want to swallow it in all cases. Also, exception handling in the control flow is generally something to avoid.
I might recommend revisiting that API on SearchPhase
to make it explicit that it may not be possible to get a SearchPhaseName
. Like if it returned an Optional you could do:
phase.asSearchPhaseName().ifPresent(name -> {
phaseStatsMap.get(name).current.inc();
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I've just pushed a commit changing getSearchPhaseName
to return Optional<SearchPhaseName>
.
Signed-off-by: Peter Alfonsi <[email protected]>
60b90af
to
49fec57
Compare
❌ Gradle check result for 49fec57: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Flaky test: #14296 |
Signed-off-by: Peter Alfonsi <[email protected]>
*/ | ||
public SearchPhaseName getSearchPhaseName() { | ||
return SearchPhaseName.valueOf(name.toUpperCase(Locale.ROOT)); | ||
public Optional<SearchPhaseName> getSearchPhaseName() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change to a class annotated PublicApi
so I think you'll want to make this change in way that keeps the existing signature.
Description
Fixes
java.lang.IllegalArgumentException: No enum constant org.opensearch.action.search.SearchPhaseName.CREATE_PIT
which is thrown when creating a PIT.The exception comes from SearchRequestStats. It doesn't track PIT stats as this is handled elsewhere. So, when it got search phases with the name "create_pit", it couldn't find a matching enum value and threw the error. Adds a try-catch block on search phase start/end/failure so that if no matching enum value is found, nothing happens.
Adds UTs. Also, manually tested that after making the change, the following commands no longer caused the exception:
curl -XPOST "http://localhost:9200/test-index/_doc/1?op_type=index" -H "Content-Type: application/json" -d '{ "field1": "value1", "field2": "value2", "field3": 123 }'
curl -XPOST "http://localhost:9200/test-index/_search/point_in_time?keep_alive=1h"
And confirmed the new catch-all doesn't show up in the output of
curl -XGET "localhost:9200/_nodes/stats/indices/search"
.Related Issues
Resolves #16750
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.