Search in sources :

Example 11 with UpdateResponse

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

the class OneQuery method run.

@Override
public void run() {
    log.info(String.format(Locale.ROOT, "Starting indexing thread: " + getId()));
    while (!Indexer.stopTimeout.hasTimedOut()) {
        int myId = Indexer.idUnique.incrementAndGet();
        Indexer.docsThisCycle.incrementAndGet();
        String core = OCCST.getRandomCore(random);
        OCCST.incrementCoreCount(core);
        Indexer.progress(myId, core);
        for (int idx = 0; idx < 3; ++idx) {
            SolrInputDocument doc = new SolrInputDocument();
            doc.addField("id", "id" + Integer.toString(myId));
            doc.addField("text", "text " + Integer.toString(myId));
            UpdateRequest update = new UpdateRequest();
            update.add(doc);
            try {
                client.setBaseURL(baseUrl + core);
                UpdateResponse response = client.add(doc, OpenCloseCoreStressTest.COMMIT_WITHIN);
                if (response.getStatus() != 0) {
                    log.warn("Failed to index a document to core " + core + " with status " + response.getStatus());
                } else {
                    Indexer.qTimesAccum.addAndGet(response.getQTime());
                    Indexer.updateCounts.incrementAndGet();
                    // retry loop.
                    break;
                }
                // Let's not go crazy here.
                Thread.sleep(100L);
            } catch (Exception e) {
                if (e instanceof InterruptedException)
                    return;
                Indexer.errors.incrementAndGet();
                if (idx == 2) {
                    log.warn("Could not reach server while indexing for three tries, quitting " + e.getMessage());
                } else {
                    log.info("Indexing thread " + Thread.currentThread().getId() + " swallowed one exception " + e.getMessage());
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException tex) {
                        return;
                    }
                }
            }
        }
    }
    log.info("Leaving indexing thread " + getId());
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) IOException(java.io.IOException)

Example 12 with UpdateResponse

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

the class CdcrReplicator method handleException.

private void handleException(Exception e) {
    if (e instanceof CdcrReplicatorException) {
        UpdateRequest req = ((CdcrReplicatorException) e).req;
        UpdateResponse rsp = ((CdcrReplicatorException) e).rsp;
        log.warn("Failed to forward update request {} to target: {}. Got response {}", req, state.getTargetCollection(), rsp);
        state.reportError(CdcrReplicatorState.ErrorType.BAD_REQUEST);
    } else if (e instanceof CloudSolrClient.RouteException) {
        log.warn("Failed to forward update request to target: " + state.getTargetCollection(), e);
        state.reportError(CdcrReplicatorState.ErrorType.BAD_REQUEST);
    } else {
        log.warn("Failed to forward update request to target: " + state.getTargetCollection(), e);
        state.reportError(CdcrReplicatorState.ErrorType.INTERNAL);
    }
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 13 with UpdateResponse

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

the class OverseerCollectionMessageHandler method commit.

void commit(NamedList results, String slice, Replica parentShardLeader) {
    log.debug("Calling soft commit to make sub shard updates visible");
    String coreUrl = new ZkCoreNodeProps(parentShardLeader).getCoreUrl();
    // HttpShardHandler is hard coded to send a QueryRequest hence we go direct
    // and we force open a searcher so that we have documents to show upon switching states
    UpdateResponse updateResponse = null;
    try {
        updateResponse = softCommit(coreUrl);
        processResponse(results, null, coreUrl, updateResponse, slice, Collections.emptySet());
    } catch (Exception e) {
        processResponse(results, e, coreUrl, updateResponse, slice, Collections.emptySet());
        throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to call distrib softCommit on: " + coreUrl, e);
    }
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) SolrServerException(org.apache.solr.client.solrj.SolrServerException) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) SolrException(org.apache.solr.common.SolrException)

Example 14 with UpdateResponse

use of org.apache.solr.client.solrj.response.UpdateResponse in project stanbol by apache.

the class SolrYard method update.

