List of usage examples for org.apache.solr.common.cloud ClusterState liveNodesContain
public boolean liveNodesContain(String name)
From source file:com.thinkaurelius.titan.diskstorage.solr.Solr5Index.java
License:Apache License
/** * Wait for all the collection shards to be ready. *//*from ww w. j a v a 2 s . co m*/ private static void waitForRecoveriesToFinish(CloudSolrClient server, String collection) throws KeeperException, InterruptedException { ZkStateReader zkStateReader = server.getZkStateReader(); try { boolean cont = true; while (cont) { boolean sawLiveRecovering = false; zkStateReader.updateClusterState(true); ClusterState clusterState = zkStateReader.getClusterState(); Map<String, Slice> slices = clusterState.getSlicesMap(collection); Preconditions.checkNotNull("Could not find collection:" + collection, slices); for (Map.Entry<String, Slice> entry : slices.entrySet()) { Map<String, Replica> shards = entry.getValue().getReplicasMap(); for (Map.Entry<String, Replica> shard : shards.entrySet()) { String state = shard.getValue().getStr(ZkStateReader.STATE_PROP); if ((state.equals(ZkStateReader.RECOVERING) || state.equals(ZkStateReader.SYNC) || state.equals(ZkStateReader.DOWN)) && clusterState .liveNodesContain(shard.getValue().getStr(ZkStateReader.NODE_NAME_PROP))) { sawLiveRecovering = true; } } } if (!sawLiveRecovering) { cont = false; } else { Thread.sleep(1000); } } } finally { logger.info("Exiting solr wait"); } }
From source file:org.apache.sentry.tests.e2e.solr.AbstractSolrSentryTestBase.java
License:Apache License
protected static void waitForRecoveriesToFinish(String collection, CloudSolrServer solrServer, boolean verbose, boolean failOnTimeout, int timeoutSeconds) throws Exception { LOG.info("Entering solr wait with timeout " + timeoutSeconds); ZkStateReader zkStateReader = solrServer.getZkStateReader(); try {//www. j av a 2 s. c om boolean cont = true; int cnt = 0; while (cont) { if (verbose) LOG.debug("-"); boolean sawLiveRecovering = false; zkStateReader.updateClusterState(true); ClusterState clusterState = zkStateReader.getClusterState(); Map<String, Slice> slices = clusterState.getSlicesMap(collection); assertNotNull("Could not find collection:" + collection, slices); for (Map.Entry<String, Slice> entry : slices.entrySet()) { Map<String, Replica> shards = entry.getValue().getReplicasMap(); for (Map.Entry<String, Replica> shard : shards.entrySet()) { if (verbose) LOG.debug("rstate:" + shard.getValue().getStr(ZkStateReader.STATE_PROP) + " live:" + clusterState.liveNodesContain(shard.getValue().getNodeName())); String state = shard.getValue().getStr(ZkStateReader.STATE_PROP); if ((state.equals(ZkStateReader.RECOVERING) || state.equals(ZkStateReader.SYNC) || state.equals(ZkStateReader.DOWN)) && clusterState .liveNodesContain(shard.getValue().getStr(ZkStateReader.NODE_NAME_PROP))) { sawLiveRecovering = true; } } } if (!sawLiveRecovering || cnt == timeoutSeconds) { if (!sawLiveRecovering) { if (verbose) LOG.debug("no one is recovering"); } else { if (verbose) LOG.debug("Gave up waiting for recovery to finish.."); if (failOnTimeout) { fail("There are still nodes recovering - waited for " + timeoutSeconds + " seconds"); // won't get here return; } } cont = false; } else { Thread.sleep(1000); } cnt++; } } finally { LOG.info("Exiting solr wait"); } }
From source file:org.janusgraph.diskstorage.solr.SolrIndex.java
License:Apache License
/** * Wait for all the collection shards to be ready. *//*from w w w. j a v a 2s . c om*/ private static void waitForRecoveriesToFinish(CloudSolrClient server, String collection) throws KeeperException, InterruptedException { final ZkStateReader zkStateReader = server.getZkStateReader(); try { boolean cont = true; while (cont) { boolean sawLiveRecovering = false; zkStateReader.forceUpdateCollection(collection); final ClusterState clusterState = zkStateReader.getClusterState(); final Map<String, Slice> slices = clusterState.getCollection(collection).getSlicesMap(); Preconditions.checkNotNull(slices, "Could not find collection:" + collection); // change paths for Replica.State per Solr refactoring // remove SYNC state per: https://tinyurl.com/pag6rwt for (final Map.Entry<String, Slice> entry : slices.entrySet()) { final Map<String, Replica> shards = entry.getValue().getReplicasMap(); for (final Map.Entry<String, Replica> shard : shards.entrySet()) { final String state = shard.getValue().getStr(ZkStateReader.STATE_PROP).toUpperCase(); if ((Replica.State.RECOVERING.name().equals(state) || Replica.State.DOWN.name().equals(state)) && clusterState .liveNodesContain(shard.getValue().getStr(ZkStateReader.NODE_NAME_PROP))) { sawLiveRecovering = true; } } } if (!sawLiveRecovering) { cont = false; } else { Thread.sleep(1000); } } } finally { logger.info("Exiting solr wait"); } }