HBASE-15990 The priority value of subsequent coprocessors in the Coprocessor.Priority.SYSTEM list are not incremented by one (ChiaPing Tsai)
This commit is contained in:
parent
9012a0b123
commit
55a04b7810
|
@ -158,9 +158,10 @@ 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, Coprocessor.PRIORITY_SYSTEM, conf));
|
this.coprocessors.add(loadInstance(implClass, priority, conf));
|
||||||
LOG.info("System coprocessor " + className + " was loaded " +
|
LOG.info("System coprocessor " + className + " was loaded " +
|
||||||
"successfully with priority (" + priority++ + ").");
|
"successfully with priority (" + priority + ").");
|
||||||
|
++priority;
|
||||||
} 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);
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.apache.hadoop.hbase.TableName;
|
||||||
import org.apache.hadoop.hbase.client.Table;
|
import org.apache.hadoop.hbase.client.Table;
|
||||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
|
@ -51,9 +53,8 @@ public class TestCoprocessorHost {
|
||||||
return this.aborted;
|
return this.aborted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoubleLoading() {
|
public void testDoubleLoadingAndPriorityValue() {
|
||||||
final Configuration conf = HBaseConfiguration.create();
|
final Configuration conf = HBaseConfiguration.create();
|
||||||
CoprocessorHost<CoprocessorEnvironment> host =
|
CoprocessorHost<CoprocessorEnvironment> host =
|
||||||
new CoprocessorHost<CoprocessorEnvironment>(new TestAbortable()) {
|
new CoprocessorHost<CoprocessorEnvironment>(new TestAbortable()) {
|
||||||
|
@ -61,7 +62,7 @@ public class TestCoprocessorHost {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CoprocessorEnvironment createEnvironment(Class<?> implClass,
|
public CoprocessorEnvironment createEnvironment(Class<?> implClass,
|
||||||
final Coprocessor instance, int priority, int sequence, Configuration conf) {
|
final Coprocessor instance, final int priority, int sequence, Configuration conf) {
|
||||||
return new CoprocessorEnvironment() {
|
return new CoprocessorEnvironment() {
|
||||||
final Coprocessor envInstance = instance;
|
final Coprocessor envInstance = instance;
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ public class TestCoprocessorHost {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPriority() {
|
public int getPriority() {
|
||||||
return 0;
|
return priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -114,10 +115,19 @@ public class TestCoprocessorHost {
|
||||||
};
|
};
|
||||||
final String key = "KEY";
|
final String key = "KEY";
|
||||||
final String coprocessor = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver";
|
final String coprocessor = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver";
|
||||||
// Try and load coprocessor three times.
|
// Try and load a coprocessor three times
|
||||||
conf.setStrings(key, coprocessor, coprocessor, coprocessor);
|
conf.setStrings(key, coprocessor, coprocessor, coprocessor, SimpleRegionObserverV2.class.getName());
|
||||||
host.loadSystemCoprocessors(conf, key);
|
host.loadSystemCoprocessors(conf, key);
|
||||||
// Only one coprocessor loaded
|
// Two coprocessors(SimpleRegionObserver and SimpleRegionObserverV2) loaded
|
||||||
Assert.assertEquals(1, host.coprocessors.size());
|
Assert.assertEquals(2, host.coprocessors.size());
|
||||||
|
// Check the priority value
|
||||||
|
CoprocessorEnvironment simpleEnv = host.findCoprocessorEnvironment(SimpleRegionObserver.class.getName());
|
||||||
|
CoprocessorEnvironment simpleEnv_v2 = host.findCoprocessorEnvironment(SimpleRegionObserverV2.class.getName());
|
||||||
|
assertNotNull(simpleEnv);
|
||||||
|
assertNotNull(simpleEnv_v2);
|
||||||
|
assertEquals(Coprocessor.PRIORITY_SYSTEM, simpleEnv.getPriority());
|
||||||
|
assertEquals(Coprocessor.PRIORITY_SYSTEM + 1, simpleEnv_v2.getPriority());
|
||||||
|
}
|
||||||
|
public static class SimpleRegionObserverV2 extends SimpleRegionObserver {
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue