private void handleException(SolrRequest request, String exceptionTopLevelMsg, String exceptionRootCauseMsg, String requestKey, long requestDuration) { String timePrefix = "time."; metrics.updateTimer(ROOT_PREFIX + "time", requestDuration, TimeUnit.NANOSECONDS); String failedRequestsPrefix = ROOT_PREFIX + "fail."; metrics.updateTimer(failedRequestsPrefix + "time", requestDuration, TimeUnit.NANOSECONDS); metrics.updateTimer(failedRequestsPrefix + timePrefix + "req." + requestKey, requestDuration, TimeUnit.NANOSECONDS); metrics.updateTimer(failedRequestsPrefix + timePrefix + "xreq.top." + requestKey + "." + exceptionTopLevelMsg, requestDuration, TimeUnit.NANOSECONDS); metrics.updateTimer(failedRequestsPrefix + timePrefix + "xreq.root." + requestKey + "." + exceptionRootCauseMsg, requestDuration, TimeUnit.NANOSECONDS); metrics.updateTimer(failedRequestsPrefix + timePrefix + "top." + exceptionTopLevelMsg, requestDuration, TimeUnit.NANOSECONDS); metrics.updateTimer(failedRequestsPrefix + timePrefix + "root." + exceptionRootCauseMsg, requestDuration, TimeUnit.NANOSECONDS); }
private SolrClient getNonRetryingSolrServer() { SolrClient s = server; while (s instanceof RetryingSolrServer) { s = ((RetryingSolrServer)s).getUnderlyingSolrServer(); } return s; }
RetriesExhaustedException(String msg, Map<String, MutableLong> counters, Throwable cause) { super(msg + getRootCauseCountersAsString(counters), cause); }
@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 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 testGetUnderlyingSolrServer() throws Exception { RetryingSolrServer retryingSolr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); assertSame(solrServer, retryingSolr.getUnderlyingSolrServer()); }
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 String normalizeRequestKey(String str) { RetryingSolrServer solr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); return solr.normalizeRequestKey(str); }
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 testGetBinder() throws Exception { RetryingSolrServer retryingSolr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); assertSame(solrServer.getBinder(), retryingSolr.getBinder()); }
public DefaultRetryPolicyFactory() { this( new FlexibleBoundedExponentialBackoffRetry( TimeUnit.MILLISECONDS.toNanos(125), TimeUnit.SECONDS.toNanos(10), 100, TimeUnit.MINUTES.toNanos(3))); }
@Override public boolean allowRetry(int retryCount, long elapsedTimeNanos, RetrySleeper sleeper) { if (retryCount >= 0 && retryCount < maxRetries && elapsedTimeNanos < maxElapsedTimeNanos) { try { sleeper.sleepFor(getSleepTime(retryCount), TimeUnit.NANOSECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return false; } return true; } return false; }
private void incCounter(Map<String, MutableLong> counters, String key) { MutableLong counter = counters.get(key); if (counter == null) { counter = new MutableLong(0); counters.put(key, counter); } counter.inc(1); }
@Test public void testNormalizeRequestKey() throws Exception { assertEquals("&NOW=<redacted>", normalizeRequestKey("&NOW=1448689151133")); }
@Test public void testGoodRequestNeedsNoRetriesWithNonNullMetricsFacade() throws Exception { testGoodRequestNeedsNoRetries(getMetricsFacade()); }
@BeforeClass public static void beforeClass() throws Exception { initCore( "solrconfig.xml", "schema.xml", RESOURCES_DIR + File.separator + DEFAULT_BASE_DIR ); }
@Test public void testGoodRequestNeedsNoRetriesWithNullMetricsFacade() throws Exception { testGoodRequestNeedsNoRetries(null); }
@Override public RetryPolicy getRetryPolicy(Throwable exception, SolrRequest request, SolrClient server, RetryPolicy currentPolicy) { if (currentPolicy == null) { return new FlexibleBoundedExponentialBackoffRetry(0, 0, 2, Long.MAX_VALUE); } else { return currentPolicy; } }
private RetryPolicyFactory getRetryTwicePolicyFactory() { return new RetryPolicyFactory() { @Override public RetryPolicy getRetryPolicy(Throwable exception, SolrRequest request, SolrClient server, RetryPolicy currentPolicy) { if (currentPolicy == null) { return new FlexibleBoundedExponentialBackoffRetry(0, 0, 2, Long.MAX_VALUE); } else { return currentPolicy; } } }; }