-
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
Refactoring GatedAutoCloseable and moving RecoveryState.Timer #2965
Conversation
This is a part of the process of merging our feature branch - feature/segment-replication - back into main by re-PRing our changes from the feature branch. GatedAutoCloseable currently wraps a subclass of RefCounted. Segment replication adds another subclass, but this also wraps RefCounted. Both subclasses have the same shutdown hook - decRef. This change makes the superclass less generic to increase code convergence. The breakdown of the plan to merge segment-replication to main is detailed in opensearch-project#2355 Segment replication design proposal - opensearch-project#2229 Signed-off-by: Kartik Ganesh <gkart@amazon.com>
This change makes two minor updates to RecoveryState - 1. The readRecoveryState API is removed because it can be replaced by an invocation of the constructor 2. The class members of the Timer inner class are changed to private, and accesses are only through the public APIs Signed-off-by: Kartik Ganesh <gkart@amazon.com>
This change removes the use of RandomBoolean in testing the Timer classes and creates a dedicated unit test for each. The common test logic is shared via a private method. Signed-off-by: Kartik Ganesh <gkart@amazon.com>
This will eventually be reused across both replication use-cases - peer recovery and segment replication. Signed-off-by: Kartik Ganesh <gkart@amazon.com>
Removes a non-deterministic code path around stopping the timer, and avoids assertThat (deprecated) Signed-off-by: Kartik Ganesh <gkart@amazon.com>
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.
Automated reviews are unhappy. Maybe missing a trailing newline?
* A serializable timer that is used to measure the time taken for | ||
* file replication operations like recovery. | ||
*/ | ||
public class Timer implements Writeable { |
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.
"Timer" is a super generic name, used in lots of places (e.g. java.util.Timer, org.opensearch.search.profile.Timer, etc). Is there a more specific name that makes sense now that it is no longer an inner class? Maybe ReplicationTimer?
Signed-off-by: Kartik Ganesh <gkart@amazon.com>
Failure due to a flaky assertion on a timer. I'm currently looking into how we can improve these tests.
|
Trying to serialize and deserialize a running Timer instance, and then checking for equality leads to flaky test failures when the ser/deser takes time. Signed-off-by: Kartik Ganesh <gkart@amazon.com>
Flaky test failure #1703 Refiring gradle check |
start gradle check |
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 looks straightforward, thank you. Will leave it for @andrross to do another pass.
I labelled to backport to 2.x (2.1), nothing breaking here right? |
* Refactoring GatedAutoCloseable to AutoCloseableRefCounted This is a part of the process of merging our feature branch - feature/segment-replication - back into main by re-PRing our changes from the feature branch. GatedAutoCloseable currently wraps a subclass of RefCounted. Segment replication adds another subclass, but this also wraps RefCounted. Both subclasses have the same shutdown hook - decRef. This change makes the superclass less generic to increase code convergence. The breakdown of the plan to merge segment-replication to main is detailed in #2355 Segment replication design proposal - #2229 Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Minor refactoring in RecoveryState This change makes two minor updates to RecoveryState - 1. The readRecoveryState API is removed because it can be replaced by an invocation of the constructor 2. The class members of the Timer inner class are changed to private, and accesses are only through the public APIs Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Update RecoveryTargetTests to test Timer subclasses deterministically This change removes the use of RandomBoolean in testing the Timer classes and creates a dedicated unit test for each. The common test logic is shared via a private method. Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Move the RecoveryState.Timer class to a top-level class This will eventually be reused across both replication use-cases - peer recovery and segment replication. Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Further update of timer tests in RecoveryTargetTests Removes a non-deterministic code path around stopping the timer, and avoids assertThat (deprecated) Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Rename to ReplicationTimer Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Remove RecoveryTargetTests assert on a running timer Trying to serialize and deserialize a running Timer instance, and then checking for equality leads to flaky test failures when the ser/deser takes time. Signed-off-by: Kartik Ganesh <gkart@amazon.com> (cherry picked from commit c7c410a)
Correct, nothing breaking; safe to backport to 2.x |
…#3014) * Refactoring GatedAutoCloseable to AutoCloseableRefCounted This is a part of the process of merging our feature branch - feature/segment-replication - back into main by re-PRing our changes from the feature branch. GatedAutoCloseable currently wraps a subclass of RefCounted. Segment replication adds another subclass, but this also wraps RefCounted. Both subclasses have the same shutdown hook - decRef. This change makes the superclass less generic to increase code convergence. The breakdown of the plan to merge segment-replication to main is detailed in #2355 Segment replication design proposal - #2229 Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Minor refactoring in RecoveryState This change makes two minor updates to RecoveryState - 1. The readRecoveryState API is removed because it can be replaced by an invocation of the constructor 2. The class members of the Timer inner class are changed to private, and accesses are only through the public APIs Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Update RecoveryTargetTests to test Timer subclasses deterministically This change removes the use of RandomBoolean in testing the Timer classes and creates a dedicated unit test for each. The common test logic is shared via a private method. Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Move the RecoveryState.Timer class to a top-level class This will eventually be reused across both replication use-cases - peer recovery and segment replication. Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Further update of timer tests in RecoveryTargetTests Removes a non-deterministic code path around stopping the timer, and avoids assertThat (deprecated) Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Rename to ReplicationTimer Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Remove RecoveryTargetTests assert on a running timer Trying to serialize and deserialize a running Timer instance, and then checking for equality leads to flaky test failures when the ser/deser takes time. Signed-off-by: Kartik Ganesh <gkart@amazon.com> (cherry picked from commit c7c410a) Co-authored-by: Kartik Ganesh <gkart@amazon.com>
Signed-off-by: Kartik Ganesh gkart@amazon.com
Description
This PR is one of the first steps in merging the feature branch
feature/segment-replication
back intomain
by re-PRing key changes. It covers part of the code changes in #2926 . The breakdown of the plan to merge segment-replication to main is detailed in #2355The changes included in this PR are as follows:
GatedAutoCloseable
currently wraps a subclass ofRefCounted
. Segment replication adds another subclass, but this also wrapsRefCounted
. Both subclasses have the same shutdown hook -decRef
. Therefore,GatedAutoCloseable
has been made less generic (and renamed toAutoCloseableRefCounted
) to increase code convergence.RecoveryState.Timer
inner class has been moved to a top-level class. This will eventually be reused across both replication use-cases - peer recovery and segment replication.RecoveryTargetTests
test class, the test methods forTimer
classes have been separated into distinct unit tests for each subclass. Common test logic is shared via a private method. The use ofRandomBoolean
has been removed to avoid non-deterministic code paths in testing. While doing so, the usage ofassertThat
(deprecated) has been replaced in these code paths.readRecoveryState
API fromRecoveryState
, replacing it by a direct invocation of the constructor.Segment replication design proposal - #2229
Issues Resolved
N/A
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.