/** * You can call this method to wait while the ChaosMonkey is running, it waits approximately the specified time, and periodically * logs the status of the collection * @param runLength The time in ms to wait * @param collectionName The main collection being used for the ChaosMonkey * @param zkStateReader current state reader */ public static void wait(long runLength, String collectionName, ZkStateReader zkStateReader) throws InterruptedException { TimeOut t = new TimeOut(runLength, TimeUnit.MILLISECONDS, TimeSource.NANO_TIME); while (!t.hasTimedOut()) { Thread.sleep(Math.min(1000, t.timeLeft(TimeUnit.MILLISECONDS))); logCollectionStateSummary(collectionName, zkStateReader); } }
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); } }
Replica leader = zkStateReader.getLeaderRetry(collectionName, s.getName(), (int)timeout.timeLeft(TimeUnit.MILLISECONDS)); long leaderIndexVersion = -1; while (!timeout.hasTimedOut()) {