HBASE-26530 Backport HBASE-26524 Support remove coprocessor by class name via alter table command (#3908)
Signed-off-by: Ankit Singhal <ankit@apache.org>
This commit is contained in:
parent
26e37bcbfe
commit
bf6f94685c
|
@ -1600,6 +1600,8 @@ public class TableDescriptorBuilder {
|
||||||
// if we found a match, remove it
|
// if we found a match, remove it
|
||||||
if (match != null) {
|
if (match != null) {
|
||||||
ModifyableTableDescriptor.this.removeValue(match);
|
ModifyableTableDescriptor.this.removeValue(match);
|
||||||
|
} else {
|
||||||
|
LOG.warn("coprocessor with class name {} was not found in the table attribute", className);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,6 +158,20 @@ public class TestTableDescriptorBuilder {
|
||||||
.anyMatch(name -> name.equals(className2)));
|
.anyMatch(name -> name.equals(className2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test removing cps in the table description that does not exist
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testRemoveNonExistingCoprocessor() throws Exception {
|
||||||
|
String className = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver";
|
||||||
|
TableDescriptor desc = TableDescriptorBuilder
|
||||||
|
.newBuilder(TableName.valueOf(name.getMethodName()))
|
||||||
|
.build();
|
||||||
|
assertFalse(desc.hasCoprocessor(className));
|
||||||
|
desc = TableDescriptorBuilder.newBuilder(desc).removeCoprocessor(className).build();
|
||||||
|
assertFalse(desc.hasCoprocessor(className));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that we add and remove strings from settings properly.
|
* Test that we add and remove strings from settings properly.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -758,6 +758,17 @@ module Hbase
|
||||||
htd.remove(name)
|
htd.remove(name)
|
||||||
end
|
end
|
||||||
hasTableUpdate = true
|
hasTableUpdate = true
|
||||||
|
elsif method == 'table_remove_coprocessor'
|
||||||
|
classname = arg.delete(CLASSNAME)
|
||||||
|
raise(ArgumentError, 'CLASSNAME parameter missing for table_remove_coprocessor method') unless classname
|
||||||
|
if classname.is_a?(Array)
|
||||||
|
classname.each do |key|
|
||||||
|
htd.removeCoprocessor(key)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
htd.removeCoprocessor(classname)
|
||||||
|
end
|
||||||
|
hasTableUpdate = true
|
||||||
# Unset table configuration
|
# Unset table configuration
|
||||||
elsif method == 'table_conf_unset'
|
elsif method == 'table_conf_unset'
|
||||||
raise(ArgumentError, 'NAME parameter missing for table_conf_unset method') unless name
|
raise(ArgumentError, 'NAME parameter missing for table_conf_unset method') unless name
|
||||||
|
|
|
@ -39,6 +39,7 @@ module HBaseConstants
|
||||||
BATCH = 'BATCH'.freeze
|
BATCH = 'BATCH'.freeze
|
||||||
CACHE = 'CACHE'.freeze
|
CACHE = 'CACHE'.freeze
|
||||||
CACHE_BLOCKS = 'CACHE_BLOCKS'.freeze
|
CACHE_BLOCKS = 'CACHE_BLOCKS'.freeze
|
||||||
|
CLASSNAME = 'CLASSNAME'.freeze
|
||||||
CLUSTER_KEY = 'CLUSTER_KEY'.freeze
|
CLUSTER_KEY = 'CLUSTER_KEY'.freeze
|
||||||
COLUMN = 'COLUMN'.freeze
|
COLUMN = 'COLUMN'.freeze
|
||||||
COLUMNS = 'COLUMNS'.freeze
|
COLUMNS = 'COLUMNS'.freeze
|
||||||
|
|
|
@ -82,6 +82,18 @@ You can also remove a table-scope attribute:
|
||||||
|
|
||||||
hbase> alter 't1', METHOD => 'table_att_unset', NAME => 'coprocessor$1'
|
hbase> alter 't1', METHOD => 'table_att_unset', NAME => 'coprocessor$1'
|
||||||
|
|
||||||
|
Other than removing coprocessor from the table-scope attribute via 'table_att_unset', you can also
|
||||||
|
use 'table_remove_coprocessor' by specifying the class name:
|
||||||
|
|
||||||
|
hbase> alter 't1', METHOD => 'table_remove_coprocessor', CLASSNAME =>
|
||||||
|
'org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver'
|
||||||
|
|
||||||
|
You can also remove multiple coprocessors at once:
|
||||||
|
|
||||||
|
hbase> alter 't1', METHOD => 'table_remove_coprocessor', CLASSNAME =>
|
||||||
|
['org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver',
|
||||||
|
'org.apache.hadoop.hbase.coprocessor.Export']
|
||||||
|
|
||||||
You can also set REGION_REPLICATION:
|
You can also set REGION_REPLICATION:
|
||||||
|
|
||||||
hbase> alter 't1', {REGION_REPLICATION => 2}
|
hbase> alter 't1', {REGION_REPLICATION => 2}
|
||||||
|
|
|
@ -977,6 +977,25 @@ module Hbase
|
||||||
assert_no_match(eval("/" + key + "/"), admin.describe(@test_name))
|
assert_no_match(eval("/" + key + "/"), admin.describe(@test_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
define_test "alter should be able to remove a coprocessor by class name" do
|
||||||
|
drop_test_table(@test_name)
|
||||||
|
create_test_table(@test_name)
|
||||||
|
|
||||||
|
cp_key = "coprocessor"
|
||||||
|
class_name = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver"
|
||||||
|
cp_value = "|" + class_name + "|12|arg1=1,arg2=2"
|
||||||
|
|
||||||
|
command(:alter, @test_name, 'METHOD' => 'table_att', cp_key => cp_value)
|
||||||
|
describe_text = admin.describe(@test_name)
|
||||||
|
assert_match(eval("/" + class_name + "/"), describe_text)
|
||||||
|
assert_match(eval("/" + cp_key + "\\$(\\d+)/"), describe_text)
|
||||||
|
assert_match(/arg1=1,arg2=2/, describe_text)
|
||||||
|
|
||||||
|
command(:alter, @test_name, 'METHOD' => 'table_remove_coprocessor', 'CLASSNAME' => class_name)
|
||||||
|
describe_text = admin.describe(@test_name)
|
||||||
|
assert_no_match(eval("/" + class_name + "/"), describe_text)
|
||||||
|
end
|
||||||
|
|
||||||
define_test "alter should be able to remove a list of table attributes" do
|
define_test "alter should be able to remove a list of table attributes" do
|
||||||
drop_test_table(@test_name)
|
drop_test_table(@test_name)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue