Skip to content

Commit 19b0b2e

Browse files
authored
HBASE-26524 Support remove coprocessor by class name via alter table command (apache#3902)
Signed-off-by: Nick Dimiduk <[email protected]> Signed-off-by: Wellington Chevreuil <[email protected]>
1 parent 7845d00 commit 19b0b2e

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/TableDescriptorBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,10 @@ public void removeCoprocessor(String className) {
15611561
// if we found a match, remove it
15621562
if (match != null) {
15631563
ModifyableTableDescriptor.this.removeValue(match);
1564+
} else {
1565+
throw new IllegalArgumentException(String
1566+
.format("coprocessor with class name %s was not found in the table attribute",
1567+
className));
15641568
}
15651569
}
15661570

hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestTableDescriptorBuilder.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ public void testSetListRemoveCP() throws Exception {
148148
.anyMatch(name -> name.equals(className2)));
149149
}
150150

151+
/**
152+
* Test removing cps in the table description that does not exist
153+
* @throws Exception if removing a coprocessor fails other than IllegalArgumentException
154+
*/
155+
@Test(expected = IllegalArgumentException.class)
156+
public void testRemoveNonExistingCoprocessor() throws Exception {
157+
String className = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver";
158+
TableDescriptor desc = TableDescriptorBuilder
159+
.newBuilder(TableName.valueOf(name.getMethodName()))
160+
.build();
161+
assertFalse(desc.hasCoprocessor(className));
162+
TableDescriptorBuilder.newBuilder(desc).removeCoprocessor(className).build();
163+
}
164+
151165
/**
152166
* Test that we add and remove strings from settings properly.
153167
*/

hbase-shell/src/main/ruby/hbase/admin.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,17 @@ def alter(table_name_str, wait = true, *args)
824824
tdb.removeValue(name)
825825
end
826826
hasTableUpdate = true
827+
elsif method == 'table_remove_coprocessor'
828+
classname = arg.delete(CLASSNAME)
829+
raise(ArgumentError, 'CLASSNAME parameter missing for table_remove_coprocessor method') unless classname
830+
if classname.is_a?(Array)
831+
classname.each do |key|
832+
tdb.removeCoprocessor(key)
833+
end
834+
else
835+
tdb.removeCoprocessor(classname)
836+
end
837+
hasTableUpdate = true
827838
# Unset table configuration
828839
elsif method == 'table_conf_unset'
829840
raise(ArgumentError, 'NAME parameter missing for table_conf_unset method') unless name

hbase-shell/src/main/ruby/shell/commands/alter.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ def help
8282
8383
hbase> alter 't1', METHOD => 'table_att_unset', NAME => 'coprocessor$1'
8484
85+
Other than removing coprocessor from the table-scope attribute via 'table_att_unset', you can also
86+
use 'table_remove_coprocessor' by specifying the class name:
87+
88+
hbase> alter 't1', METHOD => 'table_remove_coprocessor', CLASSNAME =>
89+
'org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver'
90+
91+
You can also remove multiple coprocessors at once:
92+
93+
hbase> alter 't1', METHOD => 'table_remove_coprocessor', CLASSNAME =>
94+
['org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver',
95+
'org.apache.hadoop.hbase.coprocessor.Export']
96+
8597
You can also set REGION_REPLICATION:
8698
8799
hbase> alter 't1', {REGION_REPLICATION => 2}

hbase-shell/src/test/ruby/hbase/admin_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,25 @@ def teardown
10101010
assert_no_match(eval("/" + key + "/"), admin.describe(@test_name))
10111011
end
10121012

1013+
define_test "alter should be able to remove a coprocessor by class name" do
1014+
drop_test_table(@test_name)
1015+
create_test_table(@test_name)
1016+
1017+
cp_key = "coprocessor"
1018+
class_name = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver"
1019+
cp_value = "|" + class_name + "|12|arg1=1,arg2=2"
1020+
1021+
command(:alter, @test_name, 'METHOD' => 'table_att', cp_key => cp_value)
1022+
describe_text = admin.describe(@test_name)
1023+
assert_match(eval("/" + class_name + "/"), describe_text)
1024+
assert_match(eval("/" + cp_key + "\\$(\\d+)/"), describe_text)
1025+
assert_match(/arg1=1,arg2=2/, describe_text)
1026+
1027+
command(:alter, @test_name, 'METHOD' => 'table_remove_coprocessor', 'CLASSNAME' => class_name)
1028+
describe_text = admin.describe(@test_name)
1029+
assert_no_match(eval("/" + class_name + "/"), describe_text)
1030+
end
1031+
10131032
define_test "alter should be able to remove a list of table attributes" do
10141033
drop_test_table(@test_name)
10151034

0 commit comments

Comments
 (0)