Bläddra i källkod

HADOOP-1178. Fix a NullPointerException during namenode startup. Contributed by Dhruba.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@524205 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 år sedan
förälder
incheckning
306c6cad46
3 ändrade filer med 36 tillägg och 10 borttagningar
  1. 3 0
      CHANGES.txt
  2. 12 6
      src/java/org/apache/hadoop/dfs/NameNode.java
  3. 21 4
      src/java/org/apache/hadoop/ipc/Server.java

+ 3 - 0
CHANGES.txt

@@ -70,6 +70,9 @@ Trunk (unreleased changes)
 21. HADOOP-1110.  Fix an off-by-one error counting map inputs.
     (David Bowen via cutting)
 
+22. HADOOP-1178.  Fix a NullPointerException during namenode startup.
+    (Dhruba Borthakur via cutting)
+
 
 Release 0.12.3 (not yet released)
 

+ 12 - 6
src/java/org/apache/hadoop/dfs/NameNode.java

@@ -180,18 +180,24 @@ public class NameNode implements ClientProtocol, DatanodeProtocol, FSConstants {
       this.handlerCount = conf.getInt("dfs.namenode.handler.count", 10);
       this.server = RPC.getServer(this, hostname, port, handlerCount, 
                                   false, conf);
-      this.server.start();      
 
       // The rpc-server port can be ephemeral... ensure we have the correct info
       this.nameNodeAddress = this.server.getListenerAddress(); 
       conf.set("fs.default.name", new String(nameNodeAddress.getHostName() + ":" + nameNodeAddress.getPort()));
       LOG.info("Namenode up at: " + this.nameNodeAddress);
 
-      this.namesystem = new FSNamesystem(dirs, this.nameNodeAddress.getHostName(), this.nameNodeAddress.getPort(), this, conf);
-
-      this.emptier = new Thread(new Trash(conf).getEmptier(), "Trash Emptier");
-      this.emptier.setDaemon(true);
-      this.emptier.start();
+      try {
+        this.namesystem = new FSNamesystem(dirs, this.nameNodeAddress.getHostName(), this.nameNodeAddress.getPort(), this, conf);
+        this.server.start();  //start RPC server   
+
+        this.emptier = new Thread(new Trash(conf).getEmptier(), "Trash Emptier");
+        this.emptier.setDaemon(true);
+        this.emptier.start();
+      } catch (IOException e) {
+        this.server.stop();
+        throw e;
+      }
+      
     }
     
     /**

+ 21 - 4
src/java/org/apache/hadoop/ipc/Server.java

@@ -133,14 +133,15 @@ public abstract class Server {
   private long maxCallStartAge;
   private int maxQueueSize;
 
-  private boolean running = true;                 // true while server runs
+  volatile private boolean running = true;         // true while server runs
   private LinkedList callQueue = new LinkedList(); // queued calls
 
   private List connectionList = 
        Collections.synchronizedList(new LinkedList()); //maintain a list
                                                        //of client connectionss
-  private Listener listener;
+  private Listener listener = null;
   private int numConnections = 0;
+  private Handler[] handlers = null;
   
   /** A call queued for handling. */
   private static class Call {
@@ -375,6 +376,13 @@ public abstract class Server {
         selector.wakeup();
         Thread.yield();
       }
+      if (acceptChannel != null) {
+        try {
+          acceptChannel.socket().close();
+        } catch (IOException e) {
+            LOG.info(getName() + ":Exception in closing listener socket. " + e);
+        }
+      }
     }
   }
 
@@ -629,10 +637,11 @@ public abstract class Server {
   /** Starts the service.  Must be called before any calls will be handled. */
   public synchronized void start() throws IOException {
     listener.start();
+    handlers = new Handler[handlerCount];
     
     for (int i = 0; i < handlerCount; i++) {
-      Handler handler = new Handler(i);
-      handler.start();
+      handlers[i] = new Handler(i);
+      handlers[i].start();
     }
   }
 
@@ -640,6 +649,14 @@ public abstract class Server {
   public synchronized void stop() {
     LOG.info("Stopping server on " + port);
     running = false;
+    if (handlers != null) {
+      for (int i = 0; i < handlerCount; i++) {
+        if (handlers[i] != null) {
+          handlers[i].interrupt();
+        }
+      }
+    }
+    listener.interrupt();
     listener.doStop();
     notifyAll();
   }