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

[backport to 2.x] Fix exceptions in IntervalCalculation and ResultIndexingHandler #1386

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

kaituo
Copy link
Collaborator

@kaituo kaituo commented Dec 5, 2024

Description

backport PR #1379 to 2.x

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

…search-project#1379)

* Fix race condition in PageListener

This PR
- Introduced an `AtomicInteger` called `pagesInFlight` to track the number of pages currently being processed. 
- Incremented `pagesInFlight` before processing each page and decremented it after processing is complete
- Adjusted the condition in `scheduleImputeHCTask` to check both `pagesInFlight.get() == 0` (all pages have been processed) and `sentOutPages.get() == receivedPages.get()` (all responses have been received) before scheduling the `imputeHC` task. 
- Removed the previous final check in `onResponse` that decided when to schedule `imputeHC`, relying instead on the updated counters for accurate synchronization.

These changes address the race condition where `sentOutPages` might not have been incremented in time before checking whether to schedule the `imputeHC` task. By accurately tracking the number of in-flight pages and sent pages, we ensure that `imputeHC` is executed only after all pages have been fully processed and all responses have been received.

Testing done:
1. Reproduced the race condition by starting two detectors with imputation. This causes an out of order illegal argument exception from RCF due to this race condition. Also verified the change fixed the problem.
2. added an IT for the above scenario.

Signed-off-by: Kaituo Li <[email protected]>

* Fix exceptions in IntervalCalculation and ResultIndexingHandler

- **IntervalCalculation**: Prevent an `ArrayIndexOutOfBoundsException` by returning early when there are fewer than two timestamps. Previously, the code assumed at least two timestamps, causing an exception when only one was present.

- **ResultIndexingHandler**: Handle exceptions from asynchronous calls by logging error messages instead of throwing exceptions. Since the caller does not wait for these asynchronous operations, throwing exceptions had no effect and could lead to unhandled exceptions. Logging provides visibility without disrupting the caller's flow.

Testing done:
1. added UT and ITs.

Signed-off-by: Kaituo Li <[email protected]>

---------

Signed-off-by: Kaituo Li <[email protected]>
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 97.14286% with 1 line in your changes missing coverage. Please review.

Project coverage is 81.65%. Comparing base (c95c430) to head (6440d77).
Report is 1 commits behind head on 2.x.

Files with missing lines Patch % Lines
...eries/transport/handler/ResultIndexingHandler.java 96.96% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #1386      +/-   ##
============================================
+ Coverage     80.16%   81.65%   +1.49%     
- Complexity     5721     5832     +111     
============================================
  Files           533      533              
  Lines         23528    23523       -5     
  Branches       2367     2367              
============================================
+ Hits          18861    19208     +347     
+ Misses         3552     3162     -390     
- Partials       1115     1153      +38     
Flag Coverage Δ
plugin 81.65% <97.14%> (+1.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...t/transport/ForecastResultBulkTransportAction.java 48.14% <ø> (ø)
...h/timeseries/rest/handler/IntervalCalculation.java 93.20% <100.00%> (ø)
...eries/transport/handler/ResultIndexingHandler.java 86.25% <96.96%> (+21.54%) ⬆️

... and 29 files with indirect coverage changes

@kaituo kaituo merged commit b9345e7 into opensearch-project:2.x Dec 6, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants