private Replica getReplica(DocCollection coll, String replicaName) { if (coll == null) return null; for (Slice slice : coll.getSlices()) { Replica replica = slice.getReplica(replicaName); if (replica != null) return replica; } return null; }
throw new IllegalArgumentException("Incompatible shards: + " + shards + " for docCollection: " + docCollection); List<Slice> slices = new ZooKeeperInspector().getSortedSlices(docCollection.getSlices()); if (slices.size() != shards) { throw new IllegalStateException("Incompatible sorted shards: + " + shards + " for docCollection: " + docCollection);
public Collection<Slice> getSlices(String collection) { DocCollection coll = getCollectionOrNull(collection); if (coll == null) return null; return coll.getSlices(); }
throw new IllegalArgumentException("Incompatible shards: + " + shards + " for docCollection: " + docCollection); List<Slice> slices = new ZooKeeperInspector().getSortedSlices(docCollection.getSlices()); if (slices.size() != shards) { throw new IllegalStateException("Incompatible sorted shards: + " + shards + " for docCollection: " + docCollection);
/** * Return a {@link CollectionStatePredicate} that returns true if a collection has the expected * number of shards and active replicas */ public static CollectionStatePredicate clusterShape(int expectedShards, int expectedReplicas) { return (liveNodes, collectionState) -> { if (collectionState == null) return false; if (collectionState.getSlices().size() != expectedShards) return false; if (compareActiveReplicaCountsForShards(expectedReplicas, liveNodes, collectionState)) return false; return true; }; }
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()); } } } }
public static void waitForCollection(ZkStateReader reader, String collection, int slices) throws Exception { // wait until shards have started registering... int cnt = 30; while (!reader.getClusterState().hasCollection(collection)) { if (cnt == 0) { throw new RuntimeException("timeout waiting for collection in cluster state: collection=" + collection); } cnt--; Thread.sleep(500); } cnt = 30; while (reader.getClusterState().getCollection(collection).getSlices().size() < slices) { if (cnt == 0) { throw new RuntimeException("timeout waiting for collection shards to come up: collection="+collection + ", slices.expected="+slices+ " slices.actual= " + reader.getClusterState().getCollection(collection).getSlices().size() + " slices : "+ reader.getClusterState().getCollection(collection).getSlices() ); } cnt--; Thread.sleep(500); } }
public List<List<String>> extractShardUrls(String zkHost, String collection) { DocCollection docCollection = extractDocCollection(zkHost, collection); List<Slice> slices = getSortedSlices(docCollection.getSlices()); List<List<String>> solrUrls = new ArrayList<List<String>>(slices.size()); for (Slice slice : slices) { if (slice.getLeader() == null) { throw new IllegalArgumentException("Cannot find SolrCloud slice leader. " + "It looks like not all of your shards are registered in ZooKeeper yet"); } Collection<Replica> replicas = slice.getReplicas(); List<String> urls = new ArrayList<String>(replicas.size()); for (Replica replica : replicas) { ZkCoreNodeProps props = new ZkCoreNodeProps(replica); urls.add(props.getCoreUrl()); } solrUrls.add(urls); } return solrUrls; }
protected int getTotalReplicas(String collection) { ZkStateReader zkStateReader = cloudClient.getZkStateReader(); DocCollection coll = zkStateReader.getClusterState().getCollectionOrNull(collection); if (coll == null) return 0; // support for when collection hasn't been created yet int cnt = 0; for (Slice slices : coll.getSlices()) { cnt += slices.getReplicas().size(); } return cnt; }
public String getShardId(String collectionName, String nodeName, String coreName) { Collection<CollectionRef> states = collectionStates.values(); if (collectionName != null) { CollectionRef c = collectionStates.get(collectionName); if (c != null) states = Collections.singletonList( c ); } for (CollectionRef ref : states) { DocCollection coll = ref.get(); if(coll == null) continue;// this collection go tremoved in between, skip for (Slice slice : coll.getSlices()) { for (Replica replica : slice.getReplicas()) { // TODO: for really large clusters, we could 'index' on this String rnodeName = replica.getStr(ZkStateReader.NODE_NAME_PROP); String rcore = replica.getStr(ZkStateReader.CORE_NAME_PROP); if (nodeName.equals(rnodeName) && coreName.equals(rcore)) { return slice.getName(); } } } } return null; }
public String getShardId(String collectionName, String nodeName, String coreName) { Collection<CollectionRef> states = collectionStates.values(); if (collectionName != null) { CollectionRef c = collectionStates.get(collectionName); if (c != null) states = Collections.singletonList( c ); } for (CollectionRef ref : states) { DocCollection coll = ref.get(); if(coll == null) continue;// this collection go tremoved in between, skip for (Slice slice : coll.getSlices()) { for (Replica replica : slice.getReplicas()) { // TODO: for really large clusters, we could 'index' on this String rnodeName = replica.getStr(ZkStateReader.NODE_NAME_PROP); String rcore = replica.getStr(ZkStateReader.CORE_NAME_PROP); if (nodeName.equals(rnodeName) && coreName.equals(rcore)) { return slice.getName(); } } } } return null; }
public List<List<String>> extractShardUrls(String zkHost, String collection) { DocCollection docCollection = extractDocCollection(zkHost, collection); List<Slice> slices = getSortedSlices(docCollection.getSlices()); List<List<String>> solrUrls = new ArrayList<List<String>>(slices.size()); for (Slice slice : slices) { if (slice.getLeader() == null) { throw new IllegalArgumentException("Cannot find SolrCloud slice leader. " + "It looks like not all of your shards are registered in ZooKeeper yet"); } Collection<Replica> replicas = slice.getReplicas(); List<String> urls = new ArrayList<String>(replicas.size()); for (Replica replica : replicas) { ZkCoreNodeProps props = new ZkCoreNodeProps(replica); if (replica.getStr(Slice.LEADER) == null) { urls.add(props.getCoreUrl()); // add followers at tail } else { urls.add(0, props.getCoreUrl()); // insert leader at head } } solrUrls.add(urls); } return solrUrls; }
private static void logCollectionStateSummary(String collectionName, ZkStateReader zkStateReader) { Pattern portPattern = Pattern.compile(".*:([0-9]*).*"); DocCollection docCollection = zkStateReader.getClusterState().getCollection(collectionName); if (docCollection == null) { monkeyLog("Could not find collection {}", collectionName); } StringBuilder builder = new StringBuilder(); builder.append("Collection status: {"); for (Slice slice:docCollection.getSlices()) { builder.append(slice.getName() + ": {"); for (Replica replica:slice.getReplicas()) { log.info(replica.toString()); java.util.regex.Matcher m = portPattern.matcher(replica.getBaseUrl()); m.find(); String jettyPort = m.group(1); builder.append(String.format(Locale.ROOT, "%s(%s): {state: %s, type: %s, leader: %s, Live: %s}, ", replica.getName(), jettyPort, replica.getState(), replica.getType(), (replica.get("leader")!= null), zkStateReader.getClusterState().liveNodesContain(replica.getNodeName()))); } if (slice.getReplicas().size() > 0) { builder.setLength(builder.length() - 2); } builder.append("}, "); } if (docCollection.getSlices().size() > 0) { builder.setLength(builder.length() - 2); } builder.append("}"); monkeyLog(builder.toString()); }
Collection<Slice> slices = docCollection.getSlices(); for (Slice slice : slices) {
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()); }
if (clusterState != null) { DocCollection docCollection = clusterState.getCollection(collection); Collection<Slice> slices = docCollection.getSlices(); for (Slice slice : slices) {
Collection<Slice> slices = docCollection.getSlices(); for (Slice slice : slices) {
if (clusterState != null) { DocCollection docCollection = clusterState.getCollection(collection); Collection<Slice> slices = docCollection.getSlices(); for (Slice slice : slices) {
Collection<Slice> slices = docCollection.getSlices(); for (Slice slice : slices) {
final ClusterState clusterState = AuthorizedSolrClient.getClusterState(client); DocCollection docCollection = clusterState.getCollection(collection); for (Slice slice : docCollection.getSlices()) { ArrayList<Replica> replicas = new ArrayList<>(slice.getReplicas()); Collections.shuffle(replicas);