/** * Checks if the collection has already been created in Solr. */ private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException { final ZkStateReader zkStateReader = server.getZkStateReader(); zkStateReader.forceUpdateCollection(collection); final ClusterState clusterState = zkStateReader.getClusterState(); return clusterState.getCollectionOrNull(collection) != null; }
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()); }
zkStateReader.forceUpdateCollection(collection); final ClusterState clusterState = zkStateReader.getClusterState(); final Map<String, Slice> slices = clusterState.getCollection(collection).getSlicesMap();
private int checkIfKillIsLegal(String sliceName, int numActive) throws KeeperException, InterruptedException { for (CloudJettyRunner cloudJetty : shardToJetty.get(sliceName)) { // get latest cloud state zkStateReader.forceUpdateCollection(collection); DocCollection docCollection = zkStateReader.getClusterState().getCollection(collection); Slice slice = docCollection.getSlice(sliceName); ZkNodeProps props = slice.getReplicasMap().get(cloudJetty.coreNodeName); if (props == null) { throw new RuntimeException("shard name " + cloudJetty.coreNodeName + " not found in " + slice.getReplicasMap().keySet()); } final Replica.State state = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)); final String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP); if (cloudJetty.jetty.isRunning() && state == Replica.State.ACTIVE && zkStateReader.getClusterState().liveNodesContain(nodeName)) { numActive++; } } return numActive; }
protected static void assertAllActive(String collection, ZkStateReader zkStateReader) throws KeeperException, InterruptedException { zkStateReader.forceUpdateCollection(collection); ClusterState clusterState = zkStateReader.getClusterState(); final DocCollection docCollection = clusterState.getCollectionOrNull(collection); if (docCollection == null || docCollection.getSlices() == null) { throw new IllegalArgumentException("Cannot find collection:" + collection); } Map<String,Slice> slices = docCollection.getSlicesMap(); 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()); } } } }
private boolean canKillIndexer(String sliceName) throws KeeperException, InterruptedException { int numIndexersFoundInShard = 0; for (CloudJettyRunner cloudJetty : shardToJetty.get(sliceName)) { // get latest cloud state zkStateReader.forceUpdateCollection(collection); DocCollection docCollection = zkStateReader.getClusterState().getCollection(collection); Slice slice = docCollection.getSlice(sliceName); ZkNodeProps props = slice.getReplicasMap().get(cloudJetty.coreNodeName); if (props == null) { throw new RuntimeException("shard name " + cloudJetty.coreNodeName + " not found in " + slice.getReplicasMap().keySet()); } final Replica.State state = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)); final Replica.Type replicaType = Replica.Type.valueOf(props.getStr(ZkStateReader.REPLICA_TYPE)); final String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP); if (cloudJetty.jetty.isRunning() && state == Replica.State.ACTIVE && (replicaType == Replica.Type.TLOG || replicaType == Replica.Type.NRT) && zkStateReader.getClusterState().liveNodesContain(nodeName)) { numIndexersFoundInShard++; } } return numIndexersFoundInShard > 1; }
protected void updateMappingsFromZk(List<JettySolrRunner> jettys, List<SolrClient> clients, boolean allowOverSharding) throws Exception { ZkStateReader zkStateReader = cloudClient.getZkStateReader(); zkStateReader.forceUpdateCollection(DEFAULT_COLLECTION); cloudJettys.clear(); shardToJetty.clear();
zkr.forceUpdateCollection(testCollectionName); // force the state to be fresh
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); } }
protected String printClusterStateInfo(String collection) throws Exception { cloudClient.getZkStateReader().forceUpdateCollection(collection); String cs = null; ClusterState clusterState = cloudClient.getZkStateReader().getClusterState(); if (collection != null) { cs = clusterState.getCollection(collection).toString(); } else { Map<String,DocCollection> map = clusterState.getCollectionsMap(); CharArr out = new CharArr(); new JSONWriter(out, 2).write(map); cs = out.toString(); } return cs; }
protected void waitForReplicationFromReplicas(String collectionName, ZkStateReader zkStateReader, TimeOut timeout) throws KeeperException, InterruptedException, IOException { zkStateReader.forceUpdateCollection(collectionName); DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName); Map<String, CoreContainer> containers = new HashMap<>();