result.setMapField(partitionName, partitionAssignment); result.setSimpleField(IdealStateProperty.NUM_PARTITIONS.toString(), String.valueOf(partitions)); return result;
/** * Disable (true) or enable (false) External View for this resource. */ public void setDisableExternalView(boolean disableExternalView) { _record .setSimpleField(IdealStateProperty.EXTERNAL_VIEW_DISABLED.name(), Boolean.toString(disableExternalView)); }
result.setMapField(partitionName, partitionAssignment); result.setSimpleField(IdealStateProperty.NUM_PARTITIONS.toString(), String.valueOf(partitions)); return result;
String tag = ResourceUtil.extractSimpleFieldFromZNRecord(idealStateStr, IdealState.IdealStateProperty.INSTANCE_GROUP_TAG.toString()); if (tag != null) { tagMap.put(resourceName, tag);
result.setMapField(partitionName, partitionAssignment); result.setSimpleField(IdealStateProperty.NUM_PARTITIONS.toString(), "" + partitions); return result;
recordNew.setSimpleField(IdealStateProperty.REBALANCE_MODE.toString(), RebalanceMode.SEMI_AUTO.toString()); arg1 = new ZnodeOpArg(pathChild2, ZnodePropertyType.ZNODE, "+", recordNew);
@Test public void testCustomizedIdealStateRebalancer() throws InterruptedException { _gSetupTool.addResourceToCluster(CLUSTER_NAME, db2, 60, "MasterSlave"); _gSetupTool.addResourceProperty(CLUSTER_NAME, db2, IdealStateProperty.REBALANCER_CLASS_NAME.toString(), TestCustomizedIdealStateRebalancer.TestRebalancer.class.getName()); _gSetupTool.addResourceProperty(CLUSTER_NAME, db2, IdealStateProperty.REBALANCE_MODE.toString(), RebalanceMode.USER_DEFINED.toString()); _gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, db2, 3); boolean result = ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient, CLUSTER_NAME, db2)); Assert.assertTrue(result); Thread.sleep(1000); HelixDataAccessor accessor = new ZKHelixDataAccessor(CLUSTER_NAME, new ZkBaseDataAccessor<ZNRecord>(_gZkClient)); Builder keyBuilder = accessor.keyBuilder(); ExternalView ev = accessor.getProperty(keyBuilder.externalView(db2)); Assert.assertEquals(ev.getPartitionSet().size(), 60); for (String partition : ev.getPartitionSet()) { Assert.assertEquals(ev.getStateMap(partition).size(), 1); } IdealState is = accessor.getProperty(keyBuilder.idealStates(db2)); for (String partition : is.getPartitionSet()) { Assert.assertEquals(is.getPreferenceList(partition).size(), 0); Assert.assertEquals(is.getInstanceStateMap(partition).size(), 0); } Assert.assertTrue(testRebalancerCreated); Assert.assertTrue(testRebalancerInvoked); }
@Override public ZNRecord update(ZNRecord currentData) { for (String partitionName : partitions) { List<String> preferenceList = currentData.getListField(partitionName); int numReplicas = Integer.valueOf(currentData.getSimpleField(IdealStateProperty.REPLICAS.toString())); List<String> newPrefList = addInstanceToPreferenceList(preferenceList, instanceName, numReplicas); currentData.setListField(partitionName, newPrefList); prefList.clear(); prefList.addAll(newPrefList); } return currentData; } };
private ZNRecord getExampleZNRecord() { ZNRecord record = new ZNRecord("TestDB"); record.setSimpleField(IdealStateProperty.REBALANCE_MODE.toString(), RebalanceMode.CUSTOMIZED.toString()); Map<String, String> map = new HashMap<String, String>(); map.put("localhost_12918", "MASTER"); map.put("localhost_12919", "SLAVE"); record.setMapField("TestDB_0", map); List<String> list = new ArrayList<String>(); list.add("localhost_12918"); list.add("localhost_12919"); record.setListField("TestDB_0", list); return record; } }
/** * Get the rebalancing mode on this resource * @return {@link RebalanceMode} */ public RebalanceMode getRebalanceMode() { RebalanceMode property = _record.getEnumField(IdealStateProperty.REBALANCE_MODE.toString(), RebalanceMode.class, RebalanceMode.NONE); if (property == RebalanceMode.NONE) { property = normalizeRebalanceMode(getIdealStateMode()); setRebalanceMode(property); } return property; }
/** * Whether the delay rebalance is enabled. * @return */ public boolean isDelayRebalanceEnabled() { boolean disabled = _record.getBooleanField(IdealStateProperty.DELAY_REBALANCE_DISABLED.name(), false); boolean enabled = _record.getBooleanField(ResourceConfigProperty.DELAY_REBALANCE_ENABLED.name(), true); if (disabled) { return false; } return enabled; }
/** * Get the rebalancing mode on this resource * @return {@link RebalanceMode} */ public RebalanceMode getRebalanceMode() { RebalanceMode property = _record.getEnumField(IdealStateProperty.REBALANCE_MODE.toString(), RebalanceMode.class, RebalanceMode.NONE); if (property == RebalanceMode.NONE) { property = normalizeRebalanceMode(getIdealStateMode()); setRebalanceMode(property); } return property; }
private void createISSpec(HelixDataAccessor accessor, String specId, String stateModelDefRef, RebalanceMode rebalanceMode) { PropertyKey propertyKey = accessor.keyBuilder().clusterConfig(); HelixProperty property = accessor.getProperty(propertyKey); if (property == null) { property = new HelixProperty("sampleClusterConfig"); } String key = "IdealStateRule!" + specId; String value = IdealStateProperty.REBALANCE_MODE.toString() + "=" + rebalanceMode.toString() + "," + IdealStateProperty.STATE_MODEL_DEF_REF.toString() + "=" + stateModelDefRef; property.getRecord().setSimpleField(key, value); accessor.setProperty(propertyKey, property); }
@Override public ZNRecord update(ZNRecord currentData) { List<String> preferenceList = currentData.getListField(partitionName); int numReplicas = Integer.valueOf(currentData.getSimpleField(IdealStateProperty.REPLICAS.toString())); List<String> newPrefList = removeInstanceFromPreferenceList(preferenceList, instanceName, numReplicas); currentData.setListField(partitionName, newPrefList); prefList.clear(); prefList.addAll(newPrefList); return currentData; } };
/** * Set the number of minimal active partitions for this resource. * * @param minActiveReplicas */ public void setMinActiveReplicas(int minActiveReplicas) { _record.setIntField(IdealStateProperty.MIN_ACTIVE_REPLICAS.toString(), minActiveReplicas); }
/** * Get the resource group name * * @return */ public String getResourceGroupName() { return _record.getSimpleField(IdealStateProperty.RESOURCE_GROUP_NAME.toString()); }
/** * Get the rebalance strategy for this resource. * * @return rebalance strategy, or null if not specified. */ public String getRebalanceStrategy() { return _record.getSimpleField(IdealStateProperty.REBALANCE_STRATEGY.name()); }
/** * Get the state model factory associated with this resource * @return state model factory name */ public String getStateModelFactoryName() { return _record.getStringField(IdealStateProperty.STATE_MODEL_FACTORY_NAME.toString(), HelixConstants.DEFAULT_STATE_MODEL_FACTORY); }
/** * Get the number of minimal active partitions for this resource. * * @return */ public int getMinActiveReplicas() { return _record.getIntField(IdealStateProperty.MIN_ACTIVE_REPLICAS.toString(), -1); }
/** * Set the state model associated with this resource * @param stateModel state model identifier */ public void setStateModelDefRef(String stateModel) { _record.setSimpleField(IdealStateProperty.STATE_MODEL_DEF_REF.toString(), stateModel); }