Search in sources :

Example 21 with SolrServerException

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

the class MissingSegmentRecoveryTest method setup.

@Before
public void setup() throws SolrServerException, IOException {
    CollectionAdminRequest.createCollection(collection, "conf", 1, 2).setMaxShardsPerNode(1).process(cluster.getSolrClient());
    waitForState("Expected a collection with one shard and two replicas", collection, clusterShape(1, 2));
    cluster.getSolrClient().setDefaultCollection(collection);
    List<SolrInputDocument> docs = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("id", i);
        docs.add(doc);
    }
    cluster.getSolrClient().add(docs);
    cluster.getSolrClient().commit();
    DocCollection state = getCollectionState(collection);
    leader = state.getLeader("shard1");
    replica = getRandomReplica(state.getSlice("shard1"), (r) -> leader != r);
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Files(java.nio.file.Files) Slow(org.apache.lucene.util.LuceneTestCase.Slow) DocCollection(org.apache.solr.common.cloud.DocCollection) SolrCore(org.apache.solr.core.SolrCore) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) Replica(org.apache.solr.common.cloud.Replica) ArrayList(java.util.ArrayList) SolrServerException(org.apache.solr.client.solrj.SolrServerException) List(java.util.List) SolrQuery(org.apache.solr.client.solrj.SolrQuery) After(org.junit.After) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Before(org.junit.Before) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) Before(org.junit.Before)

Example 22 with SolrServerException

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

the class UnloadDistributedZkTest method testUnloadLotsOfCores.

private void testUnloadLotsOfCores() throws Exception {
    SolrClient client = clients.get(2);
    String url3 = getBaseUrl(client);
    try (final HttpSolrClient adminClient = getHttpSolrClient(url3)) {
        adminClient.setConnectionTimeout(15000);
        adminClient.setSoTimeout(60000);
        int cnt = atLeast(3);
        ThreadPoolExecutor executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(0, Integer.MAX_VALUE, 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new DefaultSolrThreadFactory("testExecutor"));
        try {
            // create the cores
            createCores(adminClient, executor, "multiunload", 2, cnt);
        } finally {
            ExecutorUtil.shutdownAndAwaitTermination(executor);
        }
        executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(0, Integer.MAX_VALUE, 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new DefaultSolrThreadFactory("testExecutor"));
        try {
            for (int j = 0; j < cnt; j++) {
                final int freezeJ = j;
                executor.execute(() -> {
                    Unload unloadCmd = new Unload(true);
                    unloadCmd.setCoreName("multiunload" + freezeJ);
                    try {
                        adminClient.request(unloadCmd);
                    } catch (SolrServerException | IOException e) {
                        throw new RuntimeException(e);
                    }
                });
                Thread.sleep(random().nextInt(50));
            }
        } finally {
            ExecutorUtil.shutdownAndAwaitTermination(executor);
        }
    }
}
Also used : SolrServerException(org.apache.solr.client.solrj.SolrServerException) DefaultSolrThreadFactory(org.apache.solr.util.DefaultSolrThreadFactory) IOException(java.io.IOException) ExecutorUtil(org.apache.solr.common.util.ExecutorUtil) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Unload(org.apache.solr.client.solrj.request.CoreAdminRequest.Unload) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 23 with SolrServerException

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

the class AbstractFullDistribZkTestBase method showCounts.

public void showCounts() {
    Set<String> theShards = shardToJetty.keySet();
    for (String shard : theShards) {
        List<CloudJettyRunner> solrJetties = shardToJetty.get(shard);
        for (CloudJettyRunner cjetty : solrJetties) {
            ZkNodeProps props = cjetty.info;
            System.err.println("PROPS:" + props);
            try {
                SolrParams query = params("q", "*:*", "rows", "0", "distrib", "false", "tests", // "tests" is just a
                "checkShardConsistency");
                // tag that won't do
                // anything except be
                // echoed in logs
                long num = cjetty.client.solrClient.query(query).getResults().getNumFound();
                System.err.println("DOCS:" + num);
            } catch (SolrServerException | SolrException | IOException e) {
                System.err.println("error contacting client: " + e.getMessage() + "\n");
                continue;
            }
            boolean live = false;
            String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
            ZkStateReader zkStateReader = cloudClient.getZkStateReader();
            if (zkStateReader.getClusterState().liveNodesContain(nodeName)) {
                live = true;
            }
            System.err.println(" live:" + live);
        }
    }
}
Also used : ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) 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 24 with SolrServerException

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

the class TestCloudPivotFacet method assertPivotCountsAreCorrect.

/**
   * Given some query params, executes the request against the cloudClient and 
   * then walks the pivot facet values in the response, treating each one as a 
   * filter query to assert the pivot counts are correct.
   */
