|
| 1 | +package org.apache.helix.integration; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.Collections; |
| 5 | +import java.util.List; |
| 6 | +import org.apache.helix.ConfigAccessor; |
| 7 | +import org.apache.helix.TestHelper; |
| 8 | +import org.apache.helix.common.ZkTestBase; |
| 9 | +import org.apache.helix.controller.rebalancer.waged.WagedRebalancer; |
| 10 | +import org.apache.helix.integration.manager.ClusterControllerManager; |
| 11 | +import org.apache.helix.integration.manager.MockParticipantManager; |
| 12 | +import org.apache.helix.model.ClusterConfig; |
| 13 | +import org.apache.helix.model.IdealState; |
| 14 | +import org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier; |
| 15 | +import org.testng.Assert; |
| 16 | +import org.testng.annotations.BeforeClass; |
| 17 | +import org.testng.annotations.Test; |
| 18 | + |
| 19 | + |
| 20 | +public class TestEndlessBestPossibleNodes extends ZkTestBase { |
| 21 | + |
| 22 | + public static String CLUSTER_NAME = TestHelper.getTestClassName() + "_cluster"; |
| 23 | + public static int PARTICIPANT_COUNT = 12; |
| 24 | + public static List<MockParticipantManager> _participants = new ArrayList<>(); |
| 25 | + public static ClusterControllerManager _controller; |
| 26 | + public static ConfigAccessor _configAccessor; |
| 27 | + |
| 28 | + @BeforeClass |
| 29 | + public void beforeClass() { |
| 30 | + System.out.println("Start test " + TestHelper.getTestClassName()); |
| 31 | + _gSetupTool.addCluster(CLUSTER_NAME, true); |
| 32 | + for (int i = 0; i < PARTICIPANT_COUNT; i++) { |
| 33 | + addParticipant("localhost_" + i); |
| 34 | + } |
| 35 | + |
| 36 | + String controllerName = CONTROLLER_PREFIX + "_0"; |
| 37 | + _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName); |
| 38 | + _controller.syncStart(); |
| 39 | + |
| 40 | + _configAccessor = new ConfigAccessor(_gZkClient); |
| 41 | + ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME); |
| 42 | + clusterConfig.setInstanceCapacityKeys(Collections.singletonList("partcount")); |
| 43 | + clusterConfig.setDefaultInstanceCapacityMap(Collections.singletonMap("partcount", 10000)); |
| 44 | + clusterConfig.setDefaultPartitionWeightMap(Collections.singletonMap("partcount", 1)); |
| 45 | + clusterConfig.setDelayRebalaceEnabled(true); |
| 46 | + clusterConfig.setRebalanceDelayTime(57600000); |
| 47 | + clusterConfig.setPersistBestPossibleAssignment(true); |
| 48 | + _configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig); |
| 49 | + } |
| 50 | + |
| 51 | + // This test was constructed to capture the bug described in issue 2971 |
| 52 | + // https://github.com/apache/helix/issues/2971 |
| 53 | + @Test |
| 54 | + public void testEndlessBestPossibleNodes() throws Exception { |
| 55 | + int numPartition = 10; |
| 56 | + BestPossibleExternalViewVerifier verifier = |
| 57 | + new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR) |
| 58 | + .setWaitTillVerify(TestHelper.DEFAULT_REBALANCE_PROCESSING_WAIT_TIME).build(); |
| 59 | + |
| 60 | + // Create 1 WAGED Resource |
| 61 | + String firstDB = "InPlaceMigrationTestDB3"; |
| 62 | + _gSetupTool.addResourceToCluster(CLUSTER_NAME, firstDB, numPartition, "LeaderStandby", |
| 63 | + IdealState.RebalanceMode.FULL_AUTO.name(), null); |
| 64 | + IdealState idealStateOne = |
| 65 | + _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, firstDB); |
| 66 | + idealStateOne.setMinActiveReplicas(2); |
| 67 | + idealStateOne.setRebalancerClassName(WagedRebalancer.class.getName()); |
| 68 | + _gSetupTool.getClusterManagementTool().setResourceIdealState(CLUSTER_NAME, firstDB, idealStateOne); |
| 69 | + _gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, firstDB, 3); |
| 70 | + Assert.assertTrue(verifier.verifyByPolling()); |
| 71 | + |
| 72 | + // Disable instances so delay rebalance overwrite is required due to min active |
| 73 | + for (int i = 0; i < PARTICIPANT_COUNT/2; i++) { |
| 74 | + _gSetupTool.getClusterManagementTool().enableInstance(CLUSTER_NAME, _participants.get(i).getInstanceName(), false); |
| 75 | + } |
| 76 | + |
| 77 | + // Add new instance to cause partial rebalance to calculate a new best possible |
| 78 | + addParticipant("newInstance_0"); |
| 79 | + |
| 80 | + // Sleep to let pipeline run and ZK writes occur |
| 81 | + Thread.sleep(5000); |
| 82 | + |
| 83 | + // There should only be 2 best possibles created (children will be 0, 1, LAST_WRITE, and LAST_SUCCESSFUL_WRITE) |
| 84 | + int childCount = _gZkClient.getChildren("/" + CLUSTER_NAME + "/ASSIGNMENT_METADATA/BEST_POSSIBLE").size(); |
| 85 | + Assert.assertTrue(childCount > 0); |
| 86 | + Assert.assertTrue(childCount < 5, "Child count was " + childCount); |
| 87 | + } |
| 88 | + |
| 89 | + public MockParticipantManager addParticipant(String instanceName) { |
| 90 | + _gSetupTool.addInstanceToCluster(CLUSTER_NAME, instanceName); |
| 91 | + MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName); |
| 92 | + participant.syncStart(); |
| 93 | + _participants.add(participant); |
| 94 | + return participant; |
| 95 | + } |
| 96 | +} |
0 commit comments