-
Notifications
You must be signed in to change notification settings - Fork 243
Fix waged instance capacity npe on new resource #2969
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
Merged
xyuanlu
merged 3 commits into
apache:master
from
GrantPSpencer:waged-instance-capacity-npe
Jan 29, 2025
Merged
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
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
111 changes: 111 additions & 0 deletions
111
helix-core/src/test/java/org/apache/helix/integration/TestWagedNPE.java
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 |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package org.apache.helix.integration; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import org.apache.helix.ConfigAccessor; | ||
| import org.apache.helix.TestHelper; | ||
| import org.apache.helix.common.ZkTestBase; | ||
| import org.apache.helix.controller.rebalancer.DelayedAutoRebalancer; | ||
| import org.apache.helix.controller.rebalancer.strategy.CrushEdRebalanceStrategy; | ||
| import org.apache.helix.controller.rebalancer.waged.WagedRebalancer; | ||
| import org.apache.helix.integration.manager.ClusterControllerManager; | ||
| import org.apache.helix.integration.manager.MockParticipantManager; | ||
| import org.apache.helix.model.ClusterConfig; | ||
| import org.apache.helix.model.IdealState; | ||
| import org.apache.helix.model.ResourceConfig; | ||
| import org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.BeforeClass; | ||
| import org.testng.annotations.Test; | ||
|
|
||
|
|
||
| public class TestWagedNPE extends ZkTestBase { | ||
|
|
||
| public static String CLUSTER_NAME = TestHelper.getTestClassName() + "_cluster"; | ||
| public static int PARTICIPANT_COUNT = 3; | ||
| public static List<MockParticipantManager> _participants = new ArrayList<>(); | ||
| public static ClusterControllerManager _controller; | ||
| public static ConfigAccessor _configAccessor; | ||
|
|
||
| @BeforeClass | ||
| public void beforeClass() { | ||
| System.out.println("Start test " + TestHelper.getTestClassName()); | ||
| _gSetupTool.addCluster(CLUSTER_NAME, true); | ||
| for (int i = 0; i < PARTICIPANT_COUNT; i++) { | ||
| addParticipant("localhost_" + i); | ||
| } | ||
|
|
||
| String controllerName = CONTROLLER_PREFIX + "_0"; | ||
| _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName); | ||
| _controller.syncStart(); | ||
|
|
||
| _configAccessor = new ConfigAccessor(_gZkClient); | ||
| ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME); | ||
| String testCapacityKey = "TestCapacityKey"; | ||
| clusterConfig.setInstanceCapacityKeys(Collections.singletonList(testCapacityKey)); | ||
| clusterConfig.setDefaultInstanceCapacityMap(Collections.singletonMap(testCapacityKey, 100)); | ||
| clusterConfig.setDefaultPartitionWeightMap(Collections.singletonMap(testCapacityKey, 1)); | ||
| _configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig); | ||
| } | ||
|
|
||
| // This test was constructed to capture the bug described in issue 2891 | ||
| // https://github.com/apache/helix/issues/2891 | ||
| @Test | ||
| public void testNPE() throws Exception { | ||
| int numPartition = 3; | ||
| BestPossibleExternalViewVerifier verifier = | ||
| new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR) | ||
| .setWaitTillVerify(TestHelper.DEFAULT_REBALANCE_PROCESSING_WAIT_TIME).build(); | ||
|
|
||
| // Create 1 WAGED Resource | ||
| String firstDB = "firstDB"; | ||
| _gSetupTool.addResourceToCluster(CLUSTER_NAME, firstDB, numPartition, "LeaderStandby", | ||
| IdealState.RebalanceMode.FULL_AUTO.name(), null); | ||
| IdealState idealStateOne = | ||
| _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, firstDB); | ||
| idealStateOne.setMinActiveReplicas(2); | ||
| idealStateOne.setRebalancerClassName(WagedRebalancer.class.getName()); | ||
| _gSetupTool.getClusterManagementTool().setResourceIdealState(CLUSTER_NAME, firstDB, idealStateOne); | ||
| _gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, firstDB, 3); | ||
|
|
||
| // Wait for cluster to converge | ||
| Assert.assertTrue(verifier.verifyByPolling()); | ||
|
|
||
| // Drop resource | ||
| _gSetupTool.dropResourceFromCluster(CLUSTER_NAME, firstDB); | ||
|
|
||
| // Wait for cluster to converge | ||
| Assert.assertTrue(verifier.verifyByPolling()); | ||
|
|
||
| // add instance | ||
| addParticipant("instance_to_add"); | ||
|
|
||
| // Wait for cluster to converge | ||
| Assert.assertTrue(verifier.verifyByPolling()); | ||
|
|
||
| // Add a new resource | ||
| String secondDb = "secondDB"; | ||
| _configAccessor.setResourceConfig(CLUSTER_NAME, secondDb, new ResourceConfig(secondDb)); | ||
| _gSetupTool.addResourceToCluster(CLUSTER_NAME, secondDb, numPartition, "LeaderStandby", | ||
| IdealState.RebalanceMode.FULL_AUTO.name(), null); | ||
| IdealState idealStateTwo = | ||
| _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, secondDb); | ||
| idealStateTwo.setMinActiveReplicas(2); | ||
| idealStateTwo.setRebalancerClassName(WagedRebalancer.class.getName()); | ||
| _gSetupTool.getClusterManagementTool().setResourceIdealState(CLUSTER_NAME, secondDb, idealStateTwo); | ||
| _gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, secondDb, 3); | ||
|
|
||
| // Confirm cluster can converge. Cluster will not converge if NPE occurs during pipeline run | ||
| Assert.assertTrue(verifier.verifyByPolling()); | ||
| } | ||
|
|
||
| public MockParticipantManager addParticipant(String instanceName) { | ||
| _gSetupTool.addInstanceToCluster(CLUSTER_NAME, instanceName); | ||
| MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName); | ||
| participant.syncStart(); | ||
| _participants.add(participant); | ||
| return participant; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.