private void assertPivotCountsAreCorrect(SolrParams baseParams, SolrParams pivotParams) throws SolrServerException {
    SolrParams initParams = SolrParams.wrapAppended(pivotParams, baseParams);
    log.info("Doing full run: {}", initParams);
    countNumFoundChecks = 0;
    NamedList<List<PivotField>> pivots = null;
    try {
        QueryResponse initResponse = cloudClient.query(initParams);
        pivots = initResponse.getFacetPivot();
        assertNotNull(initParams + " has null pivots?", pivots);
        assertEquals(initParams + " num pivots", initParams.getParams("facet.pivot").length, pivots.size());
    } catch (Exception e) {
        throw new RuntimeException("init query failed: " + initParams + ": " + e.getMessage(), e);
    }
    try {
        for (Map.Entry<String, List<PivotField>> pivot : pivots) {
            final String pivotKey = pivot.getKey();
            // :HACK: for counting the max possible pivot depth
            final int maxDepth = 1 + pivotKey.length() - pivotKey.replace(",", "").length();
            assertTraceOk(pivotKey, baseParams, pivot.getValue());
            // will catch it.
            for (PivotField constraint : pivot.getValue()) {
                int depth = assertPivotCountsAreCorrect(pivotKey, baseParams, constraint);
                // we can't assert that the depth reached is the same as the depth requested
                // because the fq and/or mincount may have pruned the tree too much
                assertTrue("went too deep: " + depth + ": " + pivotKey + " ==> " + pivot, depth <= maxDepth);
            }
        }
    } catch (AssertionError e) {
        throw new AssertionError(initParams + " ==> " + e.getMessage(), e);
    } finally {
        log.info("Ending full run (countNumFoundChecks={}): {}", countNumFoundChecks, initParams);
    }
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) PivotField(org.apache.solr.client.solrj.response.PivotField) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) Map(java.util.Map) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 25 with SolrServerException

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

the class StoppableIndexingThread method run.

@Override
public void run() {
    int i = 0;
    int numDone = 0;
    numDeletes = 0;
    numAdds = 0;
    while (true && !stop) {
        if (numCycles != -1) {
            if (numDone > numCycles) {
                break;
            }
        }
        ++numDone;
        String id = this.id + "-" + i;
        ++i;
        boolean addFailed = false;
        if (doDeletes && AbstractFullDistribZkTestBase.random().nextBoolean() && deletes.size() > 0) {
            String deleteId = deletes.remove(0);
            try {
                numDeletes++;
                if (controlClient != null) {
                    UpdateRequest req = new UpdateRequest();
                    req.deleteById(deleteId);
                    req.setParam("CONTROL", "TRUE");
                    req.process(controlClient);
                }
                cloudClient.deleteById(deleteId);
            } catch (Exception e) {
                System.err.println("REQUEST FAILED for id=" + deleteId);
                e.printStackTrace();
                if (e instanceof SolrServerException) {
                    System.err.println("ROOT CAUSE for id=" + deleteId);
                    ((SolrServerException) e).getRootCause().printStackTrace();
                }
                deleteFails.add(deleteId);
            }
        }
        try {
            numAdds++;
            SolrInputDocument doc = new SolrInputDocument();
            addFields(doc, "id", id, i1, 50, t1, "to come to the aid of their country.");
            addFields(doc, "rnd_b", true);
            docs.add(doc);
            if (docs.size() >= batchSize) {
                indexDocs(docs);
                docs.clear();
            }
        } catch (Exception e) {
            addFailed = true;
            System.err.println("REQUEST FAILED for id=" + id);
            e.printStackTrace();
            if (e instanceof SolrServerException) {
                System.err.println("ROOT CAUSE for id=" + id);
                ((SolrServerException) e).getRootCause().printStackTrace();
            }
            addFails.add(id);
        }
        if (!addFailed && doDeletes && AbstractFullDistribZkTestBase.random().nextBoolean()) {
            deletes.add(id);
        }
        if (docs.size() > 0 && pauseBetweenUpdates) {
            try {
                Thread.sleep(AbstractFullDistribZkTestBase.random().nextInt(500) + 50);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    }
    System.err.println("added docs:" + numAdds + " with " + (addFails.size() + deleteFails.size()) + " fails" + " deletes:" + numDeletes);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Aggregations

SolrServerException (org.apache.solr.client.solrj.SolrServerException)281 IOException (java.io.IOException)210 SolrQuery (org.apache.solr.client.solrj.SolrQuery)101 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)97 ArrayList (java.util.ArrayList)58 SolrException (org.apache.solr.common.SolrException)57 SolrDocument (org.apache.solr.common.SolrDocument)55 SolrInputDocument (org.apache.solr.common.SolrInputDocument)50 SolrDocumentList (org.apache.solr.common.SolrDocumentList)44 HashMap (java.util.HashMap)30 Map (java.util.Map)29 List (java.util.List)27 UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)26 SolrClient (org.apache.solr.client.solrj.SolrClient)23 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)23 NamedList (org.apache.solr.common.util.NamedList)22 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)19 Date (java.util.Date)18 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)17 SolrParams (org.apache.solr.common.params.SolrParams)13