hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject hbase git commit: HBASE-15686 Add override mechanism for the exempt classes when dynamically loading table coprocessor
Date Wed, 04 May 2016 23:12:40 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 03e6b75a2 -> a2bc1a254


HBASE-15686 Add override mechanism for the exempt classes when dynamically loading table coprocessor

Conflicts:
	hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java


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

Branch: refs/heads/0.98
Commit: a2bc1a254b088e390519760a3c639a0708668818
Parents: 03e6b75
Author: tedyu <yuzhihong@gmail.com>
Authored: Thu Apr 28 09:21:22 2016 -0700
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Wed May 4 16:04:03 2016 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/HConstants.java     |  2 ++
 .../hbase/util/CoprocessorClassLoader.java      | 16 ++++++++++++--
 .../hbase/coprocessor/CoprocessorHost.java      | 22 +++++++++++++++++++-
 3 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/a2bc1a25/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
index ad33ff9..f046784 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
@@ -862,6 +862,8 @@ public final class HConstants {
   public static final Pattern CP_HTD_ATTR_VALUE_PARAM_PATTERN = Pattern.compile(
       "(" + CP_HTD_ATTR_VALUE_PARAM_KEY_PATTERN + ")=(" +
       CP_HTD_ATTR_VALUE_PARAM_VALUE_PATTERN + "),?");
+  public static final String CP_HTD_ATTR_INCLUSION_KEY =
+      "hbase.coprocessor.classloader.included.classes";
 
   /** The delay when re-trying a socket operation in a loop (HBASE-4712) */
   public static final int SOCKET_RETRY_WAIT_MS = 200;

http://git-wip-us.apache.org/repos/asf/hbase/blob/a2bc1a25/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CoprocessorClassLoader.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CoprocessorClassLoader.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CoprocessorClassLoader.java
index 396600b..fb2a127 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CoprocessorClassLoader.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CoprocessorClassLoader.java
@@ -277,8 +277,13 @@ public class CoprocessorClassLoader extends ClassLoaderBase {
   @Override
   public Class<?> loadClass(String name)
       throws ClassNotFoundException {
+    return loadClass(name, null);
+  }
+
+  public Class<?> loadClass(String name, String[] includedClassPrefixes)
+      throws ClassNotFoundException {
     // Delegate to the parent immediately if this class is exempt
-    if (isClassExempt(name)) {
+    if (isClassExempt(name, includedClassPrefixes)) {
       if (LOG.isDebugEnabled()) {
         LOG.debug("Skipping exempt class " + name +
             " - delegating directly to parent");
@@ -357,7 +362,14 @@ public class CoprocessorClassLoader extends ClassLoaderBase {
    * @return true if the class should *not* be loaded by this ClassLoader;
    * false otherwise.
    */
-  protected boolean isClassExempt(String name) {
+  protected boolean isClassExempt(String name, String[] includedClassPrefixes) {
+    if (includedClassPrefixes != null) {
+      for (String clsName : includedClassPrefixes) {
+        if (name.startsWith(clsName)) {
+          return false;
+        }
+      }
+    }
     for (String exemptPrefix : CLASS_PREFIX_EXEMPTIONS) {
       if (name.startsWith(exemptPrefix)) {
         return true;

http://git-wip-us.apache.org/repos/asf/hbase/blob/a2bc1a25/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java
index e646d58..2e3d0a5 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java
@@ -42,6 +42,7 @@ import org.apache.hadoop.hbase.CoprocessorEnvironment;
 import org.apache.hadoop.hbase.DoNotRetryIOException;
 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
 import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.classification.InterfaceStability;
@@ -201,6 +202,25 @@ public abstract class CoprocessorHost<E extends CoprocessorEnvironment>
{
    */
   public E load(Path path, String className, int priority,
       Configuration conf) throws IOException {
+    String[] includedClassPrefixes = null;
+    if (conf.get(HConstants.CP_HTD_ATTR_INCLUSION_KEY) != null){
+      String prefixes = conf.get(HConstants.CP_HTD_ATTR_INCLUSION_KEY);
+      includedClassPrefixes = prefixes.split(";");
+    }
+    return load(path, className, priority, conf, includedClassPrefixes);
+  }
+
+  /**
+   * Load a coprocessor implementation into the host
+   * @param path path to implementation jar
+   * @param className the main class name
+   * @param priority chaining priority
+   * @param conf configuration for coprocessor
+   * @param includedClassPrefixes class name prefixes to include
+   * @throws java.io.IOException Exception
+   */
+  public E load(Path path, String className, int priority,
+      Configuration conf, String[] includedClassPrefixes) throws IOException {
     Class<?> implClass = null;
     LOG.debug("Loading coprocessor class " + className + " with path " +
         path + " and priority " + priority);
@@ -216,7 +236,7 @@ public abstract class CoprocessorHost<E extends CoprocessorEnvironment>
{
       cl = CoprocessorClassLoader.getClassLoader(
         path, getClass().getClassLoader(), pathPrefix, conf);
       try {
-        implClass = cl.loadClass(className);
+        implClass = ((CoprocessorClassLoader)cl).loadClass(className, includedClassPrefixes);
       } catch (ClassNotFoundException e) {
         throw new IOException("Cannot load external coprocessor class " + className, e);
       }


Mime
View raw message