Search in sources :

Example 26 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class ShardSplitTest method checkSubShardConsistency.

protected void checkSubShardConsistency(String shard) throws SolrServerException, IOException {
    SolrQuery query = new SolrQuery("*:*").setRows(1000).setFields("id", "_version_");
    query.set("distrib", false);
    ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
    Slice slice = clusterState.getSlice(AbstractDistribZkTestBase.DEFAULT_COLLECTION, shard);
    long[] numFound = new long[slice.getReplicasMap().size()];
    int c = 0;
    for (Replica replica : slice.getReplicas()) {
        String coreUrl = new ZkCoreNodeProps(replica).getCoreUrl();
        QueryResponse response;
        try (HttpSolrClient client = getHttpSolrClient(coreUrl)) {
            response = client.query(query);
        }
        numFound[c++] = response.getResults().getNumFound();
        log.info("Shard: " + shard + " Replica: {} has {} docs", coreUrl, String.valueOf(response.getResults().getNumFound()));
        assertTrue("Shard: " + shard + " Replica: " + coreUrl + " has 0 docs", response.getResults().getNumFound() > 0);
    }
    for (int i = 0; i < slice.getReplicasMap().size(); i++) {
        assertEquals(shard + " is not consistent", numFound[0], numFound[i]);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) ClusterState(org.apache.solr.common.cloud.ClusterState) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) Slice(org.apache.solr.common.cloud.Slice) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) Replica(org.apache.solr.common.cloud.Replica) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 27 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class DistribDocExpirationUpdateProcessorTest method getIndexVersionOfAllReplicas.

/**
   * returns a map whose key is the coreNodeName and whose value is what the replication
   * handler returns for the indexversion
   */
private Map<String, Long> getIndexVersionOfAllReplicas() throws IOException, SolrServerException {
    Map<String, Long> results = new HashMap<String, Long>();
    DocCollection collectionState = cluster.getSolrClient().getZkStateReader().getClusterState().getCollection(COLLECTION);
    for (Replica replica : collectionState.getReplicas()) {
        String coreName = replica.getCoreName();
        try (HttpSolrClient client = getHttpSolrClient(replica.getCoreUrl())) {
            ModifiableSolrParams params = new ModifiableSolrParams();
            params.set("command", "indexversion");
            params.set("_trace", "getIndexVersion");
            params.set("qt", ReplicationHandler.PATH);
            QueryRequest req = new QueryRequest(params);
            NamedList<Object> res = client.request(req);
            assertNotNull("null response from server: " + coreName, res);
            Object version = res.get("indexversion");
            assertNotNull("null version from server: " + coreName, version);
            assertTrue("version isn't a long: " + coreName, version instanceof Long);
            results.put(coreName, (Long) version);
            long numDocs = client.query(params("q", "*:*", "distrib", "false", "rows", "0", "_trace", "counting_docs")).getResults().getNumFound();
            log.info("core=" + coreName + "; ver=" + version + "; numDocs=" + numDocs);
        }
    }
    return results;
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) HashMap(java.util.HashMap) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 28 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class TestCloudJSONFacetJoinDomain method afterClass.

@AfterClass
private static void afterClass() throws Exception {
    CLOUD_CLIENT.close();
    CLOUD_CLIENT = null;
    for (HttpSolrClient client : CLIENTS) {
        client.close();
    }
    CLIENTS = null;
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) AfterClass(org.junit.AfterClass)

Example 29 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class SyncSliceTest method test.

