Example usage for org.apache.solr.common.cloud ZkStateReader forciblyRefreshAllClusterStateSlow

List of usage examples for org.apache.solr.common.cloud ZkStateReader forciblyRefreshAllClusterStateSlow

Introduction

In this page you can find the example usage for org.apache.solr.common.cloud ZkStateReader forciblyRefreshAllClusterStateSlow.

Prototype

public void forciblyRefreshAllClusterStateSlow() throws KeeperException, InterruptedException 

Source Link

Document

Forcibly refresh cluster state from ZK.

Usage

From source file:org.janusgraph.diskstorage.solr.SolrIndex.java

License:Apache License

@Override
public void clearStorage() throws BackendException {
    try {/*from w  w w.jav a2s  .  c  o m*/
        if (mode != Mode.CLOUD) {
            logger.error(
                    "Operation only supported for SolrCloud. Cores must be deleted manually through the Solr API when using HTTP mode.");
            return;
        }
        logger.debug("Clearing storage from Solr: {}", solrClient);
        final ZkStateReader zkStateReader = ((CloudSolrClient) solrClient).getZkStateReader();
        zkStateReader.forciblyRefreshAllClusterStateSlow();
        final ClusterState clusterState = zkStateReader.getClusterState();
        for (final String collection : clusterState.getCollectionsMap().keySet()) {
            logger.debug("Clearing collection [{}] in Solr", collection);
            // Collection is not dropped because it may have been created externally
            final UpdateRequest deleteAll = newUpdateRequest();
            deleteAll.deleteByQuery("*:*");
            solrClient.request(deleteAll, collection);
        }

    } catch (final SolrServerException e) {
        logger.error("Unable to clear storage from index due to server error on Solr.", e);
        throw new PermanentBackendException(e);
    } catch (final IOException e) {
        logger.error("Unable to clear storage from index due to low-level I/O error.", e);
        throw new PermanentBackendException(e);
    } catch (final Exception e) {
        logger.error("Unable to clear storage from index due to general error.", e);
        throw new PermanentBackendException(e);
    }
}

From source file:org.janusgraph.diskstorage.solr.SolrIndex.java

License:Apache License

@Override
public boolean exists() throws BackendException {
    if (mode != Mode.CLOUD)
        throw new UnsupportedOperationException("Operation only supported for SolrCloud");
    final CloudSolrClient server = (CloudSolrClient) solrClient;
    try {//from ww w  .  j av  a2s.  c om
        final ZkStateReader zkStateReader = server.getZkStateReader();
        zkStateReader.forciblyRefreshAllClusterStateSlow();
        final ClusterState clusterState = zkStateReader.getClusterState();
        final Map<String, DocCollection> collections = clusterState.getCollectionsMap();
        return collections != null && !collections.isEmpty();
    } catch (KeeperException | InterruptedException e) {
        throw new PermanentBackendException("Unable to check if index exists", e);
    }
}