Пример #1
0
 private void rollBackAndPropagateException(Exception exception) {
   try {
     LOGGER.error(exception.getMessage(), exception);
     solrClient.rollback();
     throw new RuntimeException(exception);
   } catch (IOException | SolrServerException e) {
     LOGGER.error(e.getMessage());
   }
 }
Пример #2
0
  public int index(
      Experiment experiment,
      Map<String, Map<BioentityPropertyName, Set<String>>> bioentityIdToProperties,
      int batchSize) {

    List<SolrInputDocument> toLoad = new ArrayList<>(batchSize);
    int addedIntoThisBatch = 0;
    int addedInTotal = 0;

    try (SolrInputDocumentInputStream solrInputDocumentInputStream =
        new SolrInputDocumentInputStream(
            experimentDataPointStreamFactory.stream(experiment), bioentityIdToProperties)) {
      Iterator<SolrInputDocument> it =
          new IterableObjectInputStream<>(solrInputDocumentInputStream).iterator();
      while (it.hasNext()) {
        while (addedIntoThisBatch < batchSize && it.hasNext()) {
          SolrInputDocument analyticsInputDocument = it.next();
          if (analyticsIndexDocumentValidator.validate(analyticsInputDocument)) {
            toLoad.add(analyticsInputDocument);
            addedIntoThisBatch++;
          }
        }
        if (addedIntoThisBatch > 0) {
          UpdateResponse r = solrClient.add(toLoad);
          LOGGER.info(
              "Sent {} documents for {}, qTime:{}",
              addedIntoThisBatch,
              experiment.getAccession(),
              r.getQTime());
          addedInTotal += addedIntoThisBatch;
          addedIntoThisBatch = 0;
          toLoad = new ArrayList<>(batchSize);
        }
      }
    } catch (IOException | SolrServerException e) {
      LOGGER.error(e.getMessage(), e);
    }
    LOGGER.info("Finished: " + experiment.getAccession());
    return addedInTotal;
  }