Java Code Examples for org.apache.solr.common.cloud.Slice#getReplica()

The following examples show how to use org.apache.solr.common.cloud.Slice#getReplica() . 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: RebalanceLeaders.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void rejoinElectionQueue(Slice slice, String electionNode, String core, boolean rejoinAtHead)
    throws KeeperException, InterruptedException {
  Replica replica = slice.getReplica(LeaderElector.getNodeName(electionNode));
  Map<String, Object> propMap = new HashMap<>();
  propMap.put(COLLECTION_PROP, collectionName);
  propMap.put(SHARD_ID_PROP, slice.getName());
  propMap.put(QUEUE_OPERATION, REBALANCELEADERS.toLower());
  propMap.put(CORE_NAME_PROP, core);
  propMap.put(CORE_NODE_NAME_PROP, replica.getName());
  propMap.put(ZkStateReader.BASE_URL_PROP, replica.getProperties().get(ZkStateReader.BASE_URL_PROP));
  propMap.put(REJOIN_AT_HEAD_PROP, Boolean.toString(rejoinAtHead)); // Get ourselves to be first in line.
  propMap.put(ELECTION_NODE_PROP, electionNode);
  String asyncId = REBALANCELEADERS.toLower() + "_" + core + "_" + Math.abs(System.nanoTime());
  propMap.put(ASYNC, asyncId);
  asyncRequests.add(asyncId);

  collectionsHandler.sendToOCPQueue(new ZkNodeProps(propMap)); // ignore response; we construct our own
}
 
Example 2
Source File: ClusterStateMockUtilTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildClusterState_Simple() {
  try (ZkStateReader zkStateReader = ClusterStateMockUtil.buildClusterState("csr", "baseUrl1_")) {
    ClusterState clusterState = zkStateReader.getClusterState();
    assertNotNull(clusterState);
    assertEquals(1, clusterState.getCollectionStates().size());
    DocCollection collection1 = clusterState.getCollectionOrNull("collection1");
    assertNotNull(collection1);
    assertEquals(DocRouter.DEFAULT, collection1.getRouter());
    assertEquals(1, collection1.getActiveSlices().size());
    assertEquals(1, collection1.getSlices().size());
    Slice slice1 = collection1.getSlice("slice1");
    assertNotNull(slice1);
    assertEquals(1, slice1.getReplicas().size());
    Replica replica1 = slice1.getReplica("replica1");
    assertNotNull(replica1);
    assertEquals("baseUrl1_", replica1.getNodeName());
    assertEquals("slice1_replica1", replica1.getCoreName());
    assertEquals("http://baseUrl1", replica1.getBaseUrl());
    assertEquals("http://baseUrl1/slice1_replica1/", replica1.getCoreUrl());
    assertEquals(Replica.State.ACTIVE, replica1.getState());
    assertEquals(Replica.Type.NRT, replica1.getType());
  }
}
 
Example 3
Source File: HttpPartitionTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected void waitForState(String collection, String replicaName, Replica.State state, long ms) throws KeeperException, InterruptedException {
  TimeOut timeOut = new TimeOut(ms, TimeUnit.MILLISECONDS, TimeSource.NANO_TIME);
  Replica.State replicaState = Replica.State.ACTIVE;
  while (!timeOut.hasTimedOut()) {
    ZkStateReader zkr = cloudClient.getZkStateReader();
    zkr.forceUpdateCollection(collection);; // force the state to be fresh
    ClusterState cs = zkr.getClusterState();
    Collection<Slice> slices = cs.getCollection(collection).getActiveSlices();
    Slice slice = slices.iterator().next();
    Replica partitionedReplica = slice.getReplica(replicaName);
    replicaState = partitionedReplica.getState();
    if (replicaState == state) return;
  }
  assertEquals("Timeout waiting for state "+ state +" of replica " + replicaName + ", current state " + replicaState,
      state, replicaState);
}
 
Example 4
Source File: TestRebalanceLeaders.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void checkOneQueue(DocCollection coll, Slice slice, Set<Replica> liveReplicas) throws KeeperException, InterruptedException {

    List<String> leaderQueue = cluster.getSolrClient().getZkStateReader().getZkClient().getChildren("/collections/" + COLLECTION_NAME +
        "/leader_elect/" + slice.getName() + "/election", null, true);

    if (leaderQueue.size() != liveReplicas.size()) {

      log.error("One or more replicas is missing from the leader election queue! Slice {}, election queue: {}, collection: {}"
          , slice.getName(), leaderQueue, coll);
      fail("One or more replicas is missing from the leader election queue");
    }
    // Check that each election node has a corresponding live replica.
    for (String electionNode : leaderQueue) {
      String replica = LeaderElector.getNodeName(electionNode);
      if (slice.getReplica(replica) == null) {
        log.error("Replica {} is not in the election queue: {}", replica, leaderQueue);
        fail("Replica is not in the election queue!");
      }
    }
  }
 
Example 5
Source File: ZkController.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Replica getReplicaOrNull(DocCollection docCollection, String shard, String coreNodeName) {
  if (docCollection == null) return null;

  Slice slice = docCollection.getSlice(shard);
  if (slice == null) return null;

  Replica replica = slice.getReplica(coreNodeName);
  if (replica == null) return null;
  if (!getNodeName().equals(replica.getNodeName())) return null;

  return replica;
}
 
Example 6
Source File: ZkController.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public boolean checkIfCoreNodeNameAlreadyExists(CoreDescriptor dcore) {
  DocCollection collection = zkStateReader.getClusterState().getCollectionOrNull(dcore.getCollectionName());
  if (collection != null) {
    Collection<Slice> slices = collection.getSlices();

    for (Slice slice : slices) {
      Collection<Replica> replicas = slice.getReplicas();
      Replica r = slice.getReplica(dcore.getCloudDescriptor().getCoreNodeName());
      if (r != null) {
        return true;
      }
    }
  }
  return false;
}
 
Example 7
Source File: CloudUtil.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static boolean replicaExists(ClusterState clusterState, String collection, String shard, String coreNodeName) {
  DocCollection docCollection = clusterState.getCollectionOrNull(collection);
  if (docCollection != null) {
    Slice slice = docCollection.getSlice(shard);
    if (slice != null) {
      return slice.getReplica(coreNodeName) != null;
    }
  }
  return false;
}