/** Constructs a slices map from a collection of slices and handles disambiguation if multiple collections are being queried simultaneously */ public static void addSlices(Map<String,Slice> target, String collectionName, Collection<Slice> slices, boolean multiCollection) { for (Slice slice : slices) { String key = slice.getName(); if (multiCollection) key = collectionName + "_" + key; target.put(key, slice); } } }
/** Constructs a slices map from a collection of slices and handles disambiguation if multiple collections are being queried simultaneously */ public static void addSlices(Map<String,Slice> target, String collectionName, Collection<Slice> slices, boolean multiCollection) { for (Slice slice : slices) { String key = slice.getName(); if (multiCollection) key = collectionName + "_" + key; target.put(key, slice); } } }
/** * Get the shardId of a core on a specific node */ public String getShardId(String nodeName, String coreName) { for (Slice slice : this) { for (Replica replica : slice) { if (Objects.equals(replica.getNodeName(), nodeName) && Objects.equals(replica.getCoreName(), coreName)) return slice.getName(); } } return null; }
private final Map<String,String> getShardLeaders(CloudSolrServer solr, String collection) throws Exception { Map<String,String> leaders = new TreeMap<String,String>(); ZkStateReader zkStateReader = solr.getZkStateReader(); for (Slice slice : zkStateReader.getClusterState().getSlices(collection)) { leaders.put(slice.getName(), zkStateReader.getLeaderUrl(collection, slice.getName(), ZK_CLIENT_TIMEOUT)); } return leaders; } }
+ docRouter.getClass().getName()); int rootShard = shardNumbers.get(slice.getName()); if (rootShard < 0 || rootShard >= shards) { throw new IllegalStateException("Illegal shard number " + rootShard + " for slice: " + slice + ", docCollection: "
+ docRouter.getClass().getName()); int rootShard = shardNumbers.get(slice.getName()); if (rootShard < 0 || rootShard >= shards) { throw new IllegalStateException("Illegal shard number " + rootShard + " for slice: " + slice + ", docCollection: "
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; }
shardNumbers.put(slices.get(i).getName(), i);
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; }
private void getCheckpoints() throws IOException { this.checkpoints = new HashMap<>(); ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader(); Slice[] slices = CloudSolrStream.getSlices(this.collection, zkStateReader, false); ClusterState clusterState = zkStateReader.getClusterState(); Set<String> liveNodes = clusterState.getLiveNodes(); for(Slice slice : slices) { String sliceName = slice.getName(); long checkpoint; if(initialCheckpoint > -1) { checkpoint = initialCheckpoint; } else { checkpoint = getCheckpoint(slice, liveNodes); } this.checkpoints.put(sliceName, checkpoint); } }
while (sliceIterator.hasNext()) { Slice slice = sliceIterator.next(); String name = slice.getName(); List<String> urls = new ArrayList<>(); Replica leader = slice.getLeader();
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()); }
private static void addMissingReplicas(SolrCloudManager cloudManager, Suggestion.Ctx ctx) throws IOException { cloudManager.getClusterStateProvider().getClusterState().forEachCollection(coll -> coll.forEach(slice -> { ReplicaCount replicaCount = new ReplicaCount(); slice.forEach(replica -> { if (replica.getState() == Replica.State.ACTIVE || replica.getState() == Replica.State.RECOVERING) { replicaCount.increment(replica.getType()); } }); addMissingReplicas(replicaCount, coll, slice.getName(), Replica.Type.NRT, ctx); addMissingReplicas(replicaCount, coll, slice.getName(), Replica.Type.PULL, ctx); addMissingReplicas(replicaCount, coll, slice.getName(), Replica.Type.TLOG, ctx); } )); }
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()); } } } }
Slice[] slices = col.getActiveSlicesArr(); for (Slice slice : slices) { String name = slice.getName(); List<String> urls = new ArrayList<>(); Replica leader = slice.getLeader();
randomActiveReplica != null, "Can not found an active replica for slice %s", slice.getName()); out.output(KV.of(spec, ReplicaInfo.create(checkNotNull(randomActiveReplica))));