private static boolean compareActiveReplicaCountsForShards(int expectedReplicas, Set<String> liveNodes, DocCollection collectionState) { for (Slice slice : collectionState) { int activeReplicas = 0; for (Replica replica : slice) { if (replica.isActive(liveNodes)) activeReplicas++; } if (activeReplicas != expectedReplicas) return true; } return false; }
/** * Check that all replicas in a collection are live * * @see CollectionStatePredicate */ public static boolean isFullyActive(Set<String> liveNodes, DocCollection collectionState, int expectedShards, int expectedReplicas) { Objects.requireNonNull(liveNodes); if (collectionState == null) return false; int activeShards = 0; for (Slice slice : collectionState) { int activeReplicas = 0; for (Replica replica : slice) { if (replica.isActive(liveNodes) == false) return false; activeReplicas++; } if (activeReplicas != expectedReplicas) return false; activeShards++; } return activeShards == expectedShards; }
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 (directUpdatesToLeadersOnly && leader == null) { for (Replica replica : slice.getReplicas( replica -> replica.isActive(getClusterStateProvider().getLiveNodes()) && replica.getType() == Replica.Type.NRT)) { leader = replica;