lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject [17/37] lucene-solr:jira/http2: SOLR-13036 Fix retry logic in JettySolrRunner
Date Fri, 07 Dec 2018 09:57:32 GMT
SOLR-13036 Fix retry logic in JettySolrRunner


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/59919b4a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/59919b4a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/59919b4a

Branch: refs/heads/jira/http2
Commit: 59919b4ac06a5907e050ffe399013f16dc8c2f99
Parents: e14432e
Author: Gus Heck <gus@apache.org>
Authored: Mon Dec 3 21:54:34 2018 -0500
Committer: Gus Heck <gus@apache.org>
Committed: Mon Dec 3 21:54:34 2018 -0500

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  5 ++
 .../client/solrj/embedded/JettySolrRunner.java  | 35 ++++++++++---
 .../solrj/embedded/TestJettySolrRunner.java     | 53 +++++++++++++++++++-
 3 files changed, 85 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/59919b4a/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index d5240be..dcc6267 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -113,6 +113,8 @@ Other Changes
 * SOLR-12775: LowerCaseTokenizer is deprecated, and should be replaced by LetterTokenizer
and
   LowerCaseFilter (Alan Woodward)
 
+* SOLR-13036: Fix retry logic in JettySolrRunner (Gus Heck)
+
 ==================  7.7.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
@@ -172,6 +174,9 @@ Other Changes
 
 * SOLR-12932: ant test (without badapples=false) should pass easily for developers. (Mark
Miller)
 
+* SOLR-13036: Fix retry logic in JettySolrRunner (Gus Heck)
+
+
 ==================  7.6.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/59919b4a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
index e9d8419..24caec8 100644
--- a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
+++ b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
@@ -509,12 +509,15 @@ public class JettySolrRunner {
         log.info("Trying to start Jetty on port {} try number {} ...", port, tryCnt++);
         server.start();
         break;
-      } catch (BindException e) {
-        log.info("Port is in use, will try again until timeout of " + timeout);
-        server.stop();
-        Thread.sleep(3000);
-        if (!timeout.hasTimedOut()) {
-          continue;
+      } catch (IOException ioe) {
+        Exception e = lookForBindException(ioe);
+        if (e instanceof BindException) {
+          log.info("Port is in use, will try again until timeout of " + timeout);
+          server.stop();
+          Thread.sleep(3000);
+          if (!timeout.hasTimedOut()) {
+            continue;
+          }
         }
         
         throw e;
@@ -523,6 +526,26 @@ public class JettySolrRunner {
   }
 
   /**
+   * Traverses the cause chain looking for a BindException. Returns either a bind exception
+   * that was found in the chain or the original argument.
+   *
+   * @param ioe An IOException that might wrap a BindException
+   * @return A bind exception if present otherwise ioe
+   */
+  Exception lookForBindException(IOException ioe) {
+    Exception e = ioe;
+    while(e.getCause() != null && !(e == e.getCause()) && ! (e instanceof
BindException)) {
+      if (e.getCause() instanceof Exception) {
+        e = (Exception) e.getCause();
+        if (e instanceof BindException) {
+          return e;
+        }
+      }
+    }
+    return ioe;
+  }
+
+  /**
    * Stop the Jetty server
    *
    * @throws Exception if an error occurs on shutdown

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/59919b4a/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java
b/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java
index 6b21aa1..ae8312e 100644
--- a/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java
+++ b/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java
@@ -19,8 +19,12 @@ package org.apache.solr.client.solrj.embedded;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.request.CoreAdminRequest;
+import org.apache.solr.cloud.MiniSolrCloudCluster;
 import org.junit.Test;
 
+import java.io.IOException;
+import java.net.BindException;
+import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -62,11 +66,56 @@ public class TestJettySolrRunner extends SolrTestCaseJ4 {
 
       assertTrue(Files.exists(coresDir.resolve("newcore").resolve("core.properties")));
 
-    }
-    finally {
+    } finally {
       runner.stop();
     }
 
   }
 
+
+  @SuppressWarnings("ThrowableNotThrown")
+  @Test
+  public void testLookForBindException() throws IOException {
+    Path solrHome = createTempDir();
+    Files.write(solrHome.resolve("solr.xml"), MiniSolrCloudCluster.DEFAULT_CLOUD_SOLR_XML.getBytes(Charset.defaultCharset()));
+
+    JettyConfig config = JettyConfig.builder().build();
+
+    JettySolrRunner jetty = new JettySolrRunner(solrHome.toString(), config);
+
+    Exception result;
+    BindException be = new BindException();
+    IOException test = new IOException();
+
+    result = jetty.lookForBindException(test);
+    assertEquals(result, test);
+
+    test = new IOException();
+    result = jetty.lookForBindException(test);
+    assertEquals(result, test);
+
+    test = new IOException((Throwable) null);
+    result = jetty.lookForBindException(test);
+    assertEquals(result, test);
+
+    test = new IOException() {
+      @Override
+      public synchronized Throwable getCause() {
+        return this;
+      }
+    };
+    result = jetty.lookForBindException(test);
+    assertEquals(result, test);
+
+    test = new IOException(new RuntimeException());
+    result = jetty.lookForBindException(test);
+    assertEquals(result, test);
+
+    test = new IOException(new RuntimeException(be));
+    result = jetty.lookForBindException(test);
+    assertEquals(result, be);
+
+  }
+
+
 }


Mime
View raw message