@Test
public void test() throws Exception {
    handle.clear();
    handle.put("timestamp", SKIPVAL);
    waitForThingsToLevelOut(30);
    del("*:*");
    List<CloudJettyRunner> skipServers = new ArrayList<>();
    int docId = 0;
    indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "to come to the aid of their country.");
    indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "old haven was blue.");
    skipServers.add(shardToJetty.get("shard1").get(1));
    indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "but the song was fancy.");
    skipServers.add(shardToJetty.get("shard1").get(2));
    indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "under the moon and over the lake");
    commit();
    waitForRecoveriesToFinish(false);
    // shard should be inconsistent
    String shardFailMessage = checkShardConsistency("shard1", true, false);
    assertNotNull(shardFailMessage);
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionAction.SYNCSHARD.toString());
    params.set("collection", "collection1");
    params.set("shard", "shard1");
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    String baseUrl = ((HttpSolrClient) shardToJetty.get("shard1").get(2).client.solrClient).getBaseURL();
    baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
    try (HttpSolrClient baseClient = getHttpSolrClient(baseUrl)) {
        // we only set the connect timeout, not so timeout
        baseClient.setConnectionTimeout(30000);
        baseClient.request(request);
    }
    waitForThingsToLevelOut(15);
    checkShardConsistency(false, true);
    long cloudClientDocs = cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound();
    assertEquals(4, cloudClientDocs);
    // kill the leader - new leader could have all the docs or be missing one
    CloudJettyRunner leaderJetty = shardToLeaderJetty.get("shard1");
    // but not the leader
    skipServers = getRandomOtherJetty(leaderJetty, null);
    // this doc won't be on one node
    indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "to come to the aid of their country.");
    Set<CloudJettyRunner> jetties = new HashSet<>();
    jetties.addAll(shardToJetty.get("shard1"));
    jetties.remove(leaderJetty);
    assertEquals(getShardCount() - 1, jetties.size());
    chaosMonkey.killJetty(leaderJetty);
    Thread.sleep(3000);
    waitForNoShardInconsistency();
    Thread.sleep(1000);
    checkShardConsistency(false, true);
    cloudClientDocs = cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound();
    assertEquals(5, cloudClientDocs);
    CloudJettyRunner deadJetty = leaderJetty;
    // let's get the latest leader
    while (deadJetty == leaderJetty) {
        updateMappingsFromZk(this.jettys, this.clients);
        leaderJetty = shardToLeaderJetty.get("shard1");
    }
    // bring back dead node
    // he is not the leader anymore
    ChaosMonkey.start(deadJetty.jetty);
    waitTillAllNodesActive();
    skipServers = getRandomOtherJetty(leaderJetty, deadJetty);
    skipServers.addAll(getRandomOtherJetty(leaderJetty, deadJetty));
    // skip list should be 
    //    System.out.println("leader:" + leaderJetty.url);
    //    System.out.println("dead:" + deadJetty.url);
    //    System.out.println("skip list:" + skipServers);
    // we are skipping  2 nodes
    assertEquals(2, skipServers.size());
    // more docs than can peer sync
    for (int i = 0; i < 300; i++) {
        indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "to come to the aid of their country.");
    }
    commit();
    Thread.sleep(1000);
    waitForRecoveriesToFinish(false);
    // shard should be inconsistent
    shardFailMessage = waitTillInconsistent();
    assertNotNull("Test Setup Failure: shard1 should have just been set up to be inconsistent - but it's still consistent. Leader:" + leaderJetty.url + " Dead Guy:" + deadJetty.url + "skip list:" + skipServers, shardFailMessage);
    // good place to test compareResults
    boolean shouldFail = CloudInspectUtil.compareResults(controlClient, cloudClient);
    assertTrue("A test that compareResults is working correctly failed", shouldFail);
    jetties = new HashSet<>();
    jetties.addAll(shardToJetty.get("shard1"));
    jetties.remove(leaderJetty);
    assertEquals(getShardCount() - 1, jetties.size());
    // kill the current leader
    chaosMonkey.killJetty(leaderJetty);
    waitForNoShardInconsistency();
    checkShardConsistency(true, true);
    success = true;
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ArrayList(java.util.ArrayList) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrQuery(org.apache.solr.client.solrj.SolrQuery) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 30 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class ShardSplitTest method createNewSolrClient.

@Override
protected SolrClient createNewSolrClient(String collection, String baseUrl) {
    HttpSolrClient client = (HttpSolrClient) super.createNewSolrClient(collection, baseUrl);
    client.setSoTimeout(5 * 60 * 1000);
    return client;
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient)

Aggregations

HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)187 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)48 SolrClient (org.apache.solr.client.solrj.SolrClient)46 Test (org.junit.Test)46 SolrQuery (org.apache.solr.client.solrj.SolrQuery)38 ArrayList (java.util.ArrayList)35 Replica (org.apache.solr.common.cloud.Replica)34 SolrInputDocument (org.apache.solr.common.SolrInputDocument)31 IOException (java.io.IOException)26 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)25 Slice (org.apache.solr.common.cloud.Slice)25 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)24 SolrException (org.apache.solr.common.SolrException)23 SolrServerException (org.apache.solr.client.solrj.SolrServerException)21 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)20 NamedList (org.apache.solr.common.util.NamedList)19 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)18 DocCollection (org.apache.solr.common.cloud.DocCollection)18 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)15 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)15