Browse Source

Fix for HADOOP-44. The error string for remote exceptions now contains the full remote stack trace. Remote exceptions are now also re-thrown on the client as RemoteException rather than IOException, so that they can be distinguished from other IOExceptions.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@387660 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 years ago
parent
commit
df2d8df942

+ 3 - 1
src/java/org/apache/hadoop/ipc/Client.java

@@ -29,6 +29,8 @@ import java.io.BufferedOutputStream;
 import java.io.FilterInputStream;
 import java.io.FilterOutputStream;
 
+import java.rmi.RemoteException;
+
 import java.util.Hashtable;
 import java.util.logging.Logger;
 import java.util.logging.Level;
@@ -298,7 +300,7 @@ public class Client {
       } while (!call.done && wait > 0);
 
       if (call.error != null) {
-        throw new IOException(call.error);
+        throw new RemoteException(call.error);
       } else if (!call.done) {
         throw new IOException("timed out waiting for response");
       } else {

+ 13 - 2
src/java/org/apache/hadoop/ipc/Server.java

@@ -22,6 +22,8 @@ import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
+import java.io.StringWriter;
+import java.io.PrintWriter;
 
 import java.net.Socket;
 import java.net.ServerSocket;
@@ -214,10 +216,10 @@ public abstract class Server {
             value = call(call.param);             // make the call
           } catch (IOException e) {
             LOG.log(Level.INFO, getName() + " call error: " + e, e);
-            error = e.getMessage();
+            error = getStackTrace(e);
           } catch (Exception e) {
             LOG.log(Level.INFO, getName() + " call error: " + e, e);
-            error = e.toString();
+            error = getStackTrace(e);
           }
             
           DataOutputStream out = call.connection.out;
@@ -236,6 +238,15 @@ 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.  Parameters passed must