Search in sources :

Example 46 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class AbstractFullDistribZkTestBase method checkShardConsistency.

/**
   * Returns a non-null string if replicas within the same shard do not have a
   * consistent number of documents.
   * If expectFailure==false, the exact differences found will be logged since
   * this would be an unexpected failure.
   * verbose causes extra debugging into to be displayed, even if everything is
   * consistent.
   */
protected String checkShardConsistency(String shard, boolean expectFailure, boolean verbose) throws Exception {
    List<CloudJettyRunner> solrJetties = shardToJetty.get(shard);
    if (solrJetties == null) {
        throw new RuntimeException("shard not found:" + shard + " keys:" + shardToJetty.keySet());
    }
    long num = -1;
    long lastNum = -1;
    String failMessage = null;
    if (verbose)
        System.err.println("check const of " + shard);
    int cnt = 0;
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    assertEquals("The client count does not match up with the shard count for slice:" + shard, zkStateReader.getClusterState().getSlice(DEFAULT_COLLECTION, shard).getReplicasMap().size(), solrJetties.size());
    CloudJettyRunner lastJetty = null;
    for (CloudJettyRunner cjetty : solrJetties) {
        ZkNodeProps props = cjetty.info;
        if (verbose)
            System.err.println("client" + cnt++);
        if (verbose)
            System.err.println("PROPS:" + props);
        try {
            // "tests" is just a tag that won't do anything except be echoed in logs
            SolrParams query = params("q", "*:*", "rows", "0", "distrib", "false", "tests", "checkShardConsistency");
            num = cjetty.client.solrClient.query(query).getResults().getNumFound();
        } catch (SolrServerException e) {
            if (verbose)
                System.err.println("error contacting client: " + e.getMessage() + "\n");
            continue;
        } catch (SolrException e) {
            if (verbose)
                System.err.println("error contacting client: " + e.getMessage() + "\n");
            continue;
        }
        boolean live = false;
        String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
        if (zkStateReader.getClusterState().liveNodesContain(nodeName)) {
            live = true;
        }
        if (verbose)
            System.err.println(" live:" + live);
        if (verbose)
            System.err.println(" num:" + num + "\n");
        boolean active = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)) == Replica.State.ACTIVE;
        if (active && live) {
            if (lastNum > -1 && lastNum != num && failMessage == null) {
                failMessage = shard + " is not consistent.  Got " + lastNum + " from " + lastJetty.url + " (previous client)" + " and got " + num + " from " + cjetty.url;
                if (!expectFailure || verbose) {
                    System.err.println("######" + failMessage);
                    SolrQuery query = new SolrQuery("*:*");
                    query.set("distrib", false);
                    query.set("fl", "id,_version_");
                    query.set("rows", "100000");
                    query.set("sort", "id asc");
                    query.set("tests", "checkShardConsistency/showDiff");
                    SolrDocumentList lst1 = lastJetty.client.solrClient.query(query).getResults();
                    SolrDocumentList lst2 = cjetty.client.solrClient.query(query).getResults();
                    CloudInspectUtil.showDiff(lst1, lst2, lastJetty.url, cjetty.url);
                }
            }
            lastNum = num;
            lastJetty = cjetty;
        }
    }
    return failMessage;
}
Also used : ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException)

Example 47 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class AbstractFullDistribZkTestBase method checkShardConsistency.

/* Checks shard consistency and optionally checks against the control shard.
   * The test will be failed if differences are found.
   */
