You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2017/06/26 19:03:19 UTC

lucene-solr:feature/autoscaling: SOLR-10496: Add a test for multiple operations suggested by three different cluster policies

Repository: lucene-solr
Updated Branches:
  refs/heads/feature/autoscaling 72cf7dc2f -> 4c47a3295


SOLR-10496: Add a test for multiple operations suggested by three different cluster policies


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/4c47a329
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/4c47a329
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/4c47a329

Branch: refs/heads/feature/autoscaling
Commit: 4c47a329507409f7412467e6f26912041fe28ea8
Parents: 72cf7dc
Author: Shalin Shekhar Mangar <sh...@apache.org>
Authored: Tue Jun 27 00:33:10 2017 +0530
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Tue Jun 27 00:33:10 2017 +0530

----------------------------------------------------------------------
 .../solr/cloud/autoscaling/TestPolicy.java      | 137 ++++++++++++++++++-
 1 file changed, 135 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4c47a329/solr/solrj/src/test/org/apache/solr/cloud/autoscaling/TestPolicy.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/cloud/autoscaling/TestPolicy.java b/solr/solrj/src/test/org/apache/solr/cloud/autoscaling/TestPolicy.java
index fd49082..440cd29 100644
--- a/solr/solrj/src/test/org/apache/solr/cloud/autoscaling/TestPolicy.java
+++ b/solr/solrj/src/test/org/apache/solr/cloud/autoscaling/TestPolicy.java
@@ -88,9 +88,9 @@ public class TestPolicy extends SolrTestCaseJ4 {
       "            'node_name':'node1'," +
       "            'state':'active'}}}}}}";
 
-  public static Map<String, Map<String, List<Policy.ReplicaInfo>>> getReplicaDetails(String node, String s) {
+  public static Map<String, Map<String, List<Policy.ReplicaInfo>>> getReplicaDetails(String node, String clusterState) {
     ValidatingJsonMap m = ValidatingJsonMap
-        .getDeepCopy((Map) Utils.fromJSONString(s), 6, true);
+        .getDeepCopy((Map) Utils.fromJSONString(clusterState), 6, true);
     Map<String, Map<String, List<Policy.ReplicaInfo>>> result = new LinkedHashMap<>();
 
     m.forEach((collName, o) -> {
@@ -259,6 +259,139 @@ public class TestPolicy extends SolrTestCaseJ4 {
     assertEquals( "127.0.0.1:65434_solr",op.getParams().get("targetNode") );
   }
 
+  public void testNodeLostMultipleReplica() {
+    String nodeValues = " {" +
+        "    'node4':{" +
+        "      'node':'10.0.0.4:8987_solr'," +
+        "      'cores':1," +
+        "      'freedisk':884.7097854614258}," +
+        "    'node3':{" +
+        "      'node':'10.0.0.4:8989_solr'," +
+        "      'cores':1," +
+        "      'freedisk':884.7097854614258}," +
+        "    'node2':{" +
+        "      'node':'10.0.0.4:7574_solr'," +
+        "      'cores':1," +
+        "      'freedisk':884.7097854614258}," +
+        "}";
+
+    ClusterDataProvider provider = getClusterDataProvider((Map<String, Map>) Utils.fromJSONString(nodeValues), clusterState);
+    Map policies = (Map) Utils.fromJSONString("{" +
+        "  'cluster-preferences': [" +
+        "    { 'maximize': 'freedisk', 'precision': 50}," +
+        "    { 'minimize': 'cores', 'precision': 50}" +
+        "  ]," +
+        "  'cluster-policy': [" +
+        "    { 'replica': 0, 'nodeRole': 'overseer'}" +
+        "    { 'replica': '<2', 'shard': '#EACH', 'node': '#ANY'}," +
+        "  ]" +
+        "}");
+    AutoScalingConfig config = new AutoScalingConfig(policies);
+    Policy policy = config.getPolicy();
+    Policy.Session session = policy.createSession(provider);
+    Policy.Suggester suggester = session.getSuggester(MOVEREPLICA)
+        .hint(Hint.SRC_NODE, "node1");
+
+    SolrRequest operation = suggester.getOperation();
+    assertNotNull(operation);
+    assertEquals("node2", operation.getParams().get("targetNode"));
+
+    session = suggester.getSession();
+    suggester = session.getSuggester(MOVEREPLICA)
+        .hint(Hint.SRC_NODE, "node1");
+    operation = suggester.getOperation();
+    assertNotNull(operation);
+    assertEquals("node3", operation.getParams().get("targetNode"));
+
+    session = suggester.getSession();
+    suggester = session.getSuggester(MOVEREPLICA)
+        .hint(Hint.SRC_NODE, "node1");
+    operation = suggester.getOperation();
+    assertNull(operation);
+
+    // lets change the policy such that all replicas that were on node1
+    // can now fit on node2
+    policies = (Map) Utils.fromJSONString("{" +
+        "  'cluster-preferences': [" +
+        "    { 'maximize': 'freedisk', 'precision': 50}," +
+        "    { 'minimize': 'cores', 'precision': 50}" +
+        "  ]," +
+        "  'cluster-policy': [" +
+        "    { 'replica': 0, 'nodeRole': 'overseer'}" +
+        "    { 'replica': '<3', 'shard': '#EACH', 'node': '#ANY'}," +
+        "  ]" +
+        "}");
+    config = new AutoScalingConfig(policies);
+    policy = config.getPolicy();
+    session = policy.createSession(provider);
+    suggester = session.getSuggester(MOVEREPLICA)
+        .hint(Hint.SRC_NODE, "node1");
+
+    operation = suggester.getOperation();
+    assertNotNull(operation);
+    assertEquals("node2", operation.getParams().get("targetNode"));
+    assertEquals("r3", operation.getParams().get("replica"));
+
+    session = suggester.getSession();
+    suggester = session.getSuggester(MOVEREPLICA)
+        .hint(Hint.SRC_NODE, "node1");
+    operation = suggester.getOperation();
+    assertNotNull(operation);
+    assertEquals("node2", operation.getParams().get("targetNode"));
+    assertEquals("r5", operation.getParams().get("replica"));
+
+    session = suggester.getSession();
+    suggester = session.getSuggester(MOVEREPLICA)
+        .hint(Hint.SRC_NODE, "node1");
+    operation = suggester.getOperation();
+    assertEquals("node2", operation.getParams().get("targetNode"));
+    assertEquals("r1", operation.getParams().get("replica"));
+
+    session = suggester.getSession();
+    suggester = session.getSuggester(MOVEREPLICA)
+        .hint(Hint.SRC_NODE, "node1");
+    operation = suggester.getOperation();
+    assertNull(operation);
+
+    // now lets change the policy such that a node can have 2 shard2 replicas
+    policies = (Map) Utils.fromJSONString("{" +
+        "  'cluster-preferences': [" +
+        "    { 'maximize': 'freedisk', 'precision': 50}," +
+        "    { 'minimize': 'cores', 'precision': 50}" +
+        "  ]," +
+        "  'cluster-policy': [" +
+        "    { 'replica': 0, 'nodeRole': 'overseer'}" +
+        "    { 'replica': '<2', 'shard': 'shard1', 'node': '#ANY'}," +
+        "    { 'replica': '<3', 'shard': 'shard2', 'node': '#ANY'}," +
+        "  ]" +
+        "}");
+    config = new AutoScalingConfig(policies);
+    policy = config.getPolicy();
+    session = policy.createSession(provider);
+    suggester = session.getSuggester(MOVEREPLICA)
+        .hint(Hint.SRC_NODE, "node1");
+
+    operation = suggester.getOperation();
+    assertNotNull(operation);
+    assertEquals("node2", operation.getParams().get("targetNode"));
+    assertEquals("r3", operation.getParams().get("replica"));
+
+    session = suggester.getSession();
+    suggester = session.getSuggester(MOVEREPLICA)
+        .hint(Hint.SRC_NODE, "node1");
+    operation = suggester.getOperation();
+    assertNotNull(operation);
+    assertEquals("node2", operation.getParams().get("targetNode"));
+    assertEquals("r5", operation.getParams().get("replica"));
+
+    session = suggester.getSession();
+    suggester = session.getSuggester(MOVEREPLICA)
+        .hint(Hint.SRC_NODE, "node1");
+    operation = suggester.getOperation();
+    assertEquals("node3", operation.getParams().get("targetNode"));
+    assertEquals("r1", operation.getParams().get("replica"));
+  }
+
   private static ClusterDataProvider dataProviderWithData(String data){
     final Map m = (Map) Utils.fromJSONString(data);
     Map replicaInfo = (Map) m.get("replicaInfo");