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());
}
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);
}
}
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);
}
}
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;
}
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);
}
Aggregations