use of org.apache.solr.common.cloud.ClusterState in project janusgraph by JanusGraph.
the class SolrIndex method waitForRecoveriesToFinish.
/**
* Wait for all the collection shards to be ready.
*/
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);
// remove SYNC state per: http://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");
}
}
use of org.apache.solr.common.cloud.ClusterState in project titan by thinkaurelius.
the class SolrIndex method checkIfCollectionExists.
/**
* Checks if the collection has already been created in Solr.
*/
private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException {
ZkStateReader zkStateReader = server.getZkStateReader();
zkStateReader.updateClusterState(true);
ClusterState clusterState = zkStateReader.getClusterState();
return clusterState.getCollectionOrNull(collection) != null;
}
use of org.apache.solr.common.cloud.ClusterState in project titan by thinkaurelius.
the class SolrIndex method clearStorage.
@Override
public void clearStorage() throws BackendException {
try {
if (mode != Mode.CLOUD)
throw new UnsupportedOperationException("Operation only supported for SolrCloud");
logger.debug("Clearing storage from Solr: {}", solrClient);
ZkStateReader zkStateReader = ((CloudSolrClient) solrClient).getZkStateReader();
zkStateReader.updateClusterState(true);
ClusterState clusterState = zkStateReader.getClusterState();
for (String collection : clusterState.getCollections()) {
logger.debug("Clearing collection [{}] in Solr", collection);
UpdateRequest deleteAll = newUpdateRequest();
deleteAll.deleteByQuery("*:*");
solrClient.request(deleteAll, collection);
}
} catch (SolrServerException e) {
logger.error("Unable to clear storage from index due to server error on Solr.", e);
throw new PermanentBackendException(e);
} catch (IOException e) {
logger.error("Unable to clear storage from index due to low-level I/O error.", e);
throw new PermanentBackendException(e);
} catch (Exception e) {
logger.error("Unable to clear storage from index due to general error.", e);
throw new PermanentBackendException(e);
}
}
use of org.apache.solr.common.cloud.ClusterState in project lucene-solr by apache.
the class CoreSorterTest method getMockContainer.
private CoreContainer getMockContainer() {
CoreContainer mockCC = mock(CoreContainer.class);
ZkController mockZKC = mock(ZkController.class);
ClusterState mockClusterState = mock(ClusterState.class);
when(mockCC.isZooKeeperAware()).thenReturn(true);
when(mockCC.getZkController()).thenReturn(mockZKC);
when(mockClusterState.getLiveNodes()).thenReturn(liveNodes);
when(mockZKC.getClusterState()).thenReturn(mockClusterState);
return mockCC;
}
use of org.apache.solr.common.cloud.ClusterState in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method printClusterStateInfo.
protected String printClusterStateInfo(String collection) throws Exception {
cloudClient.getZkStateReader().forceUpdateCollection(collection);
String cs = null;
ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
if (collection != null) {
cs = clusterState.getCollection(collection).toString();
} else {
Map<String, DocCollection> map = clusterState.getCollectionsMap();
CharArr out = new CharArr();
new JSONWriter(out, 2).write(map);
cs = out.toString();
}
return cs;
}
Aggregations