@Override
public final Iterable<Representation> update(Iterable<Representation> representations) throws YardException, IllegalArgumentException, NullPointerException {
    if (representations == null) {
        throw new IllegalArgumentException("The parsed Iterable over Representations MUST NOT be NULL!");
    }
    long start = System.currentTimeMillis();
    Set<String> ids = new HashSet<String>();
    for (Representation representation : representations) {
        if (representation != null) {
            ids.add(representation.getId());
        }
    }
    if (closed) {
        log.warn("The SolrYard '{}' was already closed!", config.getName());
    }
    // for debuging
    int numDocs = ids.size();
    try {
        // returns the ids found in the solrIndex
        ids = checkRepresentations(ids);
    } catch (SolrServerException e) {
        throw new YardException("Error while searching for alredy present documents " + "before executing the actual update for the parsed Representations", e);
    } catch (IOException e) {
        throw new YardException("Unable to access SolrServer", e);
    }
    long checked = System.currentTimeMillis();
    List<SolrInputDocument> inputDocs = new ArrayList<SolrInputDocument>(ids.size());
    List<Representation> updated = new ArrayList<Representation>();
    for (Representation representation : representations) {
        if (representation != null && ids.contains(representation.getId())) {
            // null parsed or not
            // already present
            inputDocs.add(createSolrInputDocument(representation));
            updated.add(representation);
        }
    }
    long created = System.currentTimeMillis();
    if (!inputDocs.isEmpty()) {
        try {
            final UpdateRequest update = new UpdateRequest();
            if (!immediateCommit) {
                update.setCommitWithin(commitWithin);
            }
            update.add(inputDocs);
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

                public UpdateResponse run() throws IOException, SolrServerException {
                    update.process(server);
                    if (immediateCommit) {
                        server.commit();
                    }
                    return null;
                }
            });
        } catch (PrivilegedActionException pae) {
            if (pae.getException() instanceof SolrServerException) {
                throw new YardException("Error while adding updated Documents to the SolrServer", pae.getException());
            } else if (pae.getException() instanceof IOException) {
                throw new YardException("Unable to access SolrServer", pae.getException());
            } else {
                throw RuntimeException.class.cast(pae.getException());
            }
        }
    }
    long ready = System.currentTimeMillis();
    log.info(String.format("Processed updateRequest for %d documents (%d in index " + "| %d updated) in %dms (checked %dms|created %dms| stored%dms)", numDocs, ids.size(), updated.size(), ready - start, checked - start, created - checked, ready - created));
    return updated;
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) PrivilegedActionException(java.security.PrivilegedActionException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) IOException(java.io.IOException) Constraint(org.apache.stanbol.entityhub.servicesapi.query.Constraint) UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) HashSet(java.util.HashSet)

Example 15 with UpdateResponse

use of org.apache.solr.client.solrj.response.UpdateResponse in project ddf by codice.

the class BackupCommandTest method setupMockSolrClientForCollectionOptimization.

private void setupMockSolrClientForCollectionOptimization(String collection, int optimizationStatusCode) throws Exception {
    UpdateResponse optimizationResponse = getMockOptimizationResponse(optimizationStatusCode);
    when(mockSolrClient.optimize(eq(collection))).thenReturn(optimizationResponse);
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse)

Aggregations

UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)43 SolrInputDocument (org.apache.solr.common.SolrInputDocument)17 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)16 IOException (java.io.IOException)13 SolrServerException (org.apache.solr.client.solrj.SolrServerException)12 ArrayList (java.util.ArrayList)10 SolrClient (org.apache.solr.client.solrj.SolrClient)8 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)8 SolrDocument (org.apache.solr.common.SolrDocument)8 NamedList (org.apache.solr.common.util.NamedList)7 Future (java.util.concurrent.Future)6 Test (org.junit.Test)6 ExecutorService (java.util.concurrent.ExecutorService)5 SolrException (org.apache.solr.common.SolrException)5 DefaultSolrThreadFactory (org.apache.solr.util.DefaultSolrThreadFactory)5 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)4 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)3 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)3 MalformedURLException (java.net.MalformedURLException)2 HashMap (java.util.HashMap)2