@Test public void testIsExternalViewConverged() { String offlineTableName = "testTable_OFFLINE"; Map<String, Map<String, String>> externalViewSegmentStates = new TreeMap<>(); Map<String, Map<String, String>> idealStateSegmentStates = new TreeMap<>(); assertTrue(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, false)); assertTrue(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, true)); Map<String, String> instanceStateMap = new TreeMap<>(); instanceStateMap.put("instance1", ONLINE); externalViewSegmentStates.put("segment1", instanceStateMap); assertTrue(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, false)); assertTrue(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, true)); instanceStateMap = new TreeMap<>(); instanceStateMap.put("instance1", OFFLINE); idealStateSegmentStates.put("segment2", instanceStateMap); assertTrue(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, false)); assertTrue(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, true)); instanceStateMap.put("instance2", CONSUMING); assertFalse(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, false)); assertFalse(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, true)); instanceStateMap = new TreeMap<>(); externalViewSegmentStates.put("segment2", instanceStateMap); assertFalse(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, false)); assertFalse(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, true)); instanceStateMap.put("instance2", OFFLINE); assertFalse(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, false)); assertFalse(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, true)); instanceStateMap.put("instance2", CONSUMING); assertTrue(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, false)); assertTrue(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, true)); instanceStateMap.put("instance3", CONSUMING); assertTrue(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, false)); assertTrue(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, true)); instanceStateMap.put("instance2", ERROR); try { TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, false); fail(); } catch (Exception e) { } assertTrue(TableRebalancer .isExternalViewConverged(offlineTableName, externalViewSegmentStates, idealStateSegmentStates, true)); }
@VisibleForTesting static boolean isExternalViewConverged(String tableNameWithType, Map<String, Map<String, String>> externalViewSegmentStates, Map<String, Map<String, String>> idealStateSegmentStates, boolean bestEfforts) { for (Map.Entry<String, Map<String, String>> entry : idealStateSegmentStates.entrySet()) { String segmentName = entry.getKey(); Map<String, String> externalViewInstanceStateMap = externalViewSegmentStates.get(segmentName); Map<String, String> idealStateInstanceStateMap = entry.getValue(); for (Map.Entry<String, String> instanceStateEntry : idealStateInstanceStateMap.entrySet()) { String idealStateInstanceState = instanceStateEntry.getValue(); if (idealStateInstanceState.equals(SegmentStateModel.OFFLINE)) { continue; } if (externalViewInstanceStateMap == null) { return false; } String instanceName = instanceStateEntry.getKey(); String externalViewInstanceState = externalViewInstanceStateMap.get(instanceName); if (!idealStateInstanceState.equals(externalViewInstanceState)) { if (SegmentStateModel.ERROR.equals(externalViewInstanceState)) { if (bestEfforts) { LOGGER .warn("Found ERROR instance: {} for segment: {}, table: {}, counting it as good state (best-efforts)", instanceName, segmentName, tableNameWithType); } else { LOGGER.warn("Found ERROR instance: {} for segment: {}, table: {}", instanceName, segmentName, tableNameWithType); throw new IllegalStateException("Found segments in ERROR state"); } } else { return false; } } } } return true; }
TableRebalancer { @VisibleForTesting static boolean isExternalViewConverged(String tableNameWithType, Map<String, Map<String, String>> externalViewSegmentStates, Map<String, Map<String, String>> idealStateSegmentStates, boolean bestEfforts) { for (Map.Entry<String, Map<String, String>> entry : idealStateSegmentStates.entrySet()) { String segmentName = entry.getKey(); Map<String, String> externalViewInstanceStateMap = externalViewSegmentStates.get(segmentName); Map<String, String> idealStateInstanceStateMap = entry.getValue(); for (Map.Entry<String, String> instanceStateEntry : idealStateInstanceStateMap.entrySet()) { String idealStateInstanceState = instanceStateEntry.getValue(); if (idealStateInstanceState.equals(SegmentStateModel.OFFLINE)) { continue; } if (externalViewInstanceStateMap == null) { return false; } String instanceName = instanceStateEntry.getKey(); String externalViewInstanceState = externalViewInstanceStateMap.get(instanceName); if (!idealStateInstanceState.equals(externalViewInstanceState)) { if (SegmentStateModel.ERROR.equals(externalViewInstanceState)) { if (bestEfforts) { LOGGER .warn("Found ERROR instance: {} for segment: {}, table: {}, counting it as good state (best-efforts)", instanceName, segmentName, tableNameWithType); } else { LOGGER.warn("Found ERROR instance: {} for segment: {}, table: {}", instanceName, segmentName, tableNameWithType); throw new IllegalStateException("Found segments in ERROR state"); } } else { return false; } } } } return true; } }
TableRebalancer { @VisibleForTesting static boolean isExternalViewConverged(String tableNameWithType, Map<String, Map<String, String>> externalViewSegmentStates, Map<String, Map<String, String>> idealStateSegmentStates, boolean bestEfforts) { for (Map.Entry<String, Map<String, String>> entry : idealStateSegmentStates.entrySet()) { String segmentName = entry.getKey(); Map<String, String> externalViewInstanceStateMap = externalViewSegmentStates.get(segmentName); Map<String, String> idealStateInstanceStateMap = entry.getValue(); for (Map.Entry<String, String> instanceStateEntry : idealStateInstanceStateMap.entrySet()) { String idealStateInstanceState = instanceStateEntry.getValue(); if (idealStateInstanceState.equals(SegmentStateModel.OFFLINE)) { continue; } if (externalViewInstanceStateMap == null) { return false; } String instanceName = instanceStateEntry.getKey(); String externalViewInstanceState = externalViewInstanceStateMap.get(instanceName); if (!idealStateInstanceState.equals(externalViewInstanceState)) { if (SegmentStateModel.ERROR.equals(externalViewInstanceState)) { if (bestEfforts) { LOGGER .warn("Found ERROR instance: {} for segment: {}, table: {}, counting it as good state (best-efforts)", instanceName, segmentName, tableNameWithType); } else { LOGGER.warn("Found ERROR instance: {} for segment: {}, table: {}", instanceName, segmentName, tableNameWithType); throw new IllegalStateException("Found segments in ERROR state"); } } else { return false; } } } } return true; } TableRebalancer(HelixManager helixManager); }
TableRebalancer { @VisibleForTesting static boolean isExternalViewConverged(String tableNameWithType, Map<String, Map<String, String>> externalViewSegmentStates, Map<String, Map<String, String>> idealStateSegmentStates, boolean bestEfforts) { for (Map.Entry<String, Map<String, String>> entry : idealStateSegmentStates.entrySet()) { String segmentName = entry.getKey(); Map<String, String> externalViewInstanceStateMap = externalViewSegmentStates.get(segmentName); Map<String, String> idealStateInstanceStateMap = entry.getValue(); for (Map.Entry<String, String> instanceStateEntry : idealStateInstanceStateMap.entrySet()) { String idealStateInstanceState = instanceStateEntry.getValue(); if (idealStateInstanceState.equals(SegmentStateModel.OFFLINE)) { continue; } if (externalViewInstanceStateMap == null) { return false; } String instanceName = instanceStateEntry.getKey(); String externalViewInstanceState = externalViewInstanceStateMap.get(instanceName); if (!idealStateInstanceState.equals(externalViewInstanceState)) { if (SegmentStateModel.ERROR.equals(externalViewInstanceState)) { if (bestEfforts) { LOGGER .warn("Found ERROR instance: {} for segment: {}, table: {}, counting it as good state (best-efforts)", instanceName, segmentName, tableNameWithType); } else { LOGGER.warn("Found ERROR instance: {} for segment: {}, table: {}", instanceName, segmentName, tableNameWithType); throw new IllegalStateException("Found segments in ERROR state"); } } else { return false; } } } } return true; } TableRebalancer(HelixManager helixManager); RebalanceResult rebalance(TableConfig tableConfig, Configuration rebalanceConfig); }
TableRebalancer { @VisibleForTesting static boolean isExternalViewConverged(String tableNameWithType, Map<String, Map<String, String>> externalViewSegmentStates, Map<String, Map<String, String>> idealStateSegmentStates, boolean bestEfforts) { for (Map.Entry<String, Map<String, String>> entry : idealStateSegmentStates.entrySet()) { String segmentName = entry.getKey(); Map<String, String> externalViewInstanceStateMap = externalViewSegmentStates.get(segmentName); Map<String, String> idealStateInstanceStateMap = entry.getValue(); for (Map.Entry<String, String> instanceStateEntry : idealStateInstanceStateMap.entrySet()) { String idealStateInstanceState = instanceStateEntry.getValue(); if (idealStateInstanceState.equals(SegmentStateModel.OFFLINE)) { continue; } if (externalViewInstanceStateMap == null) { return false; } String instanceName = instanceStateEntry.getKey(); String externalViewInstanceState = externalViewInstanceStateMap.get(instanceName); if (!idealStateInstanceState.equals(externalViewInstanceState)) { if (SegmentStateModel.ERROR.equals(externalViewInstanceState)) { if (bestEfforts) { LOGGER .warn("Found ERROR instance: {} for segment: {}, table: {}, counting it as good state (best-efforts)", instanceName, segmentName, tableNameWithType); } else { LOGGER.warn("Found ERROR instance: {} for segment: {}, table: {}", instanceName, segmentName, tableNameWithType); throw new IllegalStateException("Found segments in ERROR state"); } } else { return false; } } } } return true; } TableRebalancer(HelixManager helixManager); RebalanceResult rebalance(TableConfig tableConfig, Configuration rebalanceConfig);  }