private String getExceptionKey(final String str) { RetryingSolrServer solr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); return solr.getExceptionKey(new Throwable() { @Override public String toString() { return str; } }); }
private SolrClient getNonRetryingSolrServer() { SolrClient s = server; while (s instanceof RetryingSolrServer) { s = ((RetryingSolrServer)s).getUnderlyingSolrServer(); } return s; }
private String normalizeRequestKey(String str) { RetryingSolrServer solr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); return solr.normalizeRequestKey(str); }
RetryPolicy retryPolicy = null; totalRequestCount.incrementAndGet(); getMetrics().markMeter(ROOT_PREFIX + "requests", 1); Map<String, MutableLong> exceptionRootCauseCounters = new HashMap<String, MutableLong>(); final long startTime = System.nanoTime(); while (true) { final long nanosToWaitForRateLimiter = limitRequestRate(request); try { isShuttingDown.await(nanosToWaitForRateLimiter, TimeUnit.NANOSECONDS); } catch (Exception exception) { long requestDuration = System.nanoTime() - lastStartTime; String exceptionTopLevelMsg = limitStringLength(getExceptionKey(exception)); String exceptionRootCauseMsg = limitStringLength(getExceptionKey(getRootCause(exception))); String requestKey = limitStringLength(getRequestKey(request)); handleException(request, exceptionTopLevelMsg, exceptionRootCauseMsg, requestKey, requestDuration); String reason = "n/a"; boolean retry = !isShuttingDown(); if (!retry) { reason = "Solrj client is shutting down"; + "per RetryPolicy {" + retryPolicy + "}"; } else { retry = !isShuttingDown(); // recheck if (!retry) { reason = "Solrj client is shutting down(2)"; retryCount++; totalRetryCount.incrementAndGet();
DocumentLoader getLoader(RetryPolicyFactory retryPolicyFactory, MetricsFacade retryMetricsFacade) { if (context instanceof SolrMorphlineContext) { DocumentLoader loader = ((SolrMorphlineContext)context).getDocumentLoader(); if (loader != null) { return loader; } } SolrClient solrServer = getSolrServer(); if (solrServer instanceof CloudSolrClient) { try { ((CloudSolrClient)solrServer).setIdField(getIndexSchema().getUniqueKeyField().getName()); } catch (RuntimeException e) { try { solrServer.close(); // release resources } catch (Exception ex2) { LOG.debug("Cannot get index schema and cannot shutdown CloudSolrServer", ex2); } throw new RuntimeException(e); // rethrow root cause } } if (retryPolicyFactory != null) { solrServer = new RetryingSolrServer(solrServer, retryPolicyFactory, retryMetricsFacade); } return new SolrServerDocumentLoader(solrServer, batchSize); }
@Test public void testGetUnderlyingSolrServer() throws Exception { RetryingSolrServer retryingSolr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); assertSame(solrServer, retryingSolr.getUnderlyingSolrServer()); }
@Test public void testGetBinder() throws Exception { RetryingSolrServer retryingSolr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); assertSame(solrServer.getBinder(), retryingSolr.getBinder()); }
protected String getRequestKey(SolrRequest request) { String str = request.getClass().getSimpleName() + "."; return REDACT_QUERY_REQUEST_PARAMS && request instanceof QueryRequest ? str + "<redacted>" : str + normalizeRequestKey(String.valueOf(request.getParams())); }
private void testGoodRequestNeedsNoRetries(MetricsFacade metricsFacade) throws Exception { CountingSolrServer countingSolrServer = new CountingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer(countingSolrServer, getNoRetryPolicyFactory(), metricsFacade); SolrQuery query = getDefaultQuery(); solr.query(query); Assert.assertEquals(1, countingSolrServer.getNumRequests()); }
@Test public void testRetryTwice() throws Exception { SolrQuery query = getDefaultQuery(); solrServer.query(query); FailingSolrServer failingSolrServer = new FailingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer(failingSolrServer, getRetryTwicePolicyFactory(), getMetricsFacade()); try { solr.query(query); fail(); } catch (RetriesExhaustedException e) { Assert.assertTrue(e.getCause() instanceof FailingSolrServer.InjectedSolrServerException); Assert.assertEquals(3, failingSolrServer.getNumRequests()); Assert.assertEquals(3, failingSolrServer.getNumInjectedFailures()); LOG.info("RetriesExhaustedException.getMessage(): " + e.getMessage()); } }
@Test public void testNoRetries() throws Exception { SolrQuery query = getDefaultQuery(); solrServer.query(query); FailingSolrServer failingSolrServer = new FailingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer(failingSolrServer, getNoRetryPolicyFactory(), getMetricsFacade()); try { solr.query(query); fail(); } catch (RetriesExhaustedException e) { assertTrue(e.getCause() instanceof FailingSolrServer.InjectedSolrServerException); Assert.assertEquals(1, failingSolrServer.getNumRequests()); Assert.assertEquals(1, failingSolrServer.getNumInjectedFailures()); } }
@Test public void testRetryOfBadRequest() throws Exception { SolrInputDocument doc = new SolrInputDocument(); // bad doc is missing 'id' field // without RetryingSolrServer try { solrServer.add(doc); fail(); } catch (SolrException e) { assertEquals(ErrorCode.BAD_REQUEST.code, e.code()); } // RetryingSolrServer, retry twice CountingSolrServer countingSolrServer = new CountingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer(countingSolrServer, getRetryTwicePolicyFactory(), getMetricsFacade()); try { solr.add(doc); fail(); } catch (RetriesExhaustedException e) { Assert.assertEquals(3, countingSolrServer.getNumRequests()); Assert.assertTrue(e.getCause() instanceof SolrException); SolrException sex = (SolrException) e.getCause(); Assert.assertEquals(ErrorCode.BAD_REQUEST.code, sex.code()); } }
SolrQuery query = getDefaultQuery(); FailingSolrServer failingSolrServer = new FailingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer( failingSolrServer, new DefaultRetryPolicyFactory(new FlexibleBoundedExponentialBackoffRetry(