/** * Delete a record from the database. * * @param table * The name of the table * @param key * The record key of the record to delete. * @return Zero on success, a non-zero error code on error. See this class's description for a * discussion of error codes. */ @Override public Status delete(String table, String key) { try { UpdateResponse response; if (batchMode) { response = client.deleteById(table, key, commitTime); } else { response = client.deleteById(table, key); client.commit(table); } return checkStatus(response.getStatus()); } catch (IOException | SolrServerException e) { e.printStackTrace(); } return Status.ERROR; }
protected Optional<SolrException> fromUpdateResponse(UpdateResponse response) { if(response != null && response.getStatus() > 0) { String message = "Solr Update response: " + Joiner.on(",").join(response.getResponse()); return Optional.of(new SolrException(SolrException.ErrorCode.BAD_REQUEST, message)); } return Optional.empty(); }
@Override protected UpdateResponse createResponse(SolrClient client) { return new UpdateResponse(); }
private static boolean evaluate(UpdateResponse response) { LOGGER.debug("Response returned: Status code {}, Elapsed time {}, QTime {}", response.getStatus(), response.getElapsedTime(), response.getQTime()); //any other status code means 'there was an error' return response.getStatus() == 0; }
@Override public UpdateResponse process( SolrServer server ) throws SolrServerException, IOException { long startTime = System.currentTimeMillis(); UpdateResponse res = new UpdateResponse(); res.setResponse( server.request( this ) ); res.setElapsedTime( System.currentTimeMillis()-startTime ); return res; }
private IndexResult indexMultipleDocuments(List<Document> docs, int withinMs) { final List<SolrInputDocument> solrDocs = docs.parallelStream() .map(doc -> createInputDocument(doc)) .collect(Collectors.toList()); try { if (solrClientLogger.isTraceEnabled()) { solrClientLogger.debug(">>> add({})", solrDocs); } else { solrClientLogger.debug(">>> add({})", solrDocs); } for(Document doc : docs){ removeNonParentDocument(doc, withinMs); } final UpdateResponse response = withinMs < 0 ? this.solrClient.add(solrDocs) : this.solrClient.add(solrDocs, withinMs); return new IndexResult(Long.valueOf(response.getQTime())).setElapsedTime(response.getElapsedTime()); } catch (SolrServerException | IOException e) { log.error("Cannot index documents {}", solrDocs, e); throw new SearchServerException("Cannot index documents", e); } }
protected UpdateResponse runUpdate(List<SolrInputDocument> batchToWrite) { try { UpdateResponse result = solr.add(batchToWrite); SolrRecordWriter.incrementCounter(taskId, SolrCounters.class.getName(), SolrCounters.BATCHES_WRITTEN.toString(), 1); SolrRecordWriter.incrementCounter(taskId, SolrCounters.class.getName(), SolrCounters.DOCUMENTS_WRITTEN.toString(), batchToWrite.size()); if (LOG.isDebugEnabled()) { SolrRecordWriter.incrementCounter(taskId, SolrCounters.class.getName(), SolrCounters.BATCH_WRITE_TIME.toString(), result.getElapsedTime()); } return result; } catch (Throwable e) { if (e instanceof Exception) { setBatchWriteException((Exception) e); } else { setBatchWriteException(new Exception(e)); } SolrRecordWriter.incrementCounter(taskId, getClass().getName() + ".errors", e.getClass().getName(), 1); LOG.error("Unable to process batch", e); return null; } }
@Override public void onAddedDocument(UpdateResponse response) { addedUpdatesInLastInterval = addTime(updatesTime, (long)response.getQTime(), addedUpdatesInLastInterval); }
@Override protected UpdateResponse createResponse(SolrClient client) { return new UpdateResponse(); }
private static boolean evaluate(UpdateResponse response) { LOGGER.debug("Response returned: Status code {}, Elapsed time {}, QTime {}", response.getStatus(), response.getElapsedTime(), response.getQTime()); //any other status code means 'there was an error' return response.getStatus() == 0; }
@Override public void storeOntologyEntries(List<OntologyEntryBean> entries) throws StorageEngineException { if (entries.isEmpty()) { LOGGER.debug("storeOntologyEntries called with empty list - ignoring"); } else { try { UpdateResponse response = server.addBeans(entries, config.getCommitWithinMs()); if (response.getStatus() != STATUS_OK) { LOGGER.error("Unexpected response: {}", response.getResponse()); throw new StorageEngineException("Could not store entries: " + response.getResponse()); } } catch (IOException e) { LOGGER.error("IO exception when calling server: {}", e.getMessage()); throw new StorageEngineException(e); } catch (SolrServerException e) { LOGGER.error("Server exception when storing entries: {}", e.getMessage()); throw new StorageEngineException(e); } } }
@Override public UpdateResponse process( SolrServer server ) throws SolrServerException, IOException { long startTime = System.currentTimeMillis(); UpdateResponse res = new UpdateResponse(); res.setResponse( server.request( this ) ); res.setElapsedTime( System.currentTimeMillis()-startTime ); return res; } }
private IndexResult indexSingleDocument(Document doc, int withinMs) { final SolrInputDocument document = createInputDocument(doc); try { if (solrClientLogger.isTraceEnabled()) { solrClientLogger.debug(">>> add({}): {}", doc.getId(), ClientUtils.toXML(document)); } else { solrClientLogger.debug(">>> add({})", doc.getId()); } removeNonParentDocument(doc, withinMs); final UpdateResponse response = withinMs < 0 ? this.solrClient.add(document) : this.solrClient.add(document, withinMs); return new IndexResult(Long.valueOf(response.getQTime())).setElapsedTime(response.getElapsedTime()); } catch (SolrServerException | IOException e) { log.error("Cannot index document {}", document.getField(ID) , e); throw new SearchServerException("Cannot index document", e); } }
protected UpdateResponse runUpdate(List<SolrInputDocument> batchToWrite) { try { UpdateResponse result = solr.add(batchToWrite); SolrRecordWriter.incrementCounter(taskId, SolrCounters.class.getName(), SolrCounters.BATCHES_WRITTEN.toString(), 1); SolrRecordWriter.incrementCounter(taskId, SolrCounters.class.getName(), SolrCounters.DOCUMENTS_WRITTEN.toString(), batchToWrite.size()); if (LOG.isDebugEnabled()) { SolrRecordWriter.incrementCounter(taskId, SolrCounters.class.getName(), SolrCounters.BATCH_WRITE_TIME.toString(), result.getElapsedTime()); } return result; } catch (Throwable e) { if (e instanceof Exception) { setBatchWriteException((Exception) e); } else { setBatchWriteException(new Exception(e)); } SolrRecordWriter.incrementCounter(taskId, getClass().getName() + ".errors", e.getClass().getName(), 1); LOG.error("Unable to process batch", e); return null; } }
@Override public void onCommit(UpdateResponse response) { addedCommitsInLastInterval = addTime(commitTime, (long)response.getQTime(), addedCommitsInLastInterval); }
/** * Delete a record from the database. * * @param table * The name of the table * @param key * The record key of the record to delete. * @return Zero on success, a non-zero error code on error. See this class's description for a * discussion of error codes. */ @Override public Status delete(String table, String key) { try { UpdateResponse response; if (batchMode) { response = client.deleteById(table, key, commitTime); } else { response = client.deleteById(table, key); client.commit(table); } return checkStatus(response.getStatus()); } catch (IOException | SolrServerException e) { e.printStackTrace(); } return Status.ERROR; }
@Override public UpdateResponse rollbackTransaction() throws SolrServerException, IOException { return new UpdateResponse(); }
@Override public UpdateResponse process(SolrServer server) throws SolrServerException, IOException { long startTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS); UpdateResponse res = new UpdateResponse(); res.setResponse(server.request(this)); long endTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS); res.setElapsedTime(endTime - startTime); return res; }
@Override public DeleteResult execute(Delete delete, DocumentFactory factory) { String query = SolrUtils.Query.buildFilterString(delete.getQuery(), factory, delete.getUpdateContext(),true); try { solrClientLogger.debug(">>> delete query({})", query); //Finding the ID of the documents to delete final SolrQuery solrQuery = new SolrQuery(); solrQuery.setParam(CommonParams.Q, "*:*"); solrQuery.setParam(CommonParams.FQ,query.trim().replaceAll("^\\+","").split("\\+")); final QueryResponse response = solrClient.query(solrQuery, REQUEST_METHOD); long qTime = 0; long elapsedTime = 0; if(Objects.nonNull(response) && CollectionUtils.isNotEmpty(response.getResults())){ final List<String> idList = response.getResults().stream().map(doc -> (String) doc.get(ID)).collect(Collectors.toList()); final UpdateResponse deleteResponse = solrClient.deleteById(idList); qTime = deleteResponse.getQTime(); elapsedTime = deleteResponse.getElapsedTime(); //Deleting nested documents final UpdateResponse deleteNestedResponse = solrClient.deleteByQuery("_root_:(" + StringUtils.join(idList, " OR ") + ")"); qTime += deleteNestedResponse.getQTime(); elapsedTime += deleteNestedResponse.getElapsedTime(); } return new DeleteResult(qTime).setElapsedTime(elapsedTime); } catch (SolrServerException | IOException e) { log.error("Cannot delete with query {}", query, e); throw new SearchServerException("Cannot delete with query", e); } }
protected UpdateResponse runUpdate(List<SolrInputDocument> batchToWrite) { try { UpdateResponse result = solr.add(batchToWrite); SolrRecordWriter.incrementCounter(taskId, "SolrRecordWriter", "BatchesWritten", 1); SolrRecordWriter.incrementCounter(taskId, "SolrRecordWriter", "DocumentsWritten", batchToWrite.size()); SolrRecordWriter.incrementCounter(taskId, "SolrRecordWriter", "BatchesWriteTime", result.getElapsedTime()); return result; } catch(Throwable e) { SolrRecordWriter.incrementCounter(taskId, "SolrRecordWriter", e.getClass().getName(), 1); if(e instanceof Exception) { setBatchWriteException((Exception) e); } else { setBatchWriteException(new Exception(e)); } return null; } }