瀏覽代碼

HADOOP-592. Fix an NPE in IPC Server. Contributed by Owen.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@462885 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 年之前
父節點
當前提交
b16e047aa3
共有 2 個文件被更改,包括 21 次插入5 次删除
  1. 3 0
      CHANGES.txt
  2. 18 5
      src/java/org/apache/hadoop/ipc/Server.java

+ 3 - 0
CHANGES.txt

@@ -6,6 +6,9 @@ Release 0.7.1 - unreleased
  1. HADOOP-593.  Fix a NullPointerException in the JobTracker.
  1. HADOOP-593.  Fix a NullPointerException in the JobTracker.
     (omalley via cutting)
     (omalley via cutting)
 
 
+ 2. HADOOP-592.  Fix a NullPointerException in the IPC Server.  Also
+    consistently log when stale calls are discarded.  (omalley via cutting)
+
 
 
 Release 0.7.0 - 2006-10-06
 Release 0.7.0 - 2006-10-06
 
 

+ 18 - 5
src/java/org/apache/hadoop/ipc/Server.java

@@ -30,6 +30,7 @@ import java.nio.channels.Selector;
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
 import java.nio.channels.SocketChannel;
 
 
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.Socket;
 
 
@@ -351,6 +352,10 @@ public abstract class Server {
     private long lastContact;
     private long lastContact;
     private int dataLength;
     private int dataLength;
     private Socket socket;
     private Socket socket;
+    // Cache the remote host & port info so that even if the socket is 
+    // disconnected, we can say where it used to connect to.
+    private String hostAddress;
+    private int remotePort;
 
 
     public Connection(SelectionKey key, SocketChannel channel, 
     public Connection(SelectionKey key, SocketChannel channel, 
     long lastContact) {
     long lastContact) {
@@ -363,14 +368,21 @@ public abstract class Server {
       this.out = new DataOutputStream
       this.out = new DataOutputStream
         (new BufferedOutputStream(
         (new BufferedOutputStream(
          this.channelOut = new SocketChannelOutputStream(channel, 4096)));
          this.channelOut = new SocketChannelOutputStream(channel, 4096)));
+      InetAddress addr = socket.getInetAddress();
+      if (addr == null) {
+        this.hostAddress = "*Unknown*";
+      } else {
+        this.hostAddress = addr.getHostAddress();
+      }
+      this.remotePort = socket.getPort();
     }   
     }   
 
 
     public String toString() {
     public String toString() {
-      return getHostAddress() + ":" + socket.getPort(); 
+      return getHostAddress() + ":" + remotePort; 
     }
     }
     
     
     public String getHostAddress() {
     public String getHostAddress() {
-      return socket.getInetAddress().getHostAddress();
+      return hostAddress;
     }
     }
 
 
     public void setLastContact(long lastContact) {
     public void setLastContact(long lastContact) {
@@ -431,7 +443,8 @@ public abstract class Server {
       Call call = new Call(id, param, this);
       Call call = new Call(id, param, this);
       synchronized (callQueue) {
       synchronized (callQueue) {
         if (callQueue.size() >= maxQueueSize) {
         if (callQueue.size() >= maxQueueSize) {
-          callQueue.removeFirst();
+          Call oldCall = (Call) callQueue.removeFirst();
+          LOG.warn("Call queue overflow discarding oldest call " + oldCall);
         }
         }
         callQueue.addLast(call);              // queue the call
         callQueue.addLast(call);              // queue the call
         callQueue.notify();                   // wake up a waiting handler
         callQueue.notify();                   // wake up a waiting handler
@@ -484,7 +497,7 @@ public abstract class Server {
           // throw the message away if it is too old
           // throw the message away if it is too old
           if (System.currentTimeMillis() - call.receivedTime > 
           if (System.currentTimeMillis() - call.receivedTime > 
               maxCallStartAge) {
               maxCallStartAge) {
-            LOG.info("Call " + call.toString() + 
+            LOG.warn("Call " + call.toString() + 
                      " discarded for being too old (" +
                      " discarded for being too old (" +
                      (System.currentTimeMillis() - call.receivedTime) + ")");
                      (System.currentTimeMillis() - call.receivedTime) + ")");
             continue;
             continue;
@@ -492,7 +505,7 @@ public abstract class Server {
           
           
           if (LOG.isDebugEnabled())
           if (LOG.isDebugEnabled())
             LOG.debug(getName() + ": has #" + call.id + " from " +
             LOG.debug(getName() + ": has #" + call.id + " from " +
-                     call.connection.socket.getInetAddress().getHostAddress());
+                     call.connection);
           
           
           String errorClass = null;
           String errorClass = null;
           String error = null;
           String error = null;