Преглед изворни кода

HADOOP-963. Fix remote exceptions to have the stack trace of the calling thread, not the IPC listener thread. Contributed by Owen.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@502030 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting пре 18 година
родитељ
комит
6141db59b8
3 измењених фајлова са 14 додато и 17 уклоњено
  1. 3 0
      CHANGES.txt
  2. 10 8
      src/java/org/apache/hadoop/ipc/Client.java
  3. 1 9
      src/java/org/apache/hadoop/ipc/Server.java

+ 3 - 0
CHANGES.txt

@@ -125,6 +125,9 @@ Trunk (unreleased changes)
 38. HADOOP-549.  Fix a NullPointerException in TaskReport's
     serialization.  (omalley via cutting)
 
+39. HADOOP-963.  Fix remote exceptions to have the stack trace of the
+    caller thread, not the IPC listener thread.  (omalley via cutting)
+
 
 Release 0.10.1 - 2007-01-10
 

+ 10 - 8
src/java/org/apache/hadoop/ipc/Client.java

@@ -77,7 +77,8 @@ public class Client {
     int id;                                       // call id
     Writable param;                               // parameter
     Writable value;                               // value, null if error
-    RemoteException error;                        // error, null if value
+    String error;                                 // exception, null if value
+    String errorClass;                            // class of exception
     long lastActivity;                            // time of last i/o
     boolean done;                                 // true when call is done
 
@@ -101,9 +102,12 @@ public class Client {
     }
 
     /** Update lastActivity with the current time. */
-    public synchronized void setResult(Writable value, RemoteException error) {
+    public synchronized void setResult(Writable value, 
+                                       String errorClass,
+                                       String error) {
       this.value = value;
       this.error = error;
+      this.errorClass =errorClass;
       this.done = true;
     }
     
@@ -255,10 +259,8 @@ public class Client {
           Call call = (Call)calls.remove(new Integer(id));
           boolean isError = in.readBoolean();     // read if error
           if (isError) {
-            RemoteException ex = 
-              new RemoteException(WritableUtils.readString(in),
-                                  WritableUtils.readString(in));
-            call.setResult(null, ex);
+            call.setResult(null, WritableUtils.readString(in),
+                           WritableUtils.readString(in));
           } else {
             Writable value = (Writable)ReflectionUtils.newInstance(valueClass, conf);
             try {
@@ -267,7 +269,7 @@ public class Client {
             } finally {
               readingCall = null;
             }
-            call.setResult(value, null);
+            call.setResult(value, null, null);
           }
           call.callComplete();                   // deliver result to caller
           //received the response. So decrement the ref count
@@ -462,7 +464,7 @@ public class Client {
       } while (!call.done && wait > 0);
 
       if (call.error != null) {
-        throw call.error;
+        throw new RemoteException(call.errorClass, call.error);
       } else if (!call.done) {
         throw new SocketTimeoutException("timed out waiting for rpc response");
       } else {

+ 1 - 9
src/java/org/apache/hadoop/ipc/Server.java

@@ -539,7 +539,7 @@ public abstract class Server {
           } catch (Throwable e) {
             LOG.info(getName() + " call error: " + e, e);
             errorClass = e.getClass().getName();
-            error = getStackTrace(e);
+            error = StringUtils.stringifyException(e);
           }
             
           DataOutputStream out = call.connection.out;
@@ -571,14 +571,6 @@ public abstract class Server {
       LOG.info(getName() + ": exiting");
     }
 
-    private String getStackTrace(Throwable throwable) {
-      StringWriter stringWriter = new StringWriter();
-      PrintWriter printWriter = new PrintWriter(stringWriter);
-      throwable.printStackTrace(printWriter);
-      printWriter.flush();
-      return stringWriter.toString();
-    }
-
   }
   /** Constructs a server listening on the named port and address.  Parameters passed must
    * be of the named class.  The <code>handlerCount</handlerCount> determines