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);
}
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);
}
}
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());
}
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());
}
}
}
}
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;
}
Aggregations