protected void checkShardConsistency(boolean checkVsControl, boolean verbose, Set<String> addFails, Set<String> deleteFails) throws Exception {
    updateMappingsFromZk(jettys, clients, true);
    Set<String> theShards = shardToJetty.keySet();
    String failMessage = null;
    for (String shard : theShards) {
        String shardFailMessage = checkShardConsistency(shard, false, verbose);
        if (shardFailMessage != null && failMessage == null) {
            failMessage = shardFailMessage;
        }
    }
    if (failMessage != null) {
        fail(failMessage);
    }
    if (!checkVsControl)
        return;
    // add a tag to aid in debugging via logs
    SolrParams q = params("q", "*:*", "rows", "0", "tests", "checkShardConsistency(vsControl)");
    SolrDocumentList controlDocList = controlClient.query(q).getResults();
    long controlDocs = controlDocList.getNumFound();
    SolrDocumentList cloudDocList = cloudClient.query(q).getResults();
    long cloudClientDocs = cloudDocList.getNumFound();
    // now check that the right # are on each shard
    theShards = shardToJetty.keySet();
    int cnt = 0;
    for (String s : theShards) {
        int times = shardToJetty.get(s).size();
        for (int i = 0; i < times; i++) {
            try {
                CloudJettyRunner cjetty = shardToJetty.get(s).get(i);
                ZkNodeProps props = cjetty.info;
                SolrClient client = cjetty.client.solrClient;
                boolean active = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)) == Replica.State.ACTIVE;
                if (active) {
                    SolrQuery query = new SolrQuery("*:*");
                    query.set("distrib", false);
                    long results = client.query(query).getResults().getNumFound();
                    if (verbose)
                        System.err.println(new ZkCoreNodeProps(props).getCoreUrl() + " : " + results);
                    if (verbose)
                        System.err.println("shard:" + props.getStr(ZkStateReader.SHARD_ID_PROP));
                    cnt += results;
                    break;
                }
            } catch (Exception e) {
                // if we have a problem, try the next one
                if (i == times - 1) {
                    throw e;
                }
            }
        }
    }
    if (controlDocs != cnt || cloudClientDocs != controlDocs) {
        String msg = "document count mismatch.  control=" + controlDocs + " sum(shards)=" + cnt + " cloudClient=" + cloudClientDocs;
        log.error(msg);
        boolean shouldFail = CloudInspectUtil.compareResults(controlClient, cloudClient, addFails, deleteFails);
        if (shouldFail) {
            fail(msg);
        }
    }
}
Also used : ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 48 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class AbstractFullDistribZkTestBase method getUrlFromZk.

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))) {
                //new ZkCoreNodeProps(node).getCoreUrl();
                return ZkCoreNodeProps.getCoreUrl(node.getStr(ZkStateReader.BASE_URL_PROP), collection);
            }
        }
    }
    throw new RuntimeException("Could not find a live node for collection:" + collection);
}
Also used : ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) Replica(org.apache.solr.common.cloud.Replica) Entry(java.util.Map.Entry) Slice(org.apache.solr.common.cloud.Slice) Map(java.util.Map) Utils.makeMap(org.apache.solr.common.util.Utils.makeMap) HashMap(java.util.HashMap) SolrException(org.apache.solr.common.SolrException)

Example 49 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class ChaosMonkey method checkIfKillIsLegal.

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;
}
Also used : Slice(org.apache.solr.common.cloud.Slice) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) CloudJettyRunner(org.apache.solr.cloud.AbstractFullDistribZkTestBase.CloudJettyRunner) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica)

Example 50 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class ChaosMonkey method getTypeForJetty.

private Type getTypeForJetty(String sliceName, CloudJettyRunner cjetty) {
    DocCollection docCollection = zkStateReader.getClusterState().getCollection(collection);
    Slice slice = docCollection.getSlice(sliceName);
    ZkNodeProps props = slice.getReplicasMap().get(cjetty.coreNodeName);
    if (props == null) {
        throw new RuntimeException("shard name " + cjetty.coreNodeName + " not found in " + slice.getReplicasMap().keySet());
    }
    return Replica.Type.valueOf(props.getStr(ZkStateReader.REPLICA_TYPE));
}
Also used : Slice(org.apache.solr.common.cloud.Slice) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) DocCollection(org.apache.solr.common.cloud.DocCollection)

Aggregations

ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)91 SolrException (org.apache.solr.common.SolrException)35 HashMap (java.util.HashMap)28 Replica (org.apache.solr.common.cloud.Replica)22 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)20 ArrayList (java.util.ArrayList)19 Slice (org.apache.solr.common.cloud.Slice)19 KeeperException (org.apache.zookeeper.KeeperException)19 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)16 Test (org.junit.Test)16 DocCollection (org.apache.solr.common.cloud.DocCollection)15 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)14 Map (java.util.Map)13 ClusterState (org.apache.solr.common.cloud.ClusterState)13 IOException (java.io.IOException)10 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)10 ZooKeeperException (org.apache.solr.common.cloud.ZooKeeperException)10 NamedList (org.apache.solr.common.util.NamedList)10 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)9 SolrCore (org.apache.solr.core.SolrCore)8