Search in sources :

Example 1 with ReplicaAssigner

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;
}
Also used : ArrayList(java.util.ArrayList) ReplicaAssigner(org.apache.solr.cloud.rule.ReplicaAssigner) Replica(org.apache.solr.common.cloud.Replica) LinkedHashMap(java.util.LinkedHashMap) Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) List(java.util.List) Rule(org.apache.solr.cloud.rule.Rule) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with ReplicaAssigner

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();
}
Also used : HashMap(java.util.HashMap) Position(org.apache.solr.cloud.rule.ReplicaAssigner.Position) ArrayList(java.util.ArrayList) ReplicaAssigner(org.apache.solr.cloud.rule.ReplicaAssigner) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) Rule(org.apache.solr.cloud.rule.Rule) Map(java.util.Map) Utils.makeMap(org.apache.solr.common.util.Utils.makeMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) SolrException(org.apache.solr.common.SolrException)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ReplicaAssigner (org.apache.solr.cloud.rule.ReplicaAssigner)2 Rule (org.apache.solr.cloud.rule.Rule)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 LinkedHashMap (java.util.LinkedHashMap)1 RemoteSolrException (org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException)1 Position (org.apache.solr.cloud.rule.ReplicaAssigner.Position)1 SolrException (org.apache.solr.common.SolrException)1 Replica (org.apache.solr.common.cloud.Replica)1 Slice (org.apache.solr.common.cloud.Slice)1 NamedList (org.apache.solr.common.util.NamedList)1 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)1 Utils.makeMap (org.apache.solr.common.util.Utils.makeMap)1