Skip to content
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

[Not For Review] [apache/helix] -- PreferenceList Ordering Changes during Maintenance Mode #2761

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.apache.helix.controller.rebalancer;

import java.util.List;
import java.util.Map;

import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
import org.apache.helix.controller.stages.CurrentStateOutput;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.MasterSlaveSMD;
import org.apache.helix.model.Partition;
import org.apache.helix.util.TestInputLoader;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class TestMaintenanceRebalancer {

private static final String RESOURCE_NAME = "testResource";
private static final String PARTITION_NAME = "testResourcePartition";

@Test(dataProvider = "TestComputeIdealStateInput")
public void testComputeIdealState(String comment, String stateModelName, List<String> liveInstances,
List<String> preferenceList, Map<String, String> currentStateMap, List<String> expectedPrefList) {
System.out.println("Test case comment: " + comment);
MaintenanceRebalancer rebalancer = new MaintenanceRebalancer();

Partition partition = new Partition(PARTITION_NAME);
CurrentStateOutput currentStateOutput = new CurrentStateOutput();
for (String instance : currentStateMap.keySet()) {
currentStateOutput.setCurrentState(RESOURCE_NAME, partition, instance, currentStateMap.get(instance));
}

IdealState currentIdealState = new IdealState(RESOURCE_NAME);
currentIdealState.setRebalanceMode(IdealState.RebalanceMode.FULL_AUTO);
currentIdealState.setRebalancerClassName("org.apache.helix.controller.rebalancer.waged.WagedRebalancer");
currentIdealState.setStateModelDefRef(stateModelName);
currentIdealState.setPreferenceList(PARTITION_NAME, preferenceList);

ResourceControllerDataProvider dataCache = mock(ResourceControllerDataProvider.class);
when(dataCache.getStateModelDef("MasterSlave")).thenReturn(MasterSlaveSMD.build());

IdealState updatedIdealState = rebalancer
.computeNewIdealState(RESOURCE_NAME, currentIdealState, currentStateOutput, dataCache);

List<String> partitionPrefList = updatedIdealState.getPreferenceList(PARTITION_NAME);
System.out.println(partitionPrefList);
System.out.println(expectedPrefList);
Assert.assertTrue(partitionPrefList.equals(expectedPrefList));
}

@DataProvider(name = "TestComputeIdealStateInput")
public Object[][] loadTestComputeIdealStateInput() {
final String[] params = {
"comment", "stateModel", "liveInstances", "preferenceList", "currentStateMap", "expectedPreferenceList"
};
return TestInputLoader.loadTestInputs("MaintenanceRebalancer.ComputeNewIdealState.json", params);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
[
{
"comment": "[Case 1] Leader - Follower (A, B, C) -> (A, C, B)",
"stateModel": "MasterSlave",
"liveInstances": [],
"preferenceList": [
"lor1-app20330.prod.linkedin.com_11932", "lor1-app21726.prod.linkedin.com_11932", "lor1-app4217.prod.linkedin.com_11932"
],
"currentStateMap": {
"lor1-app4217.prod.linkedin.com_11932" : "SLAVE",
"lor1-app20330.prod.linkedin.com_11932" : "MASTER",
"lor1-app21726.prod.linkedin.com_11932" : "SLAVE"
},
"expectedPreferenceList": [
"lor1-app20330.prod.linkedin.com_11932", "lor1-app4217.prod.linkedin.com_11932", "lor1-app21726.prod.linkedin.com_11932"
]
},
{
"comment": "[Case 2] Leader - Follower (A, B, C) -> (A, C, B)",
"stateModel": "MasterSlave",
"liveInstances": [],
"preferenceList": [
"lor1-app20171.prod.linkedin.com_11932", "lor1-app19760.prod.linkedin.com_11932", "lor1-app4298.prod.linkedin.com_11932"
],
"currentStateMap": {
"lor1-app20171.prod.linkedin.com_11932" : "MASTER",
"lor1-app4298.prod.linkedin.com_11932" : "SLAVE",
"lor1-app19760.prod.linkedin.com_11932" : "SLAVE"
},
"expectedPreferenceList": [
"lor1-app20171.prod.linkedin.com_11932", "lor1-app4298.prod.linkedin.com_11932", "lor1-app19760.prod.linkedin.com_11932"
]
},
{
"comment": "[Case 3] Leader - Follower (A, B, C) -> (A, C, B)",
"stateModel": "MasterSlave",
"liveInstances": [],
"preferenceList": [
"lor1-app19760.prod.linkedin.com_11932", "lor1-app4086.prod.linkedin.com_11932", "lor1-app4196.prod.linkedin.com_11932"
],
"currentStateMap": {
"lor1-app4086.prod.linkedin.com_11932" : "SLAVE",
"lor1-app4196.prod.linkedin.com_11932" : "SLAVE",
"lor1-app19760.prod.linkedin.com_11932" : "MASTER"
},
"expectedPreferenceList": [
"lor1-app19760.prod.linkedin.com_11932", "lor1-app4196.prod.linkedin.com_11932", "lor1-app4086.prod.linkedin.com_11932"
]
},
{
"comment": "[Case 4] Leader - Follower (A, B, C) -> (A, C, B)",
"stateModel": "MasterSlave",
"liveInstances": [],
"preferenceList": [
"lor1-app4119.prod.linkedin.com_11932", "lor1-app4481.prod.linkedin.com_11932", "lor1-app7528.prod.linkedin.com_11932"
],
"currentStateMap": {
"lor1-app7528.prod.linkedin.com_11932" : "SLAVE",
"lor1-app4119.prod.linkedin.com_11932" : "MASTER",
"lor1-app4481.prod.linkedin.com_11932" : "SLAVE"
},
"expectedPreferenceList": [
"lor1-app4119.prod.linkedin.com_11932", "lor1-app7528.prod.linkedin.com_11932", "lor1-app4481.prod.linkedin.com_11932"
]
},
{
"comment": "[Handles 0] Leader - Offline - Follower (Offline should go to end)",
"stateModel": "MasterSlave",
"liveInstances": [],
"preferenceList": [
"lor1-app21646.prod.linkedin.com_11932", "lor1-app4495.prod.linkedin.com_11932", "lor1-app4138.prod.linkedin.com_11932"
],
"currentStateMap": {
"lor1-app21646.prod.linkedin.com_11932" : "MASTER",
"lor1-app4495.prod.linkedin.com_11932" : "OFFLINE",
"lor1-app4138.prod.linkedin.com_11932" : "SLAVE"
},
"expectedPreferenceList": [
"lor1-app21646.prod.linkedin.com_11932", "lor1-app4138.prod.linkedin.com_11932", "lor1-app4495.prod.linkedin.com_11932"
]
}

]
Loading