Java Code Examples for org.apache.solr.common.params.ShardParams#SHARDS_PREFERENCE_REPLICA_BASE

The following examples show how to use org.apache.solr.common.params.ShardParams#SHARDS_PREFERENCE_REPLICA_BASE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodePreferenceRulesComparator.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(Object left, Object right) {
  if (this.sortRules != null) {
    for (PreferenceRule preferenceRule: this.sortRules) {
      final boolean lhs;
      final boolean rhs;
      switch (preferenceRule.name) {
        case ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE:
          lhs = hasReplicaType(left, preferenceRule.value);
          rhs = hasReplicaType(right, preferenceRule.value);
          break;
        case ShardParams.SHARDS_PREFERENCE_REPLICA_LOCATION:
          lhs = hasCoreUrlPrefix(left, preferenceRule.value);
          rhs = hasCoreUrlPrefix(right, preferenceRule.value);
          break;
        case ShardParams.SHARDS_PREFERENCE_NODE_WITH_SAME_SYSPROP:
          if (sysPropsCache == null) {
            throw new IllegalArgumentException("Unable to get the NodesSysPropsCacher on sorting replicas by preference:"+ preferenceRule.value);
          }
          lhs = hasSameMetric(left, preferenceRule.value);
          rhs = hasSameMetric(right, preferenceRule.value);
          break;
        case ShardParams.SHARDS_PREFERENCE_REPLICA_BASE:
          throw new IllegalArgumentException("only one base replica order may be specified in "
              + ShardParams.SHARDS_PREFERENCE + ", and it must be specified last");
        default:
          throw new IllegalArgumentException("Invalid " + ShardParams.SHARDS_PREFERENCE + " type: " + preferenceRule.name);
      }
      if (lhs != rhs) {
        return lhs ? -1 : +1;
      }
    }
  }
  return 0;
}
 
Example 2
Source File: RequestReplicaListTransformerGeneratorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testNodePreferenceRulesBase() {
  RequestReplicaListTransformerGenerator generator = new RequestReplicaListTransformerGenerator();
  ModifiableSolrParams params = new ModifiableSolrParams();
  List<Replica> replicas = getBasicReplicaList();

  String rulesParam = ShardParams.SHARDS_PREFERENCE_REPLICA_BASE + ":stable:dividend:routingPreference";

  params.add("routingPreference", "0");
  params.add(ShardParams.SHARDS_PREFERENCE, rulesParam);

  ReplicaListTransformer rlt = generator.getReplicaListTransformer(params);
  rlt.transform(replicas);
  assertEquals("node1", replicas.get(0).getNodeName());
  assertEquals("node2", replicas.get(1).getNodeName());
  assertEquals("node3", replicas.get(2).getNodeName());

  params.set("routingPreference", "1");
  rlt = generator.getReplicaListTransformer(params);
  rlt.transform(replicas);
  assertEquals("node2", replicas.get(0).getNodeName());
  assertEquals("node3", replicas.get(1).getNodeName());
  assertEquals("node1", replicas.get(2).getNodeName());

  params.set("routingPreference", "2");
  rlt = generator.getReplicaListTransformer(params);
  rlt.transform(replicas);
  assertEquals("node3", replicas.get(0).getNodeName());
  assertEquals("node1", replicas.get(1).getNodeName());
  assertEquals("node2", replicas.get(2).getNodeName());

  params.set("routingPreference", "3");
  rlt = generator.getReplicaListTransformer(params);
  rlt.transform(replicas);
  assertEquals("node1", replicas.get(0).getNodeName());
  assertEquals("node2", replicas.get(1).getNodeName());
  assertEquals("node3", replicas.get(2).getNodeName());
}
 
Example 3
Source File: RequestReplicaListTransformerGeneratorTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void replicaTypeAndReplicaBase() {
  RequestReplicaListTransformerGenerator generator = new RequestReplicaListTransformerGenerator();
  ModifiableSolrParams params = new ModifiableSolrParams();
  List<Replica> replicas = getBasicReplicaList();

  // Add a replica so that sorting by replicaType:TLOG can cause a tie
  replicas.add(
      new Replica(
          "node4",
          map(
              ZkStateReader.BASE_URL_PROP, "http://host2_2:8983/solr",
              ZkStateReader.NODE_NAME_PROP, "node4",
              ZkStateReader.CORE_NAME_PROP, "collection1",
              ZkStateReader.REPLICA_TYPE, "TLOG"
          ), "c1","s1"
      )
  );

  // Add a PULL replica so that there's a tie for "last place"
  replicas.add(
      new Replica(
          "node5",
          map(
              ZkStateReader.BASE_URL_PROP, "http://host2_2:8983/solr",
              ZkStateReader.NODE_NAME_PROP, "node5",
              ZkStateReader.CORE_NAME_PROP, "collection1",
              ZkStateReader.REPLICA_TYPE, "PULL"
          ), "c1","s1"
      )
  );

  // replicaType and replicaBase combined rule param
  String rulesParam = ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":NRT," +
      ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":TLOG," +
      ShardParams.SHARDS_PREFERENCE_REPLICA_BASE + ":stable:dividend:routingPreference";

  params.add("routingPreference", "0");
  params.add(ShardParams.SHARDS_PREFERENCE, rulesParam);
  ReplicaListTransformer rlt = generator.getReplicaListTransformer(params);
  rlt.transform(replicas);
  assertEquals("node1", replicas.get(0).getNodeName());
  assertEquals("node2", replicas.get(1).getNodeName());
  assertEquals("node4", replicas.get(2).getNodeName());
  assertEquals("node3", replicas.get(3).getNodeName());
  assertEquals("node5", replicas.get(4).getNodeName());

  params.set("routingPreference", "1");
  rlt = generator.getReplicaListTransformer(params);
  rlt.transform(replicas);
  assertEquals("node1", replicas.get(0).getNodeName());
  assertEquals("node4", replicas.get(1).getNodeName());
  assertEquals("node2", replicas.get(2).getNodeName());
  assertEquals("node5", replicas.get(3).getNodeName());
  assertEquals("node3", replicas.get(4).getNodeName());
}