本文整理汇总了Java中org.apache.helix.model.IdealState类的典型用法代码示例。如果您正苦于以下问题:Java IdealState类的具体用法?Java IdealState怎么用?Java IdealState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IdealState类属于org.apache.helix.model包,在下文中一共展示了IdealState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstanceToTopicPartitionsMap
import org.apache.helix.model.IdealState; //导入依赖的package包/类
/**
* From IdealStates.
*
* @return InstanceToNumTopicPartitionMap
*/
public static Map<String, Set<TopicPartition>> getInstanceToTopicPartitionsMap(
HelixManager helixManager) {
Map<String, Set<TopicPartition>> instanceToNumTopicPartitionMap =
new HashMap<String, Set<TopicPartition>>();
HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
String helixClusterName = helixManager.getClusterName();
for (String topic : helixAdmin.getResourcesInCluster(helixClusterName)) {
IdealState is = helixAdmin.getResourceIdealState(helixClusterName, topic);
for (String partition : is.getPartitionSet()) {
TopicPartition tpi = new TopicPartition(topic, Integer.parseInt(partition));
for (String instance : is.getInstanceSet(partition)) {
if (!instanceToNumTopicPartitionMap.containsKey(instance)) {
instanceToNumTopicPartitionMap.put(instance, new HashSet<TopicPartition>());
}
instanceToNumTopicPartitionMap.get(instance).add(tpi);
}
}
}
return instanceToNumTopicPartitionMap;
}
示例2: buildCustomIdealStateFor
import org.apache.helix.model.IdealState; //导入依赖的package包/类
public static IdealState buildCustomIdealStateFor(String topicName,
int numTopicPartitions,
PriorityQueue<InstanceTopicPartitionHolder> instanceToNumServingTopicPartitionMap) {
final CustomModeISBuilder customModeIdealStateBuilder = new CustomModeISBuilder(topicName);
customModeIdealStateBuilder
.setStateModel(OnlineOfflineStateModel.name)
.setNumPartitions(numTopicPartitions).setNumReplica(1)
.setMaxPartitionsPerNode(numTopicPartitions);
for (int i = 0; i < numTopicPartitions; ++i) {
synchronized (instanceToNumServingTopicPartitionMap) {
InstanceTopicPartitionHolder liveInstance = instanceToNumServingTopicPartitionMap.poll();
customModeIdealStateBuilder.assignInstanceAndState(Integer.toString(i),
liveInstance.getInstanceName(), "ONLINE");
liveInstance.addTopicPartition(new TopicPartition(topicName, i));
instanceToNumServingTopicPartitionMap.add(liveInstance);
}
}
return customModeIdealStateBuilder.build();
}
示例3: getUnassignedPartitions
import org.apache.helix.model.IdealState; //导入依赖的package包/类
public static Set<TopicPartition> getUnassignedPartitions(HelixManager helixManager) {
Set<TopicPartition> unassignedPartitions = new HashSet<TopicPartition>();
HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
String helixClusterName = helixManager.getClusterName();
for (String topic : helixAdmin.getResourcesInCluster(helixClusterName)) {
IdealState is = helixAdmin.getResourceIdealState(helixClusterName, topic);
int numPartitions = is.getNumPartitions();
for (int partition = 0; partition < numPartitions; ++partition) {
if (is.getInstanceSet(Integer.toString(partition)).isEmpty()) {
TopicPartition tpi = new TopicPartition(topic, partition);
unassignedPartitions.add(tpi);
}
}
}
return unassignedPartitions;
}
示例4: buildCustomIdealStateFor
import org.apache.helix.model.IdealState; //导入依赖的package包/类
public static IdealState buildCustomIdealStateFor(String topicName,
int numTopicPartitions,
PriorityQueue<InstanceTopicPartitionHolder> instanceToNumServingTopicPartitionMap) {
final CustomModeISBuilder customModeIdealStateBuilder = new CustomModeISBuilder(topicName);
customModeIdealStateBuilder
.setStateModel(OnlineOfflineStateModel.name)
.setNumPartitions(numTopicPartitions).setNumReplica(1)
.setMaxPartitionsPerNode(numTopicPartitions);
for (int i = 0; i < numTopicPartitions; ++i) {
InstanceTopicPartitionHolder liveInstance = instanceToNumServingTopicPartitionMap.poll();
if (liveInstance != null) {
customModeIdealStateBuilder.assignInstanceAndState(Integer.toString(i),
liveInstance.getInstanceName(), "ONLINE");
liveInstance.addTopicPartition(new TopicPartition(topicName, i));
instanceToNumServingTopicPartitionMap.add(liveInstance);
}
}
return customModeIdealStateBuilder.build();
}
示例5: getInstanceToTopicPartitionsMap
import org.apache.helix.model.IdealState; //导入依赖的package包/类
/**
* From IdealStates.
* @param helixManager
* @return InstanceToNumTopicPartitionMap
*/
public static Map<String, Set<TopicPartition>> getInstanceToTopicPartitionsMap(
HelixManager helixManager) {
Map<String, Set<TopicPartition>> instanceToNumTopicPartitionMap =
new HashMap<String, Set<TopicPartition>>();
HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
String helixClusterName = helixManager.getClusterName();
for (String topic : helixAdmin.getResourcesInCluster(helixClusterName)) {
IdealState is = helixAdmin.getResourceIdealState(helixClusterName, topic);
for (String partition : is.getPartitionSet()) {
TopicPartition tpi = new TopicPartition(topic, Integer.parseInt(partition));
for (String instance : is.getInstanceSet(partition)) {
if (!instanceToNumTopicPartitionMap.containsKey(instance)) {
instanceToNumTopicPartitionMap.put(instance, new HashSet<TopicPartition>());
}
instanceToNumTopicPartitionMap.get(instance).add(tpi);
}
}
}
return instanceToNumTopicPartitionMap;
}
示例6: calculateDeviationForResource
import org.apache.helix.model.IdealState; //导入依赖的package包/类
static double calculateDeviationForResource(String resource,
IdealState idealState,
RoutingTableProvider routingTableProvider) {
Set<String> partitions = idealState.getPartitionSet();
int totalAssignments = 0, totalDeviations = 0;
// Check if the external view has deviated from the actual view.
for (String partition : partitions) {
// Make a copy of the instance mapping in the ideal state.
Set<String> idealInstances = new HashSet(idealState.getInstanceSet(partition));
totalAssignments += idealInstances.size();
// Now check against our real state and count the amount of deviating
// assignments.
List<InstanceConfig> currentInstanceConfigs = routingTableProvider.getInstances(
resource, partition, "ONLINE");
Set<String> currentInstances = Sets.newHashSetWithExpectedSize(
currentInstanceConfigs.size());
if (currentInstanceConfigs != null) {
for (InstanceConfig instanceConfig : currentInstanceConfigs) {
currentInstances.add(instanceConfig.getHostName());
}
}
idealInstances.removeAll(currentInstances);
totalDeviations += idealInstances.size();
}
return (double)totalDeviations / totalAssignments;
}
示例7: rebalanceResource
import org.apache.helix.model.IdealState; //导入依赖的package包/类
private void rebalanceResource(String hdfsDir, String resource, FileSetInfo fileSetInfo)
throws Exception {
IdealState idealState = ControllerUtil.buildIdealStateForHdfsDir(
hdfsClient,
hdfsDir,
resource,
fileSetInfo.servingInfo.partitionerType,
configuration.getInt(Constants.NUM_SERVING_REPLICAS, 3),
configuration.getBoolean(Constants.ENABLE_ZK_COMPRESSION,
Constants.ENABLE_ZK_COMPRESSION_DEFAULT));
double deviation = calculateDeviationForResource(resource, idealState, routingTableProvider);
if (deviation > configuration.getDouble(Constants.REBALANCE_DEVIATION_THRESHOLD, 0.0)) {
// Write the new ideal state.
LOG.info("Writing new ideal state for " + resource);
helixAdmin.setResourceIdealState(clusterName, resource, idealState);
} else {
LOG.info("Resource " + resource + " is balanced. Skipping.");
}
}
示例8: matches
import org.apache.helix.model.IdealState; //导入依赖的package包/类
@Override
public boolean matches(Object o) {
if (o == null || !(o instanceof IdealState)) {
return false;
}
IdealState is = (IdealState)o;
if (is.getRebalanceMode() != IdealState.RebalanceMode.CUSTOMIZED ||
!is.getReplicas().equals("3") ||
is.getNumPartitions() != this.numPartitions ||
!is.getStateModelDefRef().equals("OnlineOffline")) {
return false;
}
for (Map.Entry<Integer, List<String>> entry : partitionHostMap.entrySet()) {
Map<String, String> stateMap = is.getInstanceStateMap(
this.resource + "$" + entry.getKey());
if (stateMap.size() != entry.getValue().size()) {
return false;
}
for (String host : entry.getValue()) {
if (!(stateMap.containsKey(host) && stateMap.get(host).equals("ONLINE"))) {
return false;
}
}
}
return true;
}
示例9: deleteSegment
import org.apache.helix.model.IdealState; //导入依赖的package包/类
/**
* TODO : Due to the issue of helix, if remove the segment from idealState directly, the node won't get transaction,
* so we first disable the segment, then remove it from idealState, then enable the segment. This will trigger transactions.
* After the helix patch, we can refine the logic here by directly drop the segment from idealState.
*
* @param tableName
* @param segmentId
* @return
*/
public synchronized PinotResourceManagerResponse deleteSegment(final String tableName, final String segmentId) {
LOGGER.info("Trying to delete segment: {} for table: {} ", segmentId, tableName);
final PinotResourceManagerResponse res = new PinotResourceManagerResponse();
try {
IdealState idealState = _helixAdmin.getResourceIdealState(_helixClusterName, tableName);
if (idealState.getPartitionSet().contains(segmentId)) {
LOGGER.info("Trying to delete segment: {} from IdealStates", segmentId);
HelixHelper.removeSegmentFromIdealState(_helixZkManager, tableName, segmentId);
} else {
res.message = "Segment " + segmentId + " not in IDEALSTATE.";
LOGGER.info("Segment: {} is not in IDEALSTATE", segmentId);
}
_segmentDeletionManager.deleteSegment(tableName, segmentId);
res.message = "Segment successfully deleted.";
res.status = ResponseStatus.success;
} catch (final Exception e) {
LOGGER.error("Caught exception while deleting segment", e);
res.status = ResponseStatus.failure;
res.message = e.getMessage();
}
return res;
}
示例10: isServerTenantDeletable
import org.apache.helix.model.IdealState; //导入依赖的package包/类
public boolean isServerTenantDeletable(String tenantName) {
Set<String> taggedInstances =
new HashSet<String>(_helixAdmin.getInstancesInClusterWithTag(_helixClusterName,
ControllerTenantNameBuilder.getOfflineTenantNameForTenant(tenantName)));
taggedInstances.addAll(_helixAdmin.getInstancesInClusterWithTag(_helixClusterName,
ControllerTenantNameBuilder.getRealtimeTenantNameForTenant(tenantName)));
for (String tableName : getAllTableNames()) {
if (tableName.equals(CommonConstants.Helix.BROKER_RESOURCE_INSTANCE)) {
continue;
}
IdealState tableIdealState = _helixAdmin.getResourceIdealState(_helixClusterName, tableName);
for (String partition : tableIdealState.getPartitionSet()) {
for (String instance : tableIdealState.getInstanceSet(partition)) {
if (taggedInstances.contains(instance)) {
return false;
}
}
}
}
return true;
}
示例11: handleBrokerResource
import org.apache.helix.model.IdealState; //导入依赖的package包/类
private void handleBrokerResource(AbstractTableConfig tableConfig) {
try {
String brokerTenant =
ControllerTenantNameBuilder.getBrokerTenantNameForTenant(tableConfig.getTenantConfig().getBroker());
if (_helixAdmin.getInstancesInClusterWithTag(_helixClusterName, brokerTenant).isEmpty()) {
throw new RuntimeException("broker tenant : " + tableConfig.getTenantConfig().getBroker() + " is not existed!");
}
LOGGER.info("Trying to update BrokerDataResource IdealState!");
final IdealState idealState =
_helixAdmin.getResourceIdealState(_helixClusterName, CommonConstants.Helix.BROKER_RESOURCE_INSTANCE);
String tableName = tableConfig.getTableName();
for (String instanceName : _helixAdmin.getInstancesInClusterWithTag(_helixClusterName, brokerTenant)) {
idealState.setPartitionState(tableName, instanceName, BrokerOnlineOfflineStateModel.ONLINE);
}
if (idealState != null) {
_helixAdmin
.setResourceIdealState(_helixClusterName, CommonConstants.Helix.BROKER_RESOURCE_INSTANCE, idealState);
}
} catch (final Exception e) {
LOGGER.warn("Caught exception while creating broker", e);
}
}
示例12: getInstanceToSegmentsInATableMap
import org.apache.helix.model.IdealState; //导入依赖的package包/类
public Map<String, List<String>> getInstanceToSegmentsInATableMap(String tableName) {
Map<String, List<String>> instancesToSegmentsMap = new HashMap<String, List<String>>();
IdealState is = _helixAdmin.getResourceIdealState(_helixClusterName, tableName);
Set<String> segments = is.getPartitionSet();
for (String segment : segments) {
Set<String> instances = is.getInstanceSet(segment);
for (String instance : instances) {
if (instancesToSegmentsMap.containsKey(instance)) {
instancesToSegmentsMap.get(instance).add(segment);
} else {
List<String> a = new ArrayList<String>();
a.add(segment);
instancesToSegmentsMap.put(instance, a);
}
}
}
return instancesToSegmentsMap;
}
示例13: buildInitialRealtimeIdealStateFor
import org.apache.helix.model.IdealState; //导入依赖的package包/类
public static IdealState buildInitialRealtimeIdealStateFor(String realtimeTableName,
AbstractTableConfig realtimeTableConfig, HelixAdmin helixAdmin, String helixClusterName,
ZkHelixPropertyStore<ZNRecord> zkHelixPropertyStore) {
KafkaStreamMetadata kafkaStreamMetadata =
new KafkaStreamMetadata(realtimeTableConfig.getIndexingConfig().getStreamConfigs());
String realtimeServerTenant =
ControllerTenantNameBuilder.getRealtimeTenantNameForTenant(realtimeTableConfig.getTenantConfig().getServer());
switch (kafkaStreamMetadata.getConsumerType()) {
case highLevel:
IdealState idealState =
buildInitialKafkaHighLevelConsumerRealtimeIdealStateFor(realtimeTableName, helixAdmin, helixClusterName,
zkHelixPropertyStore);
List<String> realtimeInstances = helixAdmin.getInstancesInClusterWithTag(helixClusterName, realtimeServerTenant);
if (realtimeInstances.size() % Integer.parseInt(realtimeTableConfig.getValidationConfig().getReplication()) != 0) {
throw new RuntimeException("Number of instance in current tenant should be an integer multiples of the number of replications");
}
setupInstanceConfigForKafkaHighLevelConsumer(realtimeTableName, realtimeInstances.size(),
Integer.parseInt(realtimeTableConfig.getValidationConfig().getReplication()), realtimeTableConfig
.getIndexingConfig().getStreamConfigs(), zkHelixPropertyStore, realtimeInstances);
return idealState;
case simple:
default:
throw new UnsupportedOperationException("Not support kafka consumer type: "
+ kafkaStreamMetadata.getConsumerType());
}
}
示例14: removeResourceFromBrokerIdealState
import org.apache.helix.model.IdealState; //导入依赖的package包/类
/**
* Remove a resource (offline/realtime table) from the Broker's ideal state.
*
* @param helixManager The HelixManager object for accessing helix cluster.
* @param resourceTag Name of the resource that needs to be removed from Broker ideal state.
*/
public static void removeResourceFromBrokerIdealState(HelixManager helixManager, final String resourceTag) {
Function<IdealState, IdealState> updater = new Function<IdealState, IdealState>() {
@Override
public IdealState apply(IdealState idealState) {
if (idealState.getPartitionSet().contains(resourceTag)) {
idealState.getPartitionSet().remove(resourceTag);
return idealState;
} else {
return null;
}
}
};
// Removing partitions from ideal state
LOGGER.info("Trying to remove resource from idealstats");
HelixHelper.updateIdealState(helixManager, CommonConstants.Helix.BROKER_RESOURCE_INSTANCE, updater,
DEFAULT_RETRY_POLICY);
}
示例15: removeSegmentFromIdealState
import org.apache.helix.model.IdealState; //导入依赖的package包/类
/**
* Remove the segment from the cluster.
*
* @param helixManager The HelixManager object to access the helix cluster.
* @param tableName Name of the table to which the new segment is to be added.
* @param segmentName Name of the new segment to be added
*/
public static void removeSegmentFromIdealState(HelixManager helixManager, String tableName, final String segmentName) {
Function<IdealState, IdealState> updater = new Function<IdealState, IdealState>() {
@Override
public IdealState apply(IdealState idealState) {
final Set<String> currentInstanceSet = idealState.getInstanceSet(segmentName);
if (!currentInstanceSet.isEmpty() && idealState.getPartitionSet().contains(segmentName)) {
idealState.getPartitionSet().remove(segmentName);
return idealState;
} else {
return null;
}
}
};
updateIdealState(helixManager, tableName, updater, DEFAULT_RETRY_POLICY);
}