Search in sources :

Example 6 with ConcurrentUpdateSolrClient

use of org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient in project jackrabbit-oak by apache.

the class RemoteSolrServerProvider method getIndexingSolrServer.

@CheckForNull
@Override
public SolrClient getIndexingSolrServer() throws Exception {
    SolrClient server = getSolrServer();
    if (server instanceof HttpSolrClient) {
        String url = ((HttpSolrClient) server).getBaseURL();
        ConcurrentUpdateSolrClient concurrentUpdateSolrServer = new ConcurrentUpdateSolrClient(url, 1000, Runtime.getRuntime().availableProcessors());
        concurrentUpdateSolrServer.setConnectionTimeout(remoteSolrServerConfiguration.getConnectionTimeout());
        concurrentUpdateSolrServer.setSoTimeout(remoteSolrServerConfiguration.getSocketTimeout());
        concurrentUpdateSolrServer.blockUntilFinished();
        server = concurrentUpdateSolrServer;
    }
    return server;
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient) CheckForNull(javax.annotation.CheckForNull)

Example 7 with ConcurrentUpdateSolrClient

use of org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient in project solr-cmd-utils by tblsoft.

the class SolrFeeder method doFeed.

public void doFeed() throws Exception {
    this.server = new ConcurrentUpdateSolrClient(serverUrl, queueSize, threads);
    if (threads == 1 && queueSize == 1) {
        this.server = new HttpSolrClient(serverUrl);
    }
    if (deleteIndex) {
        System.out.println("Delete the index.");
        server.deleteByQuery("*:*");
    }
    parse();
    server.commit();
    server.optimize();
    server.close();
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient)

Example 8 with ConcurrentUpdateSolrClient

use of org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient in project mycore by MyCoRe-Org.

the class MCRSolrMCRContentMapIndexHandler method index.

@Override
public void index() throws IOException, SolrServerException {
    int totalCount = contentMap.size();
    LOGGER.info("Handling {} documents", totalCount);
    // multithread processing will result in too many http request
    UpdateResponse updateResponse;
    try {
        Iterator<SolrInputDocument> documents = MCRSolrInputDocumentFactory.getInstance().getDocuments(contentMap);
        SolrClient solrClient = getSolrClient();
        if (solrClient instanceof ConcurrentUpdateSolrClient) {
            // split up to speed up processing
            splitup(documents);
            return;
        }
        if (LOGGER.isDebugEnabled()) {
            ArrayList<SolrInputDocument> debugList = new ArrayList<>();
            while (documents.hasNext()) {
                debugList.add(documents.next());
            }
            LOGGER.debug("Sending these documents: {}", debugList);
            // recreate documents interator;
            documents = debugList.iterator();
        }
        if (solrClient instanceof HttpSolrClient) {
            updateResponse = solrClient.add(documents);
        } else {
            ArrayList<SolrInputDocument> docs = new ArrayList<>(totalCount);
            while (documents.hasNext()) {
                docs.add(documents.next());
            }
            updateResponse = solrClient.add(docs);
        }
    } catch (Throwable e) {
        LOGGER.warn("Error while indexing document collection. Split and retry.", e);
        splitup();
        return;
    }
    if (updateResponse.getStatus() != 0) {
        LOGGER.error("Error while indexing document collection. Split and retry: {}", updateResponse.getResponse());
        splitup();
    } else {
        LOGGER.info("Sending {} documents was successful in {} ms.", totalCount, updateResponse.getElapsedTime());
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrClient(org.apache.solr.client.solrj.SolrClient) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) ArrayList(java.util.ArrayList) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient)

Example 9 with ConcurrentUpdateSolrClient

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

the class SolrExampleStreamingTest method createNewSolrClient.

@Override
public SolrClient createNewSolrClient() {
    try {
        // setup the server...
        String url = jetty.getBaseUrl().toString() + "/collection1";
        // smaller queue size hits locks more often
        ConcurrentUpdateSolrClient concurrentClient = new ErrorTrackingConcurrentUpdateSolrClient(url, 2, 5);
        concurrentClient.setParser(new XMLResponseParser());
        concurrentClient.setRequestWriter(new RequestWriter());
        return concurrentClient;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : RequestWriter(org.apache.solr.client.solrj.request.RequestWriter) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser)

Example 10 with ConcurrentUpdateSolrClient

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

the class StreamingSolrClients method getSolrClient.

public synchronized SolrClient getSolrClient(final SolrCmdDistributor.Req req) {
    String url = getFullUrl(req.node.getUrl());
    ConcurrentUpdateSolrClient client = solrClients.get(url);
    if (client == null) {
        // NOTE: increasing to more than 1 threadCount for the client could cause updates to be reordered
        // on a greater scale since the current behavior is to only increase the number of connections/Runners when
        // the queue is more than half full.
        client = new ErrorReportingConcurrentUpdateSolrClient(url, httpClient, 100, runnerCount, updateExecutor, true, req);
        // minimize connections created
        client.setPollQueueTime(Integer.MAX_VALUE);
        client.setParser(new BinaryResponseParser());
        client.setRequestWriter(new BinaryRequestWriter());
        Set<String> queryParams = new HashSet<>(2);
        queryParams.add(DistributedUpdateProcessor.DISTRIB_FROM);
        queryParams.add(DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM);
        client.setQueryParams(queryParams);
        solrClients.put(url, client);
    }
    return client;
}
Also used : BinaryResponseParser(org.apache.solr.client.solrj.impl.BinaryResponseParser) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient) HashSet(java.util.HashSet)

Aggregations

ConcurrentUpdateSolrClient (org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient)13 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)5 SolrClient (org.apache.solr.client.solrj.SolrClient)4 ArrayList (java.util.ArrayList)3 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)3 IOException (java.io.IOException)2 BinaryRequestWriter (org.apache.solr.client.solrj.impl.BinaryRequestWriter)2 BinaryResponseParser (org.apache.solr.client.solrj.impl.BinaryResponseParser)2 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)2 UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 HashSet (java.util.HashSet)1 List (java.util.List)1 CheckForNull (javax.annotation.CheckForNull)1 GoraException (org.apache.gora.util.GoraException)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 LBHttpSolrClient (org.apache.solr.client.solrj.impl.LBHttpSolrClient)1 XMLResponseParser (org.apache.solr.client.solrj.impl.XMLResponseParser)1 RequestWriter (org.apache.solr.client.solrj.request.RequestWriter)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1