Bläddra i källkod

Fix HADOOP-151. Close a potential socket leak.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@395444 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 år sedan
förälder
incheckning
0794e232d5
2 ändrade filer med 21 tillägg och 13 borttagningar
  1. 5 0
      CHANGES.txt
  2. 16 13
      src/java/org/apache/hadoop/ipc/RPC.java

+ 5 - 0
CHANGES.txt

@@ -64,6 +64,11 @@ Trunk (unreleased)
 18. Fix HADOOP-148.  Maintain a task failure count for each
     tasktracker and display it in the web ui.  (omalley via cutting)
 
+19. Fix HADOOP-151.  Close a potential socket leak, where new IPC
+    connection pools were created per configuration instance that RPCs
+    use.  Now a global RPC connection pool is used again, as
+    originally intended.  (cutting)
+
 
 Release 0.1.1 - 2006-04-08
 

+ 16 - 13
src/java/org/apache/hadoop/ipc/RPC.java

@@ -121,25 +121,33 @@ public class RPC {
 
   }
 
-  //TODO mb@media-style.com: static client or non-static client?
   private static Client CLIENT;
 
+  private static synchronized Client getClient(Configuration conf) {
+    // Construct & cache client.  The configuration is only used for timeout,
+    // and Clients have connection pools.  So we can either (a) lose some
+    // connection pooling and leak sockets, or (b) use the same timeout for all
+    // configurations.  Since the IPC is usually intended globally, not
+    // per-job, we choose (a).
+    if (CLIENT == null) {
+      CLIENT = new Client(ObjectWritable.class, conf);
+    }
+    return CLIENT;
+  }
+
   private static class Invoker implements InvocationHandler {
     private InetSocketAddress address;
+    private Client client;
 
     public Invoker(InetSocketAddress address, Configuration conf) {
       this.address = address;
-      CLIENT = (Client) conf.getObject(Client.class.getName());
-      if(CLIENT == null) {
-          CLIENT = new Client(ObjectWritable.class, conf);
-          conf.setObject(Client.class.getName(), CLIENT);
-      }
+      this.client = getClient(conf);
     }
 
     public Object invoke(Object proxy, Method method, Object[] args)
       throws Throwable {
       ObjectWritable value = (ObjectWritable)
-        CLIENT.call(new Invocation(method, args), address);
+        client.call(new Invocation(method, args), address);
       return value.get();
     }
   }
@@ -160,12 +168,7 @@ public class RPC {
     Invocation[] invocations = new Invocation[params.length];
     for (int i = 0; i < params.length; i++)
       invocations[i] = new Invocation(method, params[i]);
-    CLIENT = (Client) conf.getObject(Client.class.getName());
-    if(CLIENT == null) {
-        CLIENT = new Client(ObjectWritable.class, conf);
-        conf.setObject(Client.class.getName(), CLIENT);
-    }
-    Writable[] wrappedValues = CLIENT.call(invocations, addrs);
+    Writable[] wrappedValues = getClient(conf).call(invocations, addrs);
     
     if (method.getReturnType() == Void.TYPE) {
       return null;