use of org.apache.solr.cloud.rule.ReplicaAssigner in project lucene-solr by apache.
the class Assign method getNodesViaRules.
private static List<ReplicaCount> getNodesViaRules(ClusterState clusterState, String shard, int numberOfNodes, CoreContainer cc, DocCollection coll, List<String> createNodeList, List l) {
ArrayList<Rule> rules = new ArrayList<>();
for (Object o : l) rules.add(new Rule((Map) o));
Map<String, Map<String, Integer>> shardVsNodes = new LinkedHashMap<>();
for (Slice slice : coll.getSlices()) {
LinkedHashMap<String, Integer> n = new LinkedHashMap<>();
shardVsNodes.put(slice.getName(), n);
for (Replica replica : slice.getReplicas()) {
Integer count = n.get(replica.getNodeName());
if (count == null)
count = 0;
n.put(replica.getNodeName(), ++count);
}
}
List snitches = (List) coll.get(DocCollection.SNITCH);
List<String> nodesList = createNodeList == null ? new ArrayList<>(clusterState.getLiveNodes()) : createNodeList;
Map<ReplicaAssigner.Position, String> positions = new ReplicaAssigner(rules, Collections.singletonMap(shard, numberOfNodes), snitches, shardVsNodes, nodesList, cc, clusterState).getNodeMappings();
List<ReplicaCount> repCounts = new ArrayList<>();
for (String s : positions.values()) {
repCounts.add(new ReplicaCount(s));
}
return repCounts;
}
use of org.apache.solr.cloud.rule.ReplicaAssigner in project lucene-solr by apache.
the class OverseerCollectionMessageHandler method identifyNodes.
Map<Position, String> identifyNodes(ClusterState clusterState, List<String> nodeList, ZkNodeProps message, List<String> shardNames, int numNrtReplicas, int numTlogReplicas, int numPullReplicas) throws IOException {
List<Map> rulesMap = (List) message.get("rule");
if (rulesMap == null) {
int i = 0;
Map<Position, String> result = new HashMap<>();
for (String aShard : shardNames) {
for (int j = 0; j < numNrtReplicas; j++) {
result.put(new Position(aShard, j, Replica.Type.NRT), nodeList.get(i % nodeList.size()));
i++;
}
for (int j = 0; j < numTlogReplicas; j++) {
result.put(new Position(aShard, j, Replica.Type.TLOG), nodeList.get(i % nodeList.size()));
i++;
}
for (int j = 0; j < numPullReplicas; j++) {
result.put(new Position(aShard, j, Replica.Type.PULL), nodeList.get(i % nodeList.size()));
i++;
}
}
return result;
} else {
if (numTlogReplicas + numPullReplicas != 0) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, Replica.Type.TLOG + " or " + Replica.Type.PULL + " replica types not supported with placement rules");
}
}
List<Rule> rules = new ArrayList<>();
for (Object map : rulesMap) rules.add(new Rule((Map) map));
Map<String, Integer> sharVsReplicaCount = new HashMap<>();
for (String shard : shardNames) sharVsReplicaCount.put(shard, numNrtReplicas);
ReplicaAssigner replicaAssigner = new ReplicaAssigner(rules, sharVsReplicaCount, (List<Map>) message.get(SNITCH), //this is a new collection. So, there are no nodes in any shard
new HashMap<>(), nodeList, overseer.getZkController().getCoreContainer(), clusterState);
return replicaAssigner.getNodeMappings();
}
Aggregations