String state = shard.getValue().getStr(ZkStateReader.STATE_PROP); if ((state.equals(Replica.State.RECOVERING) || state.equals(Replica.State.DOWN)) && clusterState.liveNodesContain(shard.getValue().getStr( ZkStateReader.NODE_NAME_PROP))) { sawLiveRecovering = true;
public Replica getLeader(String collection, String shard) throws InterruptedException { if (clusterState != null) { Replica replica = clusterState.getLeader(collection, shard); if (replica != null && getClusterState().liveNodesContain(replica.getNodeName())) { return replica; } } return null; }
public static String getUrlFromZk(ClusterState clusterState, String collection) { Map<String,Slice> slices = clusterState.getCollection(collection).getSlicesMap(); if (slices == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not find collection:" + collection); } for (Map.Entry<String,Slice> entry : slices.entrySet()) { Slice slice = entry.getValue(); Map<String,Replica> shards = slice.getReplicasMap(); Set<Map.Entry<String,Replica>> shardEntries = shards.entrySet(); for (Map.Entry<String,Replica> shardEntry : shardEntries) { final ZkNodeProps node = shardEntry.getValue(); if (clusterState.liveNodesContain(node.getStr(ZkStateReader.NODE_NAME_PROP))) { return ZkCoreNodeProps.getCoreUrl(node.getStr(ZkStateReader.BASE_URL_PROP), collection); //new ZkCoreNodeProps(node).getCoreUrl(); } } } throw new RuntimeException("Could not find a live node for collection:" + collection); }
if ((state.equals(Replica.State.RECOVERING) || state.equals(Replica.State.DOWN)) && clusterState.liveNodesContain(shard.getValue().getStr( ZkStateReader.NODE_NAME_PROP))) { sawLiveRecovering = true;
String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP); ZkStateReader zkStateReader = cloudClient.getZkStateReader(); if (zkStateReader.getClusterState().liveNodesContain(nodeName)) { live = true;
public Replica getLeader(String collection, String shard) { if (clusterState != null) { DocCollection docCollection = clusterState.getCollectionOrNull(collection); Replica replica = docCollection != null ? docCollection.getLeader(shard) : null; if (replica != null && getClusterState().liveNodesContain(replica.getNodeName())) { return replica; } } return null; }
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()); }
for (Replica replica : replicas) { boolean live = clusterState.liveNodesContain(replica .getNodeName()); if (live) {
if (clusterState.liveNodesContain(nodeProps.getNodeName()) && !coreNodeName.equals(thisCoreNodeName)) { if (mustMatchStateFilter == null || mustMatchStateFilter == Replica.State.getState(nodeProps.getState())) { if (mustNotMatchStateFilter == null || mustNotMatchStateFilter != Replica.State.getState(nodeProps.getState())) {
final String state = shard.getValue().getStr(ZkStateReader.STATE_PROP).toUpperCase(); if ((Replica.State.RECOVERING.name().equals(state) || Replica.State.DOWN.name().equals(state)) && clusterState.liveNodesContain(shard.getValue().getStr( ZkStateReader.NODE_NAME_PROP))) { sawLiveRecovering = true;
if ((state.equals(Replica.State.RECOVERING.toString()) || state.equals(Replica.State.DOWN.toString())) && clusterState.liveNodesContain(shard.getValue().getStr( ZkStateReader.NODE_NAME_PROP))) { sawLiveRecovering = true;
for (Replica replica : replicas) { boolean live = clusterState.liveNodesContain(replica.getNodeName()); String rcoreNodeName = replica.getName(); String rbaseUrl = replica.getStr(ZkStateReader.BASE_URL_PROP);
for (Replica replica : replicas) { final boolean live = clusterState.liveNodesContain(replica.getNodeName()); final boolean isActive = replica.getState() == Replica.State.ACTIVE; if (!live || !isActive) {
for (Replica replica : replicas) { boolean live = clusterState.liveNodesContain(replica .getNodeName()); if (live) {
if (clusterState.liveNodesContain(nodeProps.getNodeName()) && !coreNodeName.equals(thisCoreNodeName)) { if (mustMatchStateFilter == null || mustMatchStateFilter == Replica.State.getState(nodeProps.getState())) { if (mustNotMatchStateFilter == null || mustNotMatchStateFilter != Replica.State.getState(nodeProps.getState())) {
/** * Executes a query against each live and active replica of the specified shard * and aserts that the results are identical. * * @see #queryAndCompare */ public QueryResponse queryAndCompareReplicas(SolrParams params, String shard) throws Exception { ArrayList<SolrClient> shardClients = new ArrayList<>(7); updateMappingsFromZk(jettys, clients); ZkStateReader zkStateReader = cloudClient.getZkStateReader(); List<CloudJettyRunner> solrJetties = shardToJetty.get(shard); assertNotNull("no jetties found for shard: " + shard, solrJetties); for (CloudJettyRunner cjetty : solrJetties) { ZkNodeProps props = cjetty.info; String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP); boolean active = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)) == Replica.State.ACTIVE; boolean live = zkStateReader.getClusterState().liveNodesContain(nodeName); if (active && live) { shardClients.add(cjetty.client.solrClient); } } return queryAndCompare(params, shardClients); }
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; }
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; }
public static int getLiveAndActiveReplicaCount(ZkStateReader zkStateReader, String collection) { Collection<Slice> slices; slices = zkStateReader.getClusterState().getActiveSlices(collection); int liveAndActive = 0; for (Slice slice : slices) { for (Replica replica : slice.getReplicas()) { boolean live = zkStateReader.getClusterState().liveNodesContain(replica.getNodeName()); boolean active = replica.getState() == Replica.State.ACTIVE; if (live && active) { liveAndActive++; } } } return liveAndActive; }
public static int getLiveAndActiveReplicaCount(ZkStateReader zkStateReader, String collection) { Slice[] slices; slices = zkStateReader.getClusterState().getCollection(collection).getActiveSlicesArr(); int liveAndActive = 0; for (Slice slice : slices) { for (Replica replica : slice.getReplicas()) { boolean live = zkStateReader.getClusterState().liveNodesContain(replica.getNodeName()); boolean active = replica.getState() == Replica.State.ACTIVE; if (live && active) { liveAndActive++; } } } return liveAndActive; }