forked from apache/helix
-
Notifications
You must be signed in to change notification settings - Fork 7
Rebalancing Fix : Handle All Nodes Disabled Case #121
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
Open
ngngwr
wants to merge
3
commits into
dev
Choose a base branch
from
ngangwar/rebalance_all_nodes_disabled
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -471,7 +471,7 @@ private Map<String, Resource> computeResourceBestPossibleStateWithWagedRebalance | |
| for (Resource resource : wagedRebalancedResourceMap.values()) { | ||
| IdealState is = newIdealStates.get(resource.getResourceName()); | ||
| // Check if the WAGED rebalancer has calculated the result for this resource or not. | ||
| if (is != null && checkBestPossibleStateCalculation(is)) { | ||
| if (is != null && checkBestPossibleStateCalculation(is, resource, currentStateOutput)) { | ||
| // The WAGED rebalancer calculates a valid result, record in the output | ||
| updateBestPossibleStateOutput(output, resource, is); | ||
| } else { | ||
|
|
@@ -540,7 +540,7 @@ private boolean computeSingleResourceBestPossibleState(ClusterEvent event, | |
| rebalancer.computeNewIdealState(resourceName, idealState, currentStateOutput, cache); | ||
|
|
||
| // Check if calculation is done successfully | ||
| if (!checkBestPossibleStateCalculation(idealState)) { | ||
| if (!checkBestPossibleStateCalculation(idealState, resource, currentStateOutput)) { | ||
| LogUtil.logWarn(logger, _eventId, | ||
| "The calculated idealState is not valid, resource: " + resourceName); | ||
| return false; | ||
|
|
@@ -577,28 +577,62 @@ private boolean computeSingleResourceBestPossibleState(ClusterEvent event, | |
| return false; | ||
| } | ||
|
|
||
| private boolean checkBestPossibleStateCalculation(IdealState idealState) { | ||
| private boolean checkBestPossibleStateCalculation(IdealState idealState, Resource resource, | ||
| CurrentStateOutput currentStateOutput) { | ||
| // If replicas is 0, indicate the resource is not fully initialized or ready to be rebalanced | ||
| if (idealState.getRebalanceMode() == IdealState.RebalanceMode.FULL_AUTO && !idealState | ||
| .getReplicas().equals("0")) { | ||
| Map<String, List<String>> preferenceLists = idealState.getPreferenceLists(); | ||
| if (preferenceLists == null || preferenceLists.isEmpty()) { | ||
| return false; | ||
| // Empty preference lists: allow only when there are existing replicas to clean up | ||
| // (e.g., all nodes disabled). Reject when resource is not initialized (no current state). | ||
| return hasCurrentStateForResource(resource, currentStateOutput); | ||
| } | ||
| int emptyListCount = 0; | ||
| for (List<String> preferenceList : preferenceLists.values()) { | ||
| if (preferenceList.isEmpty()) { | ||
| emptyListCount++; | ||
| } | ||
| } | ||
| // If all lists are empty, rebalance fails completely | ||
| return emptyListCount != preferenceLists.values().size(); | ||
| if (emptyListCount == preferenceLists.values().size()) { | ||
| // All lists empty: allow only when there are replicas to clean up (all nodes disabled). | ||
| return hasCurrentStateForResource(resource, currentStateOutput); | ||
| } | ||
| // Some but not all lists empty: this is valid when maxPartitionsPerInstance limits capacity. | ||
| // Only reject when maxPartitionsPerInstance is NOT set and we have inconsistent empty lists. | ||
| if (emptyListCount > 0 && idealState.getMaxPartitionsPerInstance() > 0) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirm the default value for getMaxPartitionsPerInstance once. |
||
| // Empty lists are expected when capacity is limited by maxPartitionsPerInstance | ||
| return true; | ||
| } | ||
| // No maxPartitionsPerInstance configured: empty lists indicate inconsistent state, reject. | ||
| return emptyListCount == 0; | ||
| } else { | ||
| // For non FULL_AUTO RebalanceMode, rebalancing is not controlled by Helix | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if the resource has at least one partition with existing replicas in current state. | ||
| * Used to distinguish "all nodes disabled" (replicas exist, need cleanup) from "resource not | ||
| * initialized" (no replicas, should skip). | ||
| */ | ||
| private boolean hasCurrentStateForResource(Resource resource, | ||
| CurrentStateOutput currentStateOutput) { | ||
| if (resource == null || currentStateOutput == null) { | ||
| return false; | ||
| } | ||
| String resourceName = resource.getResourceName(); | ||
| for (Partition partition : resource.getPartitions()) { | ||
| Map<String, String> currentStateMap = | ||
| currentStateOutput.getCurrentStateMap(resourceName, partition); | ||
| if (currentStateMap != null && !currentStateMap.isEmpty()) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private Rebalancer<ResourceControllerDataProvider> getCustomizedRebalancer( | ||
| String rebalancerClassName, String resourceName) { | ||
| Rebalancer<ResourceControllerDataProvider> customizedRebalancer = null; | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When will the preference list be null?
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.
Could this end up in a situation where rebalancer could fail to calculate preference list due to some other issue and we end up dropping all partitions which could be a risky behaviour?