Java Code Examples for org.apache.solr.common.cloud.ZkStateReader#updateLiveNodes()

The following examples show how to use org.apache.solr.common.cloud.ZkStateReader#updateLiveNodes() . 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: AbstractFullDistribZkTestBase.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected void logReplicaTypesReplicationInfo(String collectionName, ZkStateReader zkStateReader) throws KeeperException, InterruptedException, IOException {
  log.info("## Collecting extra Replica.Type information of the cluster");
  zkStateReader.updateLiveNodes();
  StringBuilder builder = new StringBuilder();
  zkStateReader.forceUpdateCollection(collectionName);
  DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName);
  for(Slice s:collection.getSlices()) {
    Replica leader = s.getLeader();
    for (Replica r:s.getReplicas()) {
      if (!r.isActive(zkStateReader.getClusterState().getLiveNodes())) {
        builder.append(String.format(Locale.ROOT, "Replica %s not in liveNodes or is not active%s", r.getName(), System.lineSeparator()));
        continue;
      }
      if (r.equals(leader)) {
        builder.append(String.format(Locale.ROOT, "Replica %s is leader%s", r.getName(), System.lineSeparator()));
      }
      logReplicationDetails(r, builder);
    }
  }
  log.info("Summary of the cluster: {}", builder);
}
 
Example 2
Source File: ZkFailoverTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void waitForLiveNodes(int numNodes) throws InterruptedException, KeeperException {
  ZkStateReader zkStateReader = cluster.getSolrClient().getZkStateReader();
  for (int i = 0; i < 100; i++) {
    zkStateReader.updateLiveNodes();
    if (zkStateReader.getClusterState().getLiveNodes().size() == numNodes) return;
    Thread.sleep(200);
  }
  fail("Timeout waiting for number of live nodes = " + numNodes);
}