Search in sources :

Example 16 with ZkStateReader

use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.

the class ManagedIndexSchema method getActiveReplicaCoreUrls.

protected static List<String> getActiveReplicaCoreUrls(ZkController zkController, String collection, String localCoreNodeName) {
    List<String> activeReplicaCoreUrls = new ArrayList<>();
    ZkStateReader zkStateReader = zkController.getZkStateReader();
    ClusterState clusterState = zkStateReader.getClusterState();
    Set<String> liveNodes = clusterState.getLiveNodes();
    Collection<Slice> activeSlices = clusterState.getActiveSlices(collection);
    if (activeSlices != null && activeSlices.size() > 0) {
        for (Slice next : activeSlices) {
            Map<String, Replica> replicasMap = next.getReplicasMap();
            if (replicasMap != null) {
                for (Map.Entry<String, Replica> entry : replicasMap.entrySet()) {
                    Replica replica = entry.getValue();
                    if (!localCoreNodeName.equals(replica.getName()) && replica.getState() == Replica.State.ACTIVE && liveNodes.contains(replica.getNodeName())) {
                        ZkCoreNodeProps replicaCoreProps = new ZkCoreNodeProps(replica);
                        activeReplicaCoreUrls.add(replicaCoreProps.getCoreUrl());
                    }
                }
            }
        }
    }
    return activeReplicaCoreUrls;
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) Slice(org.apache.solr.common.cloud.Slice) Map(java.util.Map) HashMap(java.util.HashMap)

Example 17 with ZkStateReader

use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.

the class HttpSolrCall method extractRemotePath.

protected void extractRemotePath(String corename, String origCorename, int idx) throws UnsupportedEncodingException, KeeperException, InterruptedException {
    if (core == null && idx > 0) {
        coreUrl = getRemotCoreUrl(corename, origCorename);
        // don't proxy for internal update requests
        invalidStates = checkStateIsValid(queryParams.get(CloudSolrClient.STATE_VERSION));
        if (coreUrl != null && queryParams.get(DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM) == null) {
            path = path.substring(idx);
            if (invalidStates != null) {
                //it does not make sense to send the request to a remote node
                throw new SolrException(SolrException.ErrorCode.INVALID_STATE, new String(Utils.toJSON(invalidStates), org.apache.lucene.util.IOUtils.UTF_8));
            }
            action = REMOTEQUERY;
        } else {
            if (!retry) {
                // we couldn't find a core to work with, try reloading aliases
                // TODO: it would be nice if admin ui elements skipped this...
                ZkStateReader reader = cores.getZkController().getZkStateReader();
                reader.updateAliases();
                action = RETRY;
            }
        }
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) SolrException(org.apache.solr.common.SolrException)

Example 18 with ZkStateReader

use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.

the class HttpSolrCall method getCoreByCollection.

protected SolrCore getCoreByCollection(String collectionName, boolean isPreferLeader) {
    ZkStateReader zkStateReader = cores.getZkController().getZkStateReader();
    ClusterState clusterState = zkStateReader.getClusterState();
    DocCollection collection = clusterState.getCollectionOrNull(collectionName);
    if (collection == null) {
        return null;
    }
    Set<String> liveNodes = clusterState.getLiveNodes();
    if (isPreferLeader) {
        List<Replica> leaderReplicas = collection.getLeaderReplicas(cores.getZkController().getNodeName());
        SolrCore core = randomlyGetSolrCore(liveNodes, leaderReplicas);
        if (core != null)
            return core;
    }
    List<Replica> replicas = collection.getReplicas(cores.getZkController().getNodeName());
    return randomlyGetSolrCore(liveNodes, replicas);
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) SolrCore(org.apache.solr.core.SolrCore) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica)

Example 19 with ZkStateReader

use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.

the class TestSubQueryTransformerDistrib method setupCluster.

@BeforeClass
public static void setupCluster() throws Exception {
    differentUniqueId = random().nextBoolean();
    final Path configDir = Paths.get(TEST_HOME(), "collection1", "conf");
    String configName = "solrCloudCollectionConfig";
    int nodeCount = 5;
    configureCluster(nodeCount).addConfig(configName, configDir).configure();
    Map<String, String> collectionProperties = new HashMap<>();
    collectionProperties.put("config", "solrconfig-doctransformers.xml");
    collectionProperties.put("schema", "schema-docValuesJoin.xml");
    int shards = 2;
    int replicas = 2;
    CollectionAdminRequest.createCollection(people, configName, shards, replicas).withProperty("config", "solrconfig-doctransformers.xml").withProperty("schema", "schema-docValuesJoin.xml").process(cluster.getSolrClient());
    CollectionAdminRequest.createCollection(depts, configName, shards, replicas).withProperty("config", "solrconfig-doctransformers.xml").withProperty("schema", differentUniqueId ? "schema-minimal-with-another-uniqkey.xml" : "schema-docValuesJoin.xml").process(cluster.getSolrClient());
    CloudSolrClient client = cluster.getSolrClient();
    client.setDefaultCollection(people);
    ZkStateReader zkStateReader = client.getZkStateReader();
    AbstractDistribZkTestBase.waitForRecoveriesToFinish(people, zkStateReader, true, true, 30);
    AbstractDistribZkTestBase.waitForRecoveriesToFinish(depts, zkStateReader, false, true, 30);
}
Also used : Path(java.nio.file.Path) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) HashMap(java.util.HashMap) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) BeforeClass(org.junit.BeforeClass)

Example 20 with ZkStateReader

use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.

the class ZkClientClusterStateProvider method connect.

@Override
public void connect() {
    if (zkStateReader == null) {
        synchronized (this) {
            if (zkStateReader == null) {
                ZkStateReader zk = null;
                try {
                    zk = new ZkStateReader(zkHost, zkClientTimeout, zkConnectTimeout);
                    zk.createClusterStateWatchersAndUpdate();
                    zkStateReader = zk;
                    log.info("Cluster at {} ready", zkHost);
                } catch (InterruptedException e) {
                    zk.close();
                    Thread.currentThread().interrupt();
                    throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
                } catch (KeeperException e) {
                    zk.close();
                    throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
                } catch (Exception e) {
                    if (zk != null)
                        zk.close();
                    // do not wrap because clients may be relying on the underlying exception being thrown
                    throw e;
                }
            }
        }
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) KeeperException(org.apache.zookeeper.KeeperException) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) KeeperException(org.apache.zookeeper.KeeperException) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException)

Aggregations

ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)133 ClusterState (org.apache.solr.common.cloud.ClusterState)58 Replica (org.apache.solr.common.cloud.Replica)48 Slice (org.apache.solr.common.cloud.Slice)48 HashMap (java.util.HashMap)34 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)33 ArrayList (java.util.ArrayList)32 DocCollection (org.apache.solr.common.cloud.DocCollection)31 Test (org.junit.Test)26 SolrException (org.apache.solr.common.SolrException)25 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)22 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)20 IOException (java.io.IOException)19 Map (java.util.Map)19 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)18 KeeperException (org.apache.zookeeper.KeeperException)16 SolrQuery (org.apache.solr.client.solrj.SolrQuery)15 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)15 SolrServerException (org.apache.solr.client.solrj.SolrServerException)13 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)12