public static StashTimeKey of(String id, String datacenter) { return new StashTimeKey(id, datacenter); }
public static StashTimeKey fromString(String stashTimeKeyString) { String[] stashTimeKeyStringSplits = stashTimeKeyString.split(ZK_STRING_DELIMITER); if (stashTimeKeyStringSplits.length != 2) { throw new IllegalStateException("key string can only contain one '@' character. Pattern is ID@datacenter"); } return StashTimeKey.of(stashTimeKeyStringSplits[0], stashTimeKeyStringSplits[1]); } }
@VisibleForTesting void deleteExpiredStashTimes(long currentTimeInMillis) { try { _log.debug("Checking for expired stash times at {}", currentTimeInMillis); Map<StashTimeKey, StashRunTimeInfo> expiredStashTimes = _compactionControlSource.getAllStashTimes().entrySet().stream() .filter(entry -> entry.getValue().getExpiredTimestamp() < currentTimeInMillis).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); for (Map.Entry<StashTimeKey, StashRunTimeInfo> expiredStashTimeInfo : expiredStashTimes.entrySet()) { // If we are deleting the entries here, then there could be a problem which we may want to know. So setting it as a warn. _log.warn("Deleting the stash time entry for id: {} and datacenter: {}", expiredStashTimeInfo.getKey().getId(), expiredStashTimeInfo.getKey().getDatacenter()); _compactionControlSource.deleteStashTime(expiredStashTimeInfo.getKey().getId(), expiredStashTimeInfo.getValue().getDataCenter()); } } catch (Exception e) { _log.error("Unexpected exception deleting the expired stash times", e); } } }
@VisibleForTesting protected static Map<StashTimeKey, StashRunTimeInfo> getStashTimesWithTupleKeys(Map<String, StashRunTimeInfo> stashTimesFromZk) { Map<StashTimeKey, StashRunTimeInfo> allStashTimes = Maps.newHashMap(); for (Map.Entry<String, StashRunTimeInfo> stashTimeFromZk : stashTimesFromZk.entrySet()) { allStashTimes.put(StashTimeKey.fromString(stashTimeFromZk.getKey()), stashTimeFromZk.getValue()); } return allStashTimes; } }
@VisibleForTesting protected static Map<StashTimeKey, StashRunTimeInfo> getStashTimesWithTupleKeys(Map<String, StashRunTimeInfo> stashTimesFromZk) { Map<StashTimeKey, StashRunTimeInfo> allStashTimes = Maps.newHashMap(); for (Map.Entry<String, StashRunTimeInfo> stashTimeFromZk : stashTimesFromZk.entrySet()) { allStashTimes.put(StashTimeKey.fromString(stashTimeFromZk.getKey()), stashTimeFromZk.getValue()); } return allStashTimes; } }