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 c467149970b..b600cdc83d6 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 @@ -148,8 +148,16 @@ public abstract class CoprocessorHost { if (defaultCPClasses == null || defaultCPClasses.length == 0) return; - int priority = Coprocessor.PRIORITY_SYSTEM; + int currentSystemPriority = Coprocessor.PRIORITY_SYSTEM; for (String className : defaultCPClasses) { + String[] classNameAndPriority = className.split("\\|"); + boolean hasPriorityOverride = false; + className = classNameAndPriority[0]; + int overridePriority = Coprocessor.PRIORITY_SYSTEM; + if (classNameAndPriority.length > 1){ + overridePriority = Integer.parseInt(classNameAndPriority[1]); + hasPriorityOverride = true; + } className = className.trim(); if (findCoprocessor(className) != null) { // If already loaded will just continue @@ -162,10 +170,13 @@ public abstract class CoprocessorHost { implClass = cl.loadClass(className); // Add coprocessors as we go to guard against case where a coprocessor is specified twice // in the configuration - this.coprocessors.add(loadInstance(implClass, priority, conf)); + int coprocPriority = hasPriorityOverride ? overridePriority : currentSystemPriority; + this.coprocessors.add(loadInstance(implClass, coprocPriority, conf)); LOG.info("System coprocessor " + className + " was loaded " + - "successfully with priority (" + priority + ")."); - ++priority; + "successfully with priority (" + coprocPriority + ")."); + if (!hasPriorityOverride) { + ++currentSystemPriority; + } } catch (Throwable t) { // We always abort if system coprocessors cannot be loaded abortServer(className, t); diff --git a/src/main/asciidoc/_chapters/cp.adoc b/src/main/asciidoc/_chapters/cp.adoc index a99e903c3ee..d4471e81c35 100644 --- a/src/main/asciidoc/_chapters/cp.adoc +++ b/src/main/asciidoc/_chapters/cp.adoc @@ -107,9 +107,24 @@ Therefore, the jar file must reside on the server-side HBase classpath. Coprocessors which are loaded in this way will be active on all regions of all tables. These are the system coprocessor introduced earlier. -The first listed coprocessors will be assigned the priority `Coprocessor.Priority.SYSTEM`. -Each subsequent coprocessor in the list will have its priority value incremented by one (which reduces its priority, because priorities have the natural sort order of Integers). +The first listed Coprocessors will be assigned the priority `Coprocessor.Priority.SYSTEM`. +Each subsequent coprocessor in the list will have its priority value incremented by one (which +reduces its priority, because priorities have the natural sort order of Integers). + ++ +These priority values can be manually overriden in hbase-site.xml. This can be useful if you +want to guarantee that a coprocessor will execute after another. For example, in the following +configuration `SumEndPoint` would be guaranteed to go last, except in the case of a tie with +another coprocessor: ++ +[source,xml] +---- + + hbase.coprocessor.region.classes + org.myname.hbase.coprocessor.endpoint.SumEndPoint|2147483647 + +---- When calling out to registered observers, the framework executes their callbacks methods in the sorted order of their priority. Ties are broken arbitrarily.