/** * Send a document to Solr for indexing with re-try support in case of communication exception. */ protected void addDocWithRetry(CloudSolrServer solr, SolrInputDocument doc, int retryInSecs) throws Exception { try { solr.add(doc); } catch (Exception solrExc) { // add some basic re-try logic in the event of a communication error Throwable rootCause = SolrException.getRootCause(solrExc); if (rootCause instanceof IOException) { log.error(rootCause.getClass().getSimpleName()+ " when trying to send a document to SolrCloud, will re-try after waiting "+ retryInSecs+" seconds; "+rootCause); try { Thread.sleep(retryInSecs*1000); } catch (InterruptedException ignoreMe) {} // re-try this doc solr.add(doc); } } }
@SuppressWarnings("rawtypes") protected static int sendDocsWithRetry(CloudSolrClient cloudClient, String collection, List<SolrInputDocument> batch, int minRf, int maxRetries, int waitBeforeRetry) throws Exception { UpdateRequest up = new UpdateRequest(); up.add(batch); NamedList resp = null; int numRetries = 0; while(true) { try { resp = cloudClient.request(up, collection); return cloudClient.getMinAchievedReplicationFactor(cloudClient.getDefaultCollection(), resp); } catch (Exception exc) { Throwable rootCause = SolrException.getRootCause(exc); if (++numRetries <= maxRetries) { log.warn("ERROR: " + rootCause + " ... Sleeping for " + waitBeforeRetry + " seconds before re-try ..."); Thread.sleep(waitBeforeRetry * 1000L); } else { log.error("No more retries available! Add batch failed due to: " + rootCause); throw exc; } } } }
Throwable rootCause = SolrException.getRootCause(exc);
Throwable rootCause = SolrException.getRootCause(exc);