use of org.apache.helix.model.Message in project helix by apache.
the class TestStateTransitionThrottle method testTransitionThrottleOnRecoveryPartition.
@Test
public void testTransitionThrottleOnRecoveryPartition() throws Exception {
String clusterName = getShortClassName() + "testRecoveryPartition";
MockParticipantManager[] participants = new MockParticipantManager[participantCount];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
final ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
setupCluster(clusterName, accessor);
// start partial participants
for (int i = 0; i < participantCount - 1; i++) {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_" + (12918 + i));
if (i == 0) {
// One participant 0, delay processing partition 0 transition
final String delayedPartitionName = resourceName + "_0";
participants[i].setTransition(new SleepTransition(99999999) {
@Override
public void doTransition(Message message, NotificationContext context) throws InterruptedException {
String partition = message.getPartitionName();
if (partition.equals(delayedPartitionName)) {
super.doTransition(message, context);
}
}
});
}
participants[i].syncStart();
}
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
BestPossibleExternalViewVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkClient(_gZkClient).build();
// Won't match, since there is pending transition
Assert.assertFalse(verifier.verify(3000));
participants[participantCount - 1] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_" + (12918 + participantCount - 1));
participants[participantCount - 1].syncStart();
// Load balance transition won't be scheduled since there is pending recovery balance transition
Assert.assertFalse(pollForPartitionAssignment(accessor, participants[participantCount - 1], resourceName, 5000));
// Stop participant, so blocking transition is removed.
participants[0].syncStop();
Assert.assertTrue(pollForPartitionAssignment(accessor, participants[participantCount - 1], resourceName, 5000));
// clean up
controller.syncStop();
for (int i = 0; i < participantCount; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.model.Message in project helix by apache.
the class TestZkSessionExpiry method newMsg.
private static Message newMsg() {
Message msg = new Message(DUMMY_MSG_TYPE, UUID.randomUUID().toString());
msg.setTgtSessionId("*");
msg.setTgtName("localhost_12918");
return msg;
}
use of org.apache.helix.model.Message in project helix by apache.
the class TestZkSessionExpiry method checkDummyMsgHandler.
/**
* trigger dummy message handler and verify it's invoked
* @param manager
* @param handledMsgSet
* @throws Exception
*/
private static void checkDummyMsgHandler(HelixManager manager, final Set<String> handledMsgSet) throws Exception {
final Message aMsg = newMsg();
HelixDataAccessor accessor = manager.getHelixDataAccessor();
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.message(manager.getInstanceName(), aMsg.getId()), aMsg);
boolean result = TestHelper.verify(new TestHelper.Verifier() {
@Override
public boolean verify() throws Exception {
return handledMsgSet.contains(aMsg.getId());
}
}, 5 * 1000);
Assert.assertTrue(result);
}
use of org.apache.helix.model.Message in project helix by apache.
the class TestPartitionLevelTransitionConstraint method test.
@Test
public void test() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
int n = 2;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
1, // number of nodes
n, // replicas
2, "MasterSlave", // do not rebalance
false);
// setup semi-auto ideal-state
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
StateModelDefinition stateModelDef = defineStateModel();
accessor.setProperty(accessor.keyBuilder().stateModelDef("Bootstrap"), stateModelDef);
IdealState idealState = accessor.getProperty(accessor.keyBuilder().idealStates("TestDB0"));
idealState.setStateModelDefRef("Bootstrap");
idealState.setReplicas("2");
idealState.getRecord().setListField("TestDB0_0", Arrays.asList("localhost_12919", "localhost_12918"));
accessor.setProperty(accessor.keyBuilder().idealStates("TestDB0"), idealState);
// setup partition-level constraint
ConstraintItemBuilder constraintItemBuilder = new ConstraintItemBuilder();
constraintItemBuilder.addConstraintAttribute(ConstraintAttribute.MESSAGE_TYPE.toString(), "STATE_TRANSITION").addConstraintAttribute(ConstraintAttribute.PARTITION.toString(), ".*").addConstraintAttribute(ConstraintAttribute.CONSTRAINT_VALUE.toString(), "1");
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
admin.setConstraint(clusterName, ConstraintType.MESSAGE_CONSTRAINT, "constraint1", constraintItemBuilder.build());
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
// start 1st participant
MockParticipantManager[] participants = new MockParticipantManager[n];
String instanceName1 = "localhost_12918";
participants[0] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName1);
participants[0].getStateMachineEngine().registerStateModelFactory("Bootstrap", new BootstrapStateModelFactory());
participants[0].syncStart();
boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// start 2nd participant which will be the master for Test0_0
String instanceName2 = "localhost_12919";
participants[1] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName2);
participants[1].getStateMachineEngine().registerStateModelFactory("Bootstrap", new BootstrapStateModelFactory());
participants[1].syncStart();
result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// check we received the message in the right order
Assert.assertEquals(_msgOrderList.size(), 7);
Message[] _msgOrderArray = _msgOrderList.toArray(new Message[0]);
assertMessage(_msgOrderArray[0], "OFFLINE", "BOOTSTRAP", instanceName1);
assertMessage(_msgOrderArray[1], "BOOTSTRAP", "SLAVE", instanceName1);
assertMessage(_msgOrderArray[2], "SLAVE", "MASTER", instanceName1);
// after we start the 2nd instance, the messages should be received in the following order:
// 1) offline->bootstrap for localhost_12919
// 2) bootstrap->slave for localhost_12919
// 3) master->slave for localhost_12918
// 4) slave->master for localhost_12919
assertMessage(_msgOrderArray[3], "OFFLINE", "BOOTSTRAP", instanceName2);
assertMessage(_msgOrderArray[4], "BOOTSTRAP", "SLAVE", instanceName2);
assertMessage(_msgOrderArray[5], "MASTER", "SLAVE", instanceName1);
assertMessage(_msgOrderArray[6], "SLAVE", "MASTER", instanceName2);
// clean up
// wait for all zk callbacks done
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.model.Message in project helix by apache.
the class JobRebalancer method isJobFinished.
private boolean isJobFinished(JobContext jobContext, String jobResource, CurrentStateOutput currentStateOutput) {
for (int pId : jobContext.getPartitionSet()) {
TaskPartitionState state = jobContext.getPartitionState(pId);
Partition partition = new Partition(pName(jobResource, pId));
String instance = jobContext.getAssignedParticipant(pId);
Message pendingMessage = currentStateOutput.getPendingState(jobResource, partition, instance);
// If state is INIT but is pending INIT->RUNNING, it's not yet safe to say the job finished
if (state == TaskPartitionState.RUNNING || (state == TaskPartitionState.INIT && pendingMessage != null)) {
return false;
}
}
return true;
}
Aggregations