public static SegmentMergeLineage fromZNRecord(ZNRecord record) { String tableNameWithType = record.getId(); Map<String, List<String>> segmentGroupLineageMap = record.getListFields(); Map<Integer, Map<String, List<String>>> groupToSegmentsMap = new HashMap<>(); for (Map.Entry<String, Map<String, String>> entry : record.getMapFields().entrySet()) { String levelKey = entry.getKey(); Integer level = Integer.parseInt(levelKey.substring(LEVEL_KEY_PREFIX.length())); Map<String, List<String>> groupToSegmentsForLevel = new HashMap<>(); for (Map.Entry<String, String> groupEntry : entry.getValue().entrySet()) { String groupId = groupEntry.getKey(); String segmentsString = groupEntry.getValue(); List<String> segments = Arrays.asList(segmentsString.split(SEGMENT_DELIMITER)); groupToSegmentsForLevel.put(groupId, new ArrayList<>(segments)); } groupToSegmentsMap.put(level, groupToSegmentsForLevel); } return new SegmentMergeLineage(tableNameWithType, segmentGroupLineageMap, groupToSegmentsMap); }
/** * Read the replica group partition assignment from the property store * @param tableNameWithType a table name * @return Replica group partition assignment */ public ReplicaGroupPartitionAssignment getReplicaGroupPartitionAssignment(String tableNameWithType) { String path = ZKMetadataProvider.constructPropertyStorePathForInstancePartitions(tableNameWithType); ZNRecord replicaGroupPartitionAssignment = _propertyStore.get(path, null, AccessOption.PERSISTENT); ReplicaGroupPartitionAssignment partitionAssignment = null; if (replicaGroupPartitionAssignment != null) { partitionAssignment = new ReplicaGroupPartitionAssignment(tableNameWithType, replicaGroupPartitionAssignment.getListFields()); } return partitionAssignment; }
Map<String, List<String>> listFieldMap1 = record1.getListFields(); Map<String, List<String>> listFieldMap2 = record2.getListFields(); if (listFieldMap1.size() != listFieldMap2.size()) { return false;
/** * Get the preference lists for all partitions * * @return map of lists of instances for all partitions in this resource. */ public Map<String, List<String>> getPreferenceLists() { return _record.getListFields(); }
/** * Get the preference lists for all partitions * * @return map of lists of instances for all partitions in this resource. */ public Map<String, List<String>> getPreferenceLists() { return _record.getListFields(); }
/** * Get the user-specified preference lists for all partitions * * @return map of lists of instances for all partitions in this resource. */ public Map<String, List<String>> getPreferenceLists() { return _record.getListFields(); }
/** * Get the user-specified preference lists for all partitions * * @return map of lists of instances for all partitions in this resource. */ public Map<String, List<String>> getPreferenceLists() { return _record.getListFields(); }
private static void removeListValue(ZNRecord record, String key) { if (record == null || record.getListFields() == null) { record.getListFields().remove(key); } }
private static void removeListValue(ZNRecord record, String key) { if (record == null || record.getListFields() == null) { record.getListFields().remove(key); } }
private static void resetZNRecord(ZNRecord record) { if (record != null) { record.getSimpleFields().clear(); record.getListFields().clear(); record.getMapFields().clear(); } }
private static void resetZNRecord(ZNRecord record) { if (record != null) { record.getSimpleFields().clear(); record.getListFields().clear(); record.getMapFields().clear(); } }
@Override public ZNRecord update(ZNRecord current) { if (current != null) { // Overwrite MapFields and ListFields items with the same key. // Note that default merge will keep old values in the maps or lists unchanged, which is not desired. current.getMapFields().clear(); current.getMapFields().putAll(idealState.getRecord().getMapFields()); current.getListFields().putAll(idealState.getRecord().getListFields()); } return current; } }, idealState);
@Override public ZNRecord update(ZNRecord current) { if (current != null) { // Overwrite MapFields and ListFields items with the same key. // Note that default merge will keep old values in the maps or lists unchanged, which is not desired. current.getMapFields().clear(); current.getMapFields().putAll(idealState.getRecord().getMapFields()); current.getListFields().putAll(idealState.getRecord().getListFields()); } return current; } }, idealState);
/** * Get all of the partitions * @return a set of partition names */ public Set<String> getPartitionSet() { if (getRebalanceMode() == RebalanceMode.SEMI_AUTO || getRebalanceMode() == RebalanceMode.FULL_AUTO || getRebalanceMode() == RebalanceMode.USER_DEFINED || getRebalanceMode() == RebalanceMode.TASK) { return _record.getListFields().keySet(); } else if (getRebalanceMode() == RebalanceMode.CUSTOMIZED) { return _record.getMapFields().keySet(); } else { logger.error("Invalid ideal state mode:" + getResourceName()); return Collections.emptySet(); } }
private static void setZNRecord(ZNRecord diff, ZNRecord record, String keySuffix) { if (diff == null || record == null) { return; } for (String key : record.getSimpleFields().keySet()) { diff.setSimpleField(key + "/" + keySuffix, record.getSimpleField(key)); } for (String key : record.getListFields().keySet()) { diff.setListField(key + "/" + keySuffix, record.getListField(key)); } for (String key : record.getMapFields().keySet()) { diff.setMapField(key + "/" + keySuffix, record.getMapField(key)); } }
private static void setZNRecord(ZNRecord diff, ZNRecord record, String keySuffix) { if (diff == null || record == null) { return; } for (String key : record.getSimpleFields().keySet()) { diff.setSimpleField(key + "/" + keySuffix, record.getSimpleField(key)); } for (String key : record.getListFields().keySet()) { diff.setListField(key + "/" + keySuffix, record.getListField(key)); } for (String key : record.getMapFields().keySet()) { diff.setMapField(key + "/" + keySuffix, record.getMapField(key)); } }
private Set<String> getPartitionsAssignedtoInstance(String cluster, String dbName, String instance) { HelixAdmin admin = _gSetupTool.getClusterManagementTool(); Set<String> partitionSet = new HashSet<String>(); IdealState is = admin.getResourceIdealState(cluster, dbName); for (String partition : is.getRecord().getListFields().keySet()) { List<String> assignments = is.getRecord().getListField(partition); for (String ins : assignments) { if (ins.equals(instance)) { partitionSet.add(partition); } } } return partitionSet; }
private void verifySwapInstance(HelixDataAccessor dataAccessor, String resourceName, IdealState oldIs, String oldInstance, String newInstance, boolean isFullAuto) { IdealState newIs = dataAccessor.getProperty(dataAccessor.keyBuilder().idealStates(resourceName)); if (isFullAuto) { // Full auto resource should not contain new instance as it's not live yet for (String key : newIs.getRecord().getMapFields().keySet()) { Assert.assertFalse(newIs.getRecord().getMapField(key).keySet().contains(newInstance)); } for (String key : newIs.getRecord().getListFields().keySet()) { Assert.assertFalse(newIs.getRecord().getListField(key).contains(newInstance)); } } else { verifyIdealStateWithSwappedInstance(oldIs, newIs, oldInstance, newInstance); } }
private IdealState generateNewIdealState(String resourceName, IdealState currentIdealState, ZNRecord newMapping) { IdealState newIdealState = new IdealState(resourceName); newIdealState.getRecord().setSimpleFields(currentIdealState.getRecord().getSimpleFields()); newIdealState.setRebalanceMode(currentIdealState.getRebalanceMode()); newIdealState.getRecord().setListFields(newMapping.getListFields()); return newIdealState; }
private IdealState generateNewIdealState(String resourceName, IdealState currentIdealState, ZNRecord newMapping) { IdealState newIdealState = new IdealState(resourceName); newIdealState.getRecord().setSimpleFields(currentIdealState.getRecord().getSimpleFields()); newIdealState.setRebalanceMode(currentIdealState.getRebalanceMode()); newIdealState.getRecord().setListFields(newMapping.getListFields()); return newIdealState; }