use of org.apache.solr.cloud.rule.ReplicaAssigner.Position in project lucene-solr by apache.
the class RuleEngineTest method testPlacement3.
public void testPlacement3() {
String s = "{" + " '127.0.0.1:49961_':{" + " 'node':'127.0.0.1:49961_'," + " 'freedisk':992," + " 'cores':1}," + " '127.0.0.2:49955_':{" + " 'node':'127.0.0.1:49955_'," + " 'freedisk':995," + " 'cores':1}," + " '127.0.0.3:49952_':{" + " 'node':'127.0.0.1:49952_'," + " 'freedisk':990," + " 'cores':1}," + " '127.0.0.1:49947_':{" + " 'node':'127.0.0.1:49947_'," + " 'freedisk':980," + " 'cores':1}," + " '127.0.0.2:49958_':{" + " 'node':'127.0.0.1:49958_'," + " 'freedisk':970," + " 'cores':1}}";
MockSnitch.nodeVsTags = (Map) Utils.fromJSON(s.getBytes(StandardCharsets.UTF_8));
//test not
List<Rule> rules = parseRules("[{cores:'<4'}, " + "{replica:'1',shard:'*',node:'*'}," + "{node:'!127.0.0.1:49947_'}," + "{freedisk:'>1'}]");
Map shardVsReplicaCount = makeMap("shard1", 2, "shard2", 2);
Map<Position, String> mapping = new ReplicaAssigner(rules, shardVsReplicaCount, singletonList(MockSnitch.class.getName()), new HashMap(), new ArrayList<>(MockSnitch.nodeVsTags.keySet()), null, null).getNodeMappings();
assertNotNull(mapping);
assertFalse(mapping.containsValue("127.0.0.1:49947_"));
rules = parseRules("[{cores:'<4'}, " + "{replica:'1',node:'*'}," + "{freedisk:'>980'}]");
shardVsReplicaCount = makeMap("shard1", 2, "shard2", 2);
mapping = new ReplicaAssigner(rules, shardVsReplicaCount, singletonList(MockSnitch.class.getName()), new HashMap(), new ArrayList<>(MockSnitch.nodeVsTags.keySet()), null, null).getNodeMappings0();
assertNull(mapping);
rules = parseRules("[{cores:'<4'}, " + "{replica:'1',node:'*'}," + "{freedisk:'>980~'}]");
shardVsReplicaCount = makeMap("shard1", 2, "shard2", 2);
mapping = new ReplicaAssigner(rules, shardVsReplicaCount, singletonList(MockSnitch.class.getName()), new HashMap(), new ArrayList<>(MockSnitch.nodeVsTags.keySet()), null, null).getNodeMappings0();
assertNotNull(mapping);
assertFalse(mapping.containsValue("127.0.0.2:49958_"));
rules = parseRules("[{cores:'<4'}, " + "{replica:'1',shard:'*',host:'*'}]");
shardVsReplicaCount = makeMap("shard1", 2, "shard2", 2);
mapping = new ReplicaAssigner(rules, shardVsReplicaCount, singletonList(MockSnitch.class.getName()), new HashMap(), new ArrayList<>(MockSnitch.nodeVsTags.keySet()), null, null).getNodeMappings();
assertNotNull(mapping);
rules = parseRules("[{cores:'<4'}, " + "{replica:'1',shard:'**',host:'*'}]");
shardVsReplicaCount = makeMap("shard1", 2, "shard2", 2);
mapping = new ReplicaAssigner(rules, shardVsReplicaCount, singletonList(MockSnitch.class.getName()), new HashMap(), new ArrayList<>(MockSnitch.nodeVsTags.keySet()), null, null).getNodeMappings0();
assertNull(mapping);
rules = parseRules("[{cores:'<4'}, " + "{replica:'1~',shard:'**',host:'*'}]");
shardVsReplicaCount = makeMap("shard1", 2, "shard2", 2);
mapping = new ReplicaAssigner(rules, shardVsReplicaCount, singletonList(MockSnitch.class.getName()), new HashMap(), new ArrayList<>(MockSnitch.nodeVsTags.keySet()), null, null).getNodeMappings();
assertNotNull(mapping);
}
use of org.apache.solr.cloud.rule.ReplicaAssigner.Position in project lucene-solr by apache.
the class RuleEngineTest method testPlacement2.
@Test
public void testPlacement2() {
String s = "{" + " '127.0.0.1:49961_':{" + " 'node':'127.0.0.1:49961_'," + " 'freedisk':992," + " 'cores':1}," + " '127.0.0.1:49955_':{" + " 'node':'127.0.0.1:49955_'," + " 'freedisk':992," + " 'cores':1}," + " '127.0.0.1:49952_':{" + " 'node':'127.0.0.1:49952_'," + " 'freedisk':992," + " 'cores':1}," + " '127.0.0.1:49947_':{" + " 'node':'127.0.0.1:49947_'," + " 'freedisk':992," + " 'cores':1}," + " '127.0.0.1:49958_':{" + " 'node':'127.0.0.1:49958_'," + " 'freedisk':992," + " 'cores':1}}";
MockSnitch.nodeVsTags = (Map) Utils.fromJSON(s.getBytes(StandardCharsets.UTF_8));
Map shardVsReplicaCount = makeMap("shard1", 2, "shard2", 2);
List<Rule> rules = parseRules("[{'cores':'<4'}, {" + "'replica':'1',shard:'*','node':'*'}," + " {'freedisk':'>1'}]");
Map<Position, String> mapping = new ReplicaAssigner(rules, shardVsReplicaCount, singletonList(MockSnitch.class.getName()), new HashMap(), new ArrayList<>(MockSnitch.nodeVsTags.keySet()), null, null).getNodeMappings();
assertNotNull(mapping);
mapping = new ReplicaAssigner(rules, shardVsReplicaCount, singletonList(MockSnitch.class.getName()), new HashMap(), new ArrayList<>(MockSnitch.nodeVsTags.keySet()), null, null).getNodeMappings();
assertNotNull(mapping);
rules = parseRules("[{role:'!overseer'}, {'freedisk':'>1'}]");
Map<String, Object> snitchSession = new HashMap<>();
List<String> preferredOverseerNodes = ImmutableList.of("127.0.0.1:49947_", "127.0.0.1:49952_");
ReplicaAssigner replicaAssigner = new ReplicaAssigner(rules, shardVsReplicaCount, singletonList(MockSnitch.class.getName()), new HashMap(), new ArrayList<>(MockSnitch.nodeVsTags.keySet()), null, null) {
@Override
protected SnitchContext getSnitchCtx(String node, SnitchInfoImpl info, CoreContainer cc) {
return new ServerSnitchContext(info, node, snitchSession, cc) {
@Override
public Map getZkJson(String path) {
if (ZkStateReader.ROLES.equals(path)) {
return Collections.singletonMap("overseer", preferredOverseerNodes);
}
return null;
}
};
}
};
mapping = replicaAssigner.getNodeMappings();
assertNotNull(mapping);
for (String nodeName : mapping.values()) {
assertFalse(preferredOverseerNodes.contains(nodeName));
}
}
use of org.apache.solr.cloud.rule.ReplicaAssigner.Position in project lucene-solr by apache.
the class RuleEngineTest method testPlacement.
@Test
public void testPlacement() throws Exception {
String rulesStr = "rack:*,replica:<2";
List<Rule> rules = parse(Arrays.asList(rulesStr));
Map shardVsReplicaCount = makeMap("shard1", 3, "shard2", 3);
Map nodeVsTags = makeMap("node1:80", makeMap("rack", "178"), "node2:80", makeMap("rack", "179"), "node3:80", makeMap("rack", "180"), "node4:80", makeMap("rack", "181"), "node5:80", makeMap("rack", "182"));
MockSnitch.nodeVsTags = nodeVsTags;
Map<Position, String> mapping = new ReplicaAssigner(rules, shardVsReplicaCount, singletonList(MockSnitch.class.getName()), new HashMap(), new ArrayList<>(MockSnitch.nodeVsTags.keySet()), null, null).getNodeMappings0();
assertNull(mapping);
rulesStr = "rack:*,replica:<2~";
rules = parse(Arrays.asList(rulesStr));
mapping = new ReplicaAssigner(rules, shardVsReplicaCount, singletonList(MockSnitch.class.getName()), new HashMap(), new ArrayList<>(MockSnitch.nodeVsTags.keySet()), null, null).getNodeMappings();
assertNotNull(mapping);
//for each shard there can be a max of 1 replica
rulesStr = "rack:*,shard:*,replica:<2";
rules = parse(Arrays.asList(rulesStr));
mapping = new ReplicaAssigner(rules, shardVsReplicaCount, singletonList(MockSnitch.class.getName()), new HashMap(), new ArrayList<>(MockSnitch.nodeVsTags.keySet()), null, null).getNodeMappings();
assertNotNull(mapping);
}
use of org.apache.solr.cloud.rule.ReplicaAssigner.Position 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