String tableKey = server + DELIMITER + db + DELIMITER + table;
Map<String, Map<String, Collection<WaitingAction>>> partKeyPatterns = missingDeps.get(tableKey);
if (partKeyPatterns == null) {
LOG.warn("Got partition available notification for " + tableKey
+ ". Unexpected and should not be listening to topic. Unregistering topic");
HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class);
hcatService.unregisterFromNotification(server, db, table);
return null;
}
Collection<String> actionsWithAvailDep = new HashSet<String>();
List<String> partKeysToRemove = new ArrayList<String>();
StringBuilder partValSB = new StringBuilder();
synchronized (partKeyPatterns) {
// If partition patterns are date, date;country and date;country;state,
// construct the partition values for each pattern from the available partitions map and
// for the matching value in the dependency map, get the waiting actions.
for (Entry<String, Map<String, Collection<WaitingAction>>> entry : partKeyPatterns.entrySet()) {
String[] partKeys = entry.getKey().split(DELIMITER);
partValSB.setLength(0);
for (String key : partKeys) {
partValSB.append(partitions.get(key)).append(DELIMITER);
}
partValSB.setLength(partValSB.length() - 1);
Map<String, Collection<WaitingAction>> partValues = entry.getValue();
String partVal = partValSB.toString();
Collection<WaitingAction> wActions = entry.getValue().get(partVal);
if (wActions == null)
continue;
for (WaitingAction wAction : wActions) {
String actionID = wAction.getActionID();
actionsWithAvailDep.add(actionID);
Collection<String> depURIs = availableDeps.get(actionID);
if (depURIs == null) {
depURIs = new ArrayList<String>();
Collection<String> existing = availableDeps.putIfAbsent(actionID, depURIs);
if (existing != null) {
depURIs = existing;
}
}
synchronized (depURIs) {
depURIs.add(wAction.getDependencyURI());
availableDeps.put(actionID, depURIs);
}
}
partValues.remove(partVal);
if (partValues.isEmpty()) {
partKeysToRemove.add(entry.getKey());
}
}
for (String partKey : partKeysToRemove) {
partKeyPatterns.remove(partKey);
}
if (partKeyPatterns.isEmpty()) {
missingDeps.remove(tableKey);
// Close JMS session. Stop listening on topic
HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class);
hcatService.unregisterFromNotification(server, db, table);
}
}
return actionsWithAvailDep;
}