HBASE-23710 - Priority configuration for system coprocessor

Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Geoffrey Jacoby 2020-01-20 13:24:29 -08:00 committed by Viraj Jasani
parent 02d80b240b
commit c080923d77
No known key found for this signature in database
GPG Key ID: E906DFF511D3E5DB
2 changed files with 32 additions and 6 deletions

View File

@ -148,8 +148,16 @@ public abstract class CoprocessorHost<E extends CoprocessorEnvironment> {
if (defaultCPClasses == null || defaultCPClasses.length == 0) if (defaultCPClasses == null || defaultCPClasses.length == 0)
return; return;
int priority = Coprocessor.PRIORITY_SYSTEM; int currentSystemPriority = Coprocessor.PRIORITY_SYSTEM;
for (String className : defaultCPClasses) { 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(); className = className.trim();
if (findCoprocessor(className) != null) { if (findCoprocessor(className) != null) {
// If already loaded will just continue // If already loaded will just continue
@ -162,10 +170,13 @@ public abstract class CoprocessorHost<E extends CoprocessorEnvironment> {
implClass = cl.loadClass(className); implClass = cl.loadClass(className);
// Add coprocessors as we go to guard against case where a coprocessor is specified twice // Add coprocessors as we go to guard against case where a coprocessor is specified twice
// in the configuration // 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 " + LOG.info("System coprocessor " + className + " was loaded " +
"successfully with priority (" + priority + ")."); "successfully with priority (" + coprocPriority + ").");
++priority; if (!hasPriorityOverride) {
++currentSystemPriority;
}
} catch (Throwable t) { } catch (Throwable t) {
// We always abort if system coprocessors cannot be loaded // We always abort if system coprocessors cannot be loaded
abortServer(className, t); abortServer(className, t);

View File

@ -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. Coprocessors which are loaded in this way will be active on all regions of all tables.
These are the system coprocessor introduced earlier. 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]
----
<property>
<name>hbase.coprocessor.region.classes</name>
<value>org.myname.hbase.coprocessor.endpoint.SumEndPoint|2147483647</value>
</property>
----
When calling out to registered observers, the framework executes their callbacks methods in the sorted order of their priority. When calling out to registered observers, the framework executes their callbacks methods in the sorted order of their priority.
Ties are broken arbitrarily. Ties are broken arbitrarily.