Repository: hbase
Updated Branches:
  refs/heads/master 1fad92032 -> 1c8822ddf


HBASE-17170 HBase is also retrying DoNotRetryIOException because of class 
loader differences (Ankit Singhal)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1c8822dd
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1c8822dd
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1c8822dd

Branch: refs/heads/master
Commit: 1c8822ddff02c0b4f64b42b316900f2a970ff098
Parents: 1fad920
Author: tedyu <yuzhih...@gmail.com>
Authored: Mon Dec 5 10:15:09 2016 -0800
Committer: tedyu <yuzhih...@gmail.com>
Committed: Mon Dec 5 10:15:09 2016 -0800

----------------------------------------------------------------------
 .../hbase/ipc/RemoteWithExtrasException.java    | 50 ++++++++++++++++++++
 1 file changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/1c8822dd/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RemoteWithExtrasException.java
----------------------------------------------------------------------
diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RemoteWithExtrasException.java
 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RemoteWithExtrasException.java
index 46356f8..0e50943 100644
--- 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RemoteWithExtrasException.java
+++ 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RemoteWithExtrasException.java
@@ -17,8 +17,16 @@
  */
 package org.apache.hadoop.hbase.ipc;
 
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.classification.InterfaceStability;
+import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
+import org.apache.hadoop.hbase.util.DynamicClassLoader;
 import org.apache.hadoop.ipc.RemoteException;
 
 /**
@@ -30,11 +38,21 @@ import org.apache.hadoop.ipc.RemoteException;
 @SuppressWarnings("serial")
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
+@edu.umd.cs.findbugs.annotations.SuppressWarnings(
+    value = "DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED", justification = 
"None. Address sometime.")
 public class RemoteWithExtrasException extends RemoteException {
   private final String hostname;
   private final int port;
   private final boolean doNotRetry;
 
+  private final static ClassLoader CLASS_LOADER;
+
+  static {
+    ClassLoader parent = RemoteWithExtrasException.class.getClassLoader();
+    Configuration conf = HBaseConfiguration.create();
+    CLASS_LOADER = new DynamicClassLoader(conf, parent);
+  }
+
   public RemoteWithExtrasException(String className, String msg, final boolean 
doNotRetry) {
     this(className, msg, null, -1, doNotRetry);
   }
@@ -47,6 +65,38 @@ public class RemoteWithExtrasException extends 
RemoteException {
     this.doNotRetry = doNotRetry;
   }
 
+  @Override
+  public IOException unwrapRemoteException() {
+    Class<?> realClass;
+    try {
+      // try to load a exception class from where the HBase classes are loaded 
or from Dynamic
+      // classloader.
+      realClass = Class.forName(getClassName(), false, CLASS_LOADER);
+    } catch (ClassNotFoundException cnfe) {
+      try {
+        // cause could be a hadoop exception, try to load from hadoop classpath
+        realClass = Class.forName(getClassName(), false, 
super.getClass().getClassLoader());
+      } catch (ClassNotFoundException e) {
+        return new DoNotRetryIOException(
+            "Unable to load exception received from server:" + e.getMessage(), 
this);
+      }
+    }
+    try {
+      return instantiateException(realClass.asSubclass(IOException.class));
+    } catch (Exception e) {
+      return new DoNotRetryIOException(
+          "Unable to instantiate exception received from server:" + 
e.getMessage(), this);
+    }
+  }
+
+  private IOException instantiateException(Class<? extends IOException> cls) 
throws Exception {
+    Constructor<? extends IOException> cn = cls.getConstructor(String.class);
+    cn.setAccessible(true);
+    IOException ex = cn.newInstance(this.getMessage());
+    ex.initCause(this);
+    return ex;
+  }
+
   /**
    * @return null if not set
    */

Reply via email to