@Override public void call(Object... data) { Exception e = (Exception) data[0]; if (e == null) return; String msg = e.getMessage(); if (msg != null && msg.contains("Timeout")) { Diagnostics.logThreadDumps("REQUESTING THREAD DUMP DUE TO TIMEOUT: " + e.getMessage()); } } };
public static void waitForCollectionToDisappear(String collection, ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout, int timeoutSeconds) throws Exception { log.info("Wait for collection to disappear - collection: " + collection + " failOnTimeout:" + failOnTimeout + " timeout (sec):" + timeoutSeconds); boolean cont = true; int cnt = 0; while (cont) { if (verbose) System.out.println("-"); ClusterState clusterState = zkStateReader.getClusterState(); if (!clusterState.hasCollection(collection)) break; if (cnt == timeoutSeconds) { if (verbose) System.out.println("Gave up waiting for "+collection+" to disappear.."); if (failOnTimeout) { Diagnostics.logThreadDumps("Gave up waiting for "+collection+" to disappear. THREAD DUMP:"); zkStateReader.getZkClient().printLayoutToStdOut(); fail("The collection ("+collection+") is still present - waited for " + timeoutSeconds + " seconds"); // won't get here return; } cont = false; } else { Thread.sleep(1000); } cnt++; } log.info("Collection has disappeared - collection: " + collection); }
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:"); try { zkStateReader.getZkClient().printLayoutToStdOut();
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");
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); } }