use of org.apache.helix.ConfigAccessor in project helix by apache.
the class HelixTaskExecutor method updateStateTransitionMessageThreadPool.
/**
* Dedicated Thread pool can be provided in configuration or by client.
* This method is to check it and update the thread pool if necessary.
*/
private void updateStateTransitionMessageThreadPool(Message message, HelixManager manager) {
if (!message.getMsgType().equals(MessageType.STATE_TRANSITION.name())) {
return;
}
String resourceName = message.getResourceName();
String factoryName = message.getStateModelFactoryName();
String stateModelName = message.getStateModelDef();
if (factoryName == null) {
factoryName = HelixConstants.DEFAULT_STATE_MODEL_FACTORY;
}
StateModelFactory<? extends StateModel> stateModelFactory = manager.getStateMachineEngine().getStateModelFactory(stateModelName, factoryName);
String perStateTransitionTypeKey = getStateTransitionType(getPerResourceStateTransitionPoolName(resourceName), message.getFromState(), message.getToState());
if (perStateTransitionTypeKey != null && stateModelFactory != null && !_transitionTypeThreadpoolChecked.contains(perStateTransitionTypeKey)) {
ExecutorService perStateTransitionTypeExecutor = stateModelFactory.getExecutorService(resourceName, message.getFromState(), message.getToState());
_transitionTypeThreadpoolChecked.add(perStateTransitionTypeKey);
if (perStateTransitionTypeExecutor != null) {
_executorMap.put(perStateTransitionTypeKey, perStateTransitionTypeExecutor);
LOG.info(String.format("Added client specified dedicate threadpool for resource %s from %s to %s", getPerResourceStateTransitionPoolName(resourceName), message.getFromState(), message.getToState()));
return;
}
}
if (!_resourcesThreadpoolChecked.contains(resourceName)) {
int threadpoolSize = -1;
ConfigAccessor configAccessor = manager.getConfigAccessor();
// Changes to this configuration on thread pool size will only take effect after the participant get restarted.
if (configAccessor != null) {
HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(manager.getClusterName()).forResource(resourceName).build();
String threadpoolSizeStr = configAccessor.get(scope, MAX_THREADS);
try {
if (threadpoolSizeStr != null) {
threadpoolSize = Integer.parseInt(threadpoolSizeStr);
}
} catch (Exception e) {
LOG.error("Failed to parse ThreadPoolSize from resourceConfig for resource" + resourceName, e);
}
}
final String key = getPerResourceStateTransitionPoolName(resourceName);
if (threadpoolSize > 0) {
_executorMap.put(key, Executors.newFixedThreadPool(threadpoolSize, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "GerenricHelixController-message_handle_" + key);
}
}));
LOG.info("Added dedicate threadpool for resource: " + resourceName + " with size: " + threadpoolSize);
} else {
// check whether client specifies customized threadpool.
if (stateModelFactory != null) {
ExecutorService executor = stateModelFactory.getExecutorService(resourceName);
if (executor != null) {
_executorMap.put(key, executor);
LOG.info("Added client specified dedicate threadpool for resource: " + key);
}
} else {
LOG.error(String.format("Fail to get dedicate threadpool defined in stateModelFactory %s: using factoryName: %s for resource %s. No stateModelFactory was found!", stateModelName, factoryName, resourceName));
}
}
_resourcesThreadpoolChecked.add(resourceName);
}
}
use of org.apache.helix.ConfigAccessor in project helix by apache.
the class TestStateTransitionTimeoutWithResource method beforeClass.
@Override
@BeforeClass
public void beforeClass() throws Exception {
System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
// setup storage cluster
_setupTool.addCluster(CLUSTER_NAME, true);
for (int i = 0; i < NODE_NR; i++) {
String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
}
_manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
_manager.connect();
_configAccessor = new ConfigAccessor(_gZkClient);
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
boolean result = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
}
use of org.apache.helix.ConfigAccessor in project helix by apache.
the class TestDelayedAutoRebalanceWithDisabledInstance method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
super.beforeClass();
_configAccessor = new ConfigAccessor(_gZkClient);
}
use of org.apache.helix.ConfigAccessor in project helix by apache.
the class TestClusterInMaintenanceModeWhenReachingMaxPartition method testDisableCluster.
@Test
public void testDisableCluster() throws Exception {
ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
ClusterConfig clusterConfig = configAccessor.getClusterConfig(CLUSTER_NAME);
clusterConfig.setMaxPartitionsPerInstance(10);
configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
int i = 0;
for (String stateModel : TestStateModels) {
String db = "Test-DB-" + i++;
createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, _PARTITIONS, _replica, _replica, -1);
_testDBs.add(db);
}
Thread.sleep(100);
Assert.assertTrue(_clusterVerifier.verify());
MaintenanceSignal maintenanceSignal = _dataAccessor.getProperty(_dataAccessor.keyBuilder().maintenance());
Assert.assertNull(maintenanceSignal);
for (i = 2; i < NUM_NODE; i++) {
_participants.get(i).syncStop();
}
Thread.sleep(500);
maintenanceSignal = _dataAccessor.getProperty(_dataAccessor.keyBuilder().maintenance());
Assert.assertNotNull(maintenanceSignal);
Assert.assertNotNull(maintenanceSignal.getReason());
}
use of org.apache.helix.ConfigAccessor in project helix by apache.
the class TestP2PMessageSemiAuto method beforeClass.
@BeforeClass
public void beforeClass() throws InterruptedException {
System.out.println("START " + getShortClassName() + " at " + new Date(System.currentTimeMillis()));
// setup storage cluster
_gSetupTool.addCluster(CLUSTER_NAME, true);
for (int i = 0; i < PARTICIPANT_NUMBER; i++) {
String instance = PARTICIPANT_PREFIX + "_" + (PARTICIPANT_START_PORT + i);
_gSetupTool.addInstanceToCluster(CLUSTER_NAME, instance);
_instances.add(instance);
}
// start dummy participants
for (int i = 0; i < PARTICIPANT_NUMBER; i++) {
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, _instances.get(i));
participant.setTransition(new DelayedTransitionBase(50));
participant.syncStart();
_participants.add(participant);
}
createDBInSemiAuto(_gSetupTool, CLUSTER_NAME, DB_NAME_1, _instances, BuiltInStateModelDefinitions.MasterSlave.name(), PARTITION_NUMBER, REPLICA_NUMBER);
createDBInSemiAuto(_gSetupTool, CLUSTER_NAME, DB_NAME_2, _instances, BuiltInStateModelDefinitions.MasterSlave.name(), PARTITION_NUMBER, REPLICA_NUMBER);
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
_clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkClient(_gZkClient).build();
Assert.assertTrue(_clusterVerifier.verify());
_configAccessor = new ConfigAccessor(_gZkClient);
_accessor = new ZKHelixDataAccessor(CLUSTER_NAME, _baseAccessor);
}
Aggregations