hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yhema...@apache.org
Subject svn commit: r749262 - in /hadoop/core/trunk: CHANGES.txt src/core/org/apache/hadoop/http/HttpServer.java
Date Mon, 02 Mar 2009 10:34:25 GMT
Author: yhemanth
Date: Mon Mar  2 10:34:24 2009
New Revision: 749262

URL: http://svn.apache.org/viewvc?rev=749262&view=rev
Log:
HADOOP-4744. Workaround for jetty6 returning -1 when getLocalPort is invoked on the connector,
by retrying a few times. Contributed by Jothi Padmanabhan.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/core/org/apache/hadoop/http/HttpServer.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=749262&r1=749261&r2=749262&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Mon Mar  2 10:34:24 2009
@@ -909,8 +909,8 @@
     (Doğacan Güney via enis)
 
     HADOOP-4744. Workaround for jetty6 returning -1 when getLocalPort is invoked on
-    the connector. The workaround patch takes the most conservative approach of 
-    killing the server process whenever this is true. (ddas)
+    the connector. The workaround patch retries a few times before failing.
+    (Jothi Padmanabhan via yhemanth)
 
     HADOOP-5280. Adds a check to prevent a task state transition from FAILED to any of
     UNASSIGNED, RUNNING, COMMIT_PENDING or SUCCEEDED. (ddas) 

Modified: hadoop/core/trunk/src/core/org/apache/hadoop/http/HttpServer.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/core/org/apache/hadoop/http/HttpServer.java?rev=749262&r1=749261&r2=749262&view=diff
==============================================================================
--- hadoop/core/trunk/src/core/org/apache/hadoop/http/HttpServer.java (original)
+++ hadoop/core/trunk/src/core/org/apache/hadoop/http/HttpServer.java Mon Mar  2 10:34:24
2009
@@ -76,6 +76,7 @@
   protected final Map<Context, Boolean> defaultContexts =
       new HashMap<Context, Boolean>();
   protected final List<String> filterNames = new ArrayList<String>();
+  private static final int MAX_RETRIES = 10;
 
   /** Same as this(name, bindAddress, port, findPort, null); */
   public HttpServer(String name, String bindAddress, int port, boolean findPort
@@ -341,15 +342,7 @@
    * @return the port
    */
   public int getPort() {
-    int port = webServer.getConnectors()[0].getLocalPort();
-    if (port < 0) {
-      LOG.warn("Exiting since getLocalPort returned " + port + 
-               " Open status of jetty connector is: " +
-      (((ServerSocketChannel)webServer.getConnectors()[0].getConnection()).
-                                                    isOpen()));
-      System.exit(-1);
-    }
-    return port;
+    return webServer.getConnectors()[0].getLocalPort();
   }
 
   /**
@@ -420,25 +413,64 @@
    */
   public void start() throws IOException {
     try {
+      int port = 0;
+      int oriPort = listener.getPort(); // The original requested port
       while (true) {
         try {
+          listener.open();
+          port = listener.getLocalPort();
+          //Workaround to handle the problem reported in HADOOP-4744
+          if (port < 0) {
+            Thread.sleep(100);
+            int numRetries = 1;
+            while (port < 0) {
+              LOG.warn("listener.getLocalPort returned " + port);
+              if (numRetries++ > MAX_RETRIES) {
+                throw new Exception(" listener.getLocalPort is returning " +
+                		"less than 0 even after " +numRetries+" resets");
+              }
+              for (int i = 0; i < 2; i++) {
+                LOG.info("Retrying listener.getLocalPort()");
+                port = listener.getLocalPort();
+                if (port > 0) {
+                  break;
+                }
+                Thread.sleep(200);
+              }
+              if (port > 0) {
+                break;
+              }
+              LOG.info("Bouncing the listener");
+              listener.close();
+              Thread.sleep(1000);
+              listener.setPort(oriPort == 0 ? 0 : (oriPort += 1));
+              listener.open();
+              Thread.sleep(100);
+              port = listener.getLocalPort();
+            }
+          } //Workaround end
+          LOG.info("Jetty bound to port " + port);
           webServer.start();
           break;
-        } catch (MultiException ex) {
-          // if the multi exception contains ONLY a bind exception,
+        } catch (IOException ex) {
+          // if this is a bind exception,
           // then try the next port number.
-          if (ex.size() == 1 && ex.getThrowable(0) instanceof BindException) {
+          if (ex instanceof BindException) {
             if (!findPort) {
-              throw (BindException) ex.getThrowable(0);
+              throw (BindException) ex;
             }
           } else {
+            LOG.info("HttpServer.start() threw a non Bind IOException"); 
             throw ex;
           }
+        } catch (MultiException ex) {
+          LOG.info("HttpServer.start() threw a MultiException"); 
+          throw ex;
         }
-        listener.setPort(listener.getLocalPort() + 1);
+        listener.setPort((oriPort += 1));
       }
-    } catch (IOException ie) {
-      throw ie;
+    } catch (IOException e) {
+      throw e;
     } catch (Exception e) {
       throw new IOException("Problem starting http server", e);
     }
@@ -448,6 +480,7 @@
    * stop the server
    */
   public void stop() throws Exception {
+    listener.close();
     webServer.stop();
   }
 



Mime
View raw message