List of usage examples for org.apache.solr.common.cloud ZkStateReader forceUpdateCollection
public void forceUpdateCollection(String collection) throws KeeperException, InterruptedException
From source file:org.janusgraph.diskstorage.solr.SolrIndex.java
License:Apache License
/** * Checks if the collection has already been created in Solr. *///w ww . j a v a 2 s . co m private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException { final ZkStateReader zkStateReader = server.getZkStateReader(); zkStateReader.forceUpdateCollection(collection); final ClusterState clusterState = zkStateReader.getClusterState(); return clusterState.getCollectionOrNull(collection) != null; }
From source file:org.janusgraph.diskstorage.solr.SolrIndex.java
License:Apache License
/** * Wait for all the collection shards to be ready. *///ww w. j a v a 2 s.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"); } }