helix
helix copied to clipboard
[apache/helix] -- Fix PreferenceList Ordering Changes during Maintenance Mode
Issues
- [x] My PR addresses the following Helix issues and references them in the PR description: Fixes #2777
Description
- [x] Here are some details about my PR, including screenshots of any UI changes: When entering maintenance-mode, we observed that instance order in preference list changes by PreferenceListNodeComparator as it uses the order in which the current-state is materialized in array list. For instance: Lets say we have 3 hosts, and here's the Current state:
{
A: LEADER,
B: FOLLOWER
C: FOLLOWER
}
Now when we create a preference-list using new ArrayList(currentState.keySet), the order in array-list depends on the hash order the keys (A, B, C). With sorting using PreferenceListNodeComparator, we put Leader at the front and ordering among Followers can be anything and could either be [A, B, C] or [A, C, B ]
Tests
- [x] The following tests are written for this issue:
Added Tests: TestMaintenanceRebalancer.testComputeIdealState
This covers various scenarios where the preference list should be preserved wrt current state
- The following is the result of the "mvn test" command on the appropriate module:
mvn clean install -Dmaven.test.skip.exec=true && mvn test -o -Dtest=TestMaintenanceRebalancer -pl=helix-core
[INFO] --- surefire:3.0.0-M3:test (default-test) @ helix-core ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.apache.helix.controller.rebalancer.TestMaintenanceRebalancer
Test case comment: [Case 1] Same state - No (A, B, C) -> (A, C, B) for different hash order
[lKmBBEPisM, 8PNpMU7EgT, HOs3rOFCad]
[lKmBBEPisM, 8PNpMU7EgT, HOs3rOFCad]
Test case comment: [Case 2] Same state - No (A, B, C) -> (A, C, B) for different hash order
[Q3ZZuCeBpu, QY9U91XBYo, GMYBW20gmC]
[Q3ZZuCeBpu, QY9U91XBYo, GMYBW20gmC]
Test case comment: [Case 3] second becomes leader, (A, B, C) -> (B, A, C) for different hash order
[8PNpMU7EgT, lKmBBEPisM, HOs3rOFCad]
[8PNpMU7EgT, lKmBBEPisM, HOs3rOFCad]
Test case comment: [Case 4] second becomes leader, (A, B, C) -> (B, A, C) for different hash order
[QY9U91XBYo, Q3ZZuCeBpu, GMYBW20gmC]
[QY9U91XBYo, Q3ZZuCeBpu, GMYBW20gmC]
Test case comment: [Case 5] leader becomes offline, (A, B, C) -> (B, C, A) for different hash order
[8PNpMU7EgT, HOs3rOFCad, lKmBBEPisM]
[8PNpMU7EgT, HOs3rOFCad, lKmBBEPisM]
Test case comment: [Case 6] leader becomes offline, (A, B, C) -> (B, C, A) for different hash order
[QY9U91XBYo, GMYBW20gmC, Q3ZZuCeBpu]
[QY9U91XBYo, GMYBW20gmC, Q3ZZuCeBpu]
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.983 s - in org.apache.helix.controller.rebalancer.TestMaintenanceRebalancer
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jacoco:0.8.6:report (generate-code-coverage-report) @ helix-core ---
[INFO] Loading execution data file /Users/hkandwal/Documents/workspaces/projects/helix_os_hk/helix-core/target/jacoco.exec
[INFO] Analyzed bundle 'Apache Helix :: Core' with 950 classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 42.293 s
[INFO] Finished at: 2024-03-14T11:50:53-07:00
[INFO] ------------------------------------------------------------------------
Changes that Break Backward Compatibility (Optional)
- My PR contains changes that break backward compatibility or previous assumptions for certain methods or API. They include:
(Consider including all behavior changes for public methods or API. Also include these changes in merge description so that other developers are aware of these changes. This allows them to make relevant code changes in feature branches accounting for the new method/API behavior.)
Documentation (Optional)
- In case of new functionality, my PR adds documentation in the following wiki page:
(Link the GitHub wiki you added)
Commits
- My commits all reference appropriate Apache Helix GitHub issues in their subject lines. In addition, my commits follow the guidelines from "How to write a good git commit message":
- Subject is separated from body by a blank line
- Subject is limited to 50 characters (not including Jira issue reference)
- Subject does not end with a period
- Subject uses the imperative mood ("add", not "adding")
- Body wraps at 72 characters
- Body explains "what" and "why", not "how"
Code Quality
- My diff has been formatted using helix-style.xml (helix-style-intellij.xml if IntelliJ IDE is used)