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 2018/07/23 08:56:26 UTC
lucene-solr:jira/solr-11990: SOLR-11990: Added a test which simulates
a lost node and asserts that move replica suggester moves the replica on the
lost node to a node already having the withCollection present
Repository: lucene-solr
Updated Branches:
refs/heads/jira/solr-11990 582f1fd98 -> 1228538f9
SOLR-11990: Added a test which simulates a lost node and asserts that move replica suggester moves the replica on the lost node to a node already having the withCollection present
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/1228538f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/1228538f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/1228538f
Branch: refs/heads/jira/solr-11990
Commit: 1228538f934f35f15797d89c2c66f2deb9cddd8c
Parents: 582f1fd
Author: Shalin Shekhar Mangar <sh...@apache.org>
Authored: Mon Jul 23 14:26:19 2018 +0530
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Mon Jul 23 14:26:19 2018 +0530
----------------------------------------------------------------------
.../solrj/cloud/autoscaling/TestPolicy.java | 130 +++++++++++++++++++
1 file changed, 130 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1228538f/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java b/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
index 6375222..a3c8311 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
@@ -415,6 +415,136 @@ public class TestPolicy extends SolrTestCaseJ4 {
assertTrue(nodes.contains("node2"));
}
+ public void testWithCollectionMoveReplica() {
+ String clusterStateStr = "{" +
+ " 'comments_coll':{" +
+ " 'router': {" +
+ " 'name': 'compositeId'" +
+ " }," +
+ " 'shards':{" +
+ " 'shard1' : {" +
+ " 'range': '80000000-ffffffff'," +
+ " 'replicas': {" +
+ " 'r1': {" +
+ " 'core': 'r1'," +
+ " 'base_url': 'http://10.0.0.4:8983/solr'," +
+ " 'node_name': 'node1'," +
+ " 'state': 'active'," +
+ " 'leader': 'true'" +
+ " }" +
+ " }" +
+ " }" +
+ " }," +
+ " 'withCollection' :'articles_coll'" +
+ " }," +
+ " 'articles_coll': {" +
+ " 'router': {" +
+ " 'name': 'compositeId'" +
+ " }," +
+ " 'shards': {" +
+ " 'shard1': {" +
+ " 'range': '80000000-ffffffff'," +
+ " 'replicas': {" +
+ " 'r1': {" +
+ " 'core': 'r1'," +
+ " 'base_url': 'http://10.0.0.4:8983/solr'," +
+ " 'node_name': 'node1'," +
+ " 'state': 'active'," +
+ " 'leader': 'true'" +
+ " }," +
+ " 'r2': {" +
+ " 'core': 'r2'," +
+ " 'base_url': 'http://10.0.0.4:7574/solr'," +
+ " 'node_name': 'node2'," +
+ " 'state': 'active'" +
+ " }" +
+ " }" +
+ " }" +
+ " }" +
+ " }" +
+ "}";
+ ClusterState clusterState = ClusterState.load(1, clusterStateStr.getBytes(UTF_8),
+ ImmutableSet.of("node2", "node3", "node4", "node5"));
+ DelegatingClusterStateProvider clusterStateProvider = new DelegatingClusterStateProvider(null) {
+ @Override
+ public ClusterState getClusterState() throws IOException {
+ return clusterState;
+ }
+
+ @Override
+ public Set<String> getLiveNodes() {
+ return clusterState.getLiveNodes();
+ }
+ };
+
+ SolrClientNodeStateProvider solrClientNodeStateProvider = new SolrClientNodeStateProvider(null) {
+ @Override
+ protected Map<String, Object> fetchTagValues(String node, Collection<String> tags) {
+ Map<String, Object> result = new HashMap<>();
+ AtomicInteger cores = new AtomicInteger();
+ forEachReplica(node, replicaInfo -> cores.incrementAndGet());
+ if (tags.contains(ImplicitSnitch.CORES)) result.put(ImplicitSnitch.CORES, cores.get());
+ if (tags.contains(ImplicitSnitch.DISK)) result.put(ImplicitSnitch.DISK, 100);
+ return result;
+ }
+
+ @Override
+ protected Map<String, Object> fetchReplicaMetrics(String solrNode, Map<String, Object> metricsKeyVsTag) {
+ //e.g: solr.core.perReplicaDataColl.shard1.replica_n4:INDEX.sizeInBytes
+ Map<String, Object> result = new HashMap<>();
+ metricsKeyVsTag.forEach((k, v) -> {
+ if (k.endsWith(":INDEX.sizeInBytes")) result.put(k, 100);
+ });
+ return result;
+ }
+
+ @Override
+ protected ClusterStateProvider getClusterStateProvider() {
+ return clusterStateProvider;
+ }
+ };
+ Map m = solrClientNodeStateProvider.getNodeValues("node1", ImmutableSet.of("cores", "withCollection"));
+ assertNotNull(m.get("withCollection"));
+
+ Map policies = (Map) Utils.fromJSONString("{" +
+ " 'cluster-preferences': [" +
+ " { 'minimize': 'cores'}," +
+ " { 'maximize': 'freedisk', '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(new DelegatingCloudManager(null) {
+ @Override
+ public ClusterStateProvider getClusterStateProvider() {
+ return clusterStateProvider;
+ }
+
+ @Override
+ public NodeStateProvider getNodeStateProvider() {
+ return solrClientNodeStateProvider;
+ }
+ });
+ Suggester suggester = session.getSuggester(CollectionAction.MOVEREPLICA);
+ suggester.hint(Hint.COLL_SHARD, new Pair<>("comments_coll", "shard1"));
+ suggester.hint(Hint.SRC_NODE, "node1");
+ SolrRequest op = suggester.getSuggestion();
+ assertNotNull(op);
+ assertEquals("node2 should have been selected by move replica","node2",
+ op.getParams().get("targetNode"));
+
+ session = suggester.getSession();
+ suggester = session.getSuggester(MOVEREPLICA);
+ suggester.hint(Hint.COLL_SHARD, new Pair<>("comments_coll", "shard1"));
+ suggester.hint(Hint.SRC_NODE, "node1");
+ op = suggester.getSuggestion();
+ assertNull(op);
+ }
+
public void testValidate() {
expectError("replica", -1, "must be greater than");
expectError("replica", "hello", "not a valid number");