use of com.yahoo.collections.ListMap in project vespa by vespa-engine.
the class Dispatcher method hitsByNode.
/**
* Return a map of hits by their search node (partition) id
*/
private static ListMap<Integer, FastHit> hitsByNode(Result result) {
ListMap<Integer, FastHit> hitsByPartition = new ListMap<>();
for (Iterator<Hit> i = result.hits().unorderedDeepIterator(); i.hasNext(); ) {
Hit h = i.next();
if (!(h instanceof FastHit))
continue;
FastHit hit = (FastHit) h;
hitsByPartition.put(hit.getDistributionKey(), hit);
}
return hitsByPartition;
}
use of com.yahoo.collections.ListMap in project vespa by vespa-engine.
the class VersionStatus method findConfigServerVersions.
private static ListMap<Version, String> findConfigServerVersions(Controller controller) {
List<URI> configServers = controller.zoneRegistry().zones().controllerManaged().not().among(ZoneId.from("prod.cd-us-east-1a"), ZoneId.from("prod.aws-us-east-1a")).ids().stream().flatMap(zoneId -> controller.zoneRegistry().getConfigServerUris(zoneId).stream()).collect(Collectors.toList());
ListMap<Version, String> versions = new ListMap<>();
for (URI configServer : configServers) versions.put(controller.applications().configServer().version(configServer), configServer.getHost());
return versions;
}
use of com.yahoo.collections.ListMap in project vespa by vespa-engine.
the class NodeRepository method performOn.
/**
* Performs an operation requiring locking on all nodes matching some filter.
*
* @param filter the filter determining the set of nodes where the operation will be performed
* @param action the action to perform
* @return the set of nodes on which the action was performed, as they became as a result of the operation
*/
private List<Node> performOn(NodeFilter filter, UnaryOperator<Node> action) {
List<Node> unallocatedNodes = new ArrayList<>();
ListMap<ApplicationId, Node> allocatedNodes = new ListMap<>();
// Group matching nodes by the lock needed
for (Node node : db.getNodes()) {
if (!filter.matches(node))
continue;
if (node.allocation().isPresent())
allocatedNodes.put(node.allocation().get().owner(), node);
else
unallocatedNodes.add(node);
}
// perform operation while holding locks
List<Node> resultingNodes = new ArrayList<>();
try (Mutex lock = lockUnallocated()) {
for (Node node : unallocatedNodes) resultingNodes.add(action.apply(node));
}
for (Map.Entry<ApplicationId, List<Node>> applicationNodes : allocatedNodes.entrySet()) {
try (Mutex lock = lock(applicationNodes.getKey())) {
for (Node node : applicationNodes.getValue()) resultingNodes.add(action.apply(node));
}
}
return resultingNodes;
}
Aggregations