Search in sources :

Example 61 with Slice

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

the class AbstractDistribZkTestBase method waitForRecoveriesToFinish.

public static void waitForRecoveriesToFinish(String collection, ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout, int timeoutSeconds) throws Exception {
    log.info("Wait for recoveries to finish - collection: " + collection + " failOnTimeout:" + failOnTimeout + " timeout (sec):" + timeoutSeconds);
    boolean cont = true;
    int cnt = 0;
    while (cont) {
        if (verbose)
            System.out.println("-");
        boolean sawLiveRecovering = false;
        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()) {
            Slice slice = entry.getValue();
            if (slice.getState() == Slice.State.CONSTRUCTION) {
                // similar to replica recovering; pretend its the same thing
                if (verbose)
                    System.out.println("Found a slice in construction state; will wait.");
                sawLiveRecovering = true;
            }
            Map<String, Replica> shards = slice.getReplicasMap();
            for (Map.Entry<String, Replica> shard : shards.entrySet()) {
                if (verbose)
                    System.out.println("replica:" + shard.getValue().getName() + " rstate:" + shard.getValue().getStr(ZkStateReader.STATE_PROP) + " live:" + clusterState.liveNodesContain(shard.getValue().getNodeName()));
                final Replica.State state = shard.getValue().getState();
                if ((state == Replica.State.RECOVERING || state == Replica.State.DOWN || state == Replica.State.RECOVERY_FAILED) && clusterState.liveNodesContain(shard.getValue().getStr(ZkStateReader.NODE_NAME_PROP))) {
                    sawLiveRecovering = true;
                }
            }
        }
        if (!sawLiveRecovering || cnt == timeoutSeconds) {
            if (!sawLiveRecovering) {
                if (verbose)
                    System.out.println("no one is recoverying");
            } else {
                if (verbose)
                    System.out.println("Gave up waiting for recovery to finish..");
                if (failOnTimeout) {
                    Diagnostics.logThreadDumps("Gave up waiting for recovery to finish.  THREAD DUMP:");
                    zkStateReader.getZkClient().printLayoutToStdOut();
                    fail("There are still nodes recoverying - waited for " + timeoutSeconds + " seconds");
                    // won't get here
                    return;
                }
            }
            cont = false;
        } else {
            Thread.sleep(1000);
        }
        cnt++;
    }
    log.info("Recoveries finished - collection: " + collection);
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) Slice(org.apache.solr.common.cloud.Slice) Map(java.util.Map) Replica(org.apache.solr.common.cloud.Replica)

Example 62 with Slice

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

the class AbstractDistribZkTestBase method waitForNewLeader.

static void waitForNewLeader(CloudSolrClient cloudClient, String shardName, Replica oldLeader, TimeOut timeOut) throws Exception {
    log.info("Will wait for a node to become leader for {} secs", timeOut.timeLeft(SECONDS));
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    zkStateReader.forceUpdateCollection(DEFAULT_COLLECTION);
    for (; ; ) {
        ClusterState clusterState = zkStateReader.getClusterState();
        DocCollection coll = clusterState.getCollection("collection1");
        Slice slice = coll.getSlice(shardName);
        if (slice.getLeader() != null && !slice.getLeader().equals(oldLeader) && slice.getLeader().getState() == Replica.State.ACTIVE) {
            log.info("Old leader {}, new leader {}. New leader got elected in {} ms", oldLeader, slice.getLeader(), timeOut.timeElapsed(MILLISECONDS));
            break;
        }
        if (timeOut.hasTimedOut()) {
            Diagnostics.logThreadDumps("Could not find new leader in specified timeout");
            zkStateReader.getZkClient().printLayoutToStdOut();
            fail("Could not find new leader even after waiting for " + timeOut.timeElapsed(MILLISECONDS) + "ms");
        }
        Thread.sleep(100);
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection)

Example 63 with Slice

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

the class AbstractFullDistribZkTestBase method logReplicaTypesReplicationInfo.

protected void logReplicaTypesReplicationInfo(String collectionName, ZkStateReader zkStateReader) throws KeeperException, InterruptedException, IOException {
    log.info("## Collecting extra Replica.Type information of the cluster");
    zkStateReader.updateLiveNodes();
    StringBuilder builder = new StringBuilder();
    zkStateReader.forceUpdateCollection(collectionName);
    DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName);
    for (Slice s : collection.getSlices()) {
        Replica leader = s.getLeader();
        for (Replica r : s.getReplicas()) {
            if (!r.isActive(zkStateReader.getClusterState().getLiveNodes())) {
                builder.append(String.format(Locale.ROOT, "Replica %s not in liveNodes or is not active%s", r.getName(), System.lineSeparator()));
                continue;
            }
            if (r.equals(leader)) {
                builder.append(String.format(Locale.ROOT, "Replica %s is leader%s", r.getName(), System.lineSeparator()));
            }
            logReplicationDetails(r, builder);
        }
    }
    log.info("Summary of the cluster: " + builder.toString());
}
Also used : Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica)

Example 64 with Slice

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

the class AbstractDistribZkTestBase method assertAllActive.

protected static void assertAllActive(String collection, ZkStateReader zkStateReader) throws KeeperException, InterruptedException {
    zkStateReader.forceUpdateCollection(collection);
    ClusterState clusterState = zkStateReader.getClusterState();
    Map<String, Slice> slices = clusterState.getSlicesMap(collection);
    if (slices == null) {
        throw new IllegalArgumentException("Cannot find collection:" + collection);
    }
    for (Map.Entry<String, Slice> entry : slices.entrySet()) {
        Slice slice = entry.getValue();
        if (slice.getState() != Slice.State.ACTIVE) {
            fail("Not all shards are ACTIVE - found a shard " + slice.getName() + " that is: " + slice.getState());
        }
        Map<String, Replica> shards = slice.getReplicasMap();
        for (Map.Entry<String, Replica> shard : shards.entrySet()) {
            Replica replica = shard.getValue();
            if (replica.getState() != Replica.State.ACTIVE) {
                fail("Not all replicas are ACTIVE - found a replica " + replica.getName() + " that is: " + replica.getState());
            }
        }
    }
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) Slice(org.apache.solr.common.cloud.Slice) Map(java.util.Map) Replica(org.apache.solr.common.cloud.Replica)

Example 65 with Slice

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

the class AbstractFullDistribZkTestBase method getTotalReplicas.

/* Total number of replicas (number of cores serving an index to the collection) shown by the cluster state */
protected int getTotalReplicas(String collection) {
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    DocCollection coll = zkStateReader.getClusterState().getCollectionOrNull(collection);
    // support for when collection hasn't been created yet
    if (coll == null)
        return 0;
    int cnt = 0;
    for (Slice slices : coll.getSlices()) {
        cnt += slices.getReplicas().size();
    }
    return cnt;
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection)

Aggregations

Slice (org.apache.solr.common.cloud.Slice)219 Replica (org.apache.solr.common.cloud.Replica)141 DocCollection (org.apache.solr.common.cloud.DocCollection)121 ClusterState (org.apache.solr.common.cloud.ClusterState)80 ArrayList (java.util.ArrayList)79 HashMap (java.util.HashMap)66 SolrException (org.apache.solr.common.SolrException)49 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)49 Map (java.util.Map)45 Test (org.junit.Test)37 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)28 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)25 HashSet (java.util.HashSet)24 SolrQuery (org.apache.solr.client.solrj.SolrQuery)24 IOException (java.io.IOException)23 NamedList (org.apache.solr.common.util.NamedList)23 List (java.util.List)22 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)22 DocRouter (org.apache.solr.common.cloud.DocRouter)20 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)20