Skip to content

Commit bbdc840

Browse files
taklwuapurtell
authored andcommitted
HBASE-26530 Backport HBASE-26524 Support remove coprocessor by class name via alter table command (#3908)
Signed-off-by: Ankit Singhal <ankit@apache.org>
1 parent 49d4c4a commit bbdc840

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,8 @@ public void removeCoprocessor(String className) {
16001600
// if we found a match, remove it
16011601
if (match != null) {
16021602
ModifyableTableDescriptor.this.removeValue(match);
1603+
} else {
1604+
LOG.warn("coprocessor with class name {} was not found in the table attribute", className);
16031605
}
16041606
}
16051607

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
@@ -158,6 +158,20 @@ public void testSetListRemoveCP() throws Exception {
158158
.anyMatch(name -> name.equals(className2)));
159159
}
160160

161+
/**
162+
* Test removing cps in the table description that does not exist
163+
*/
164+
@Test
165+
public void testRemoveNonExistingCoprocessor() throws Exception {
166+
String className = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver";
167+
TableDescriptor desc = TableDescriptorBuilder
168+
.newBuilder(TableName.valueOf(name.getMethodName()))
169+
.build();
170+
assertFalse(desc.hasCoprocessor(className));
171+
desc = TableDescriptorBuilder.newBuilder(desc).removeCoprocessor(className).build();
172+
assertFalse(desc.hasCoprocessor(className));
173+
}
174+
161175
/**
162176
* Test that we add and remove strings from settings properly.
163177
*/

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,17 @@ def alter(table_name_str, wait = true, *args)
758758
htd.remove(name)
759759
end
760760
hasTableUpdate = true
761+
elsif method == 'table_remove_coprocessor'
762+
classname = arg.delete(CLASSNAME)
763+
raise(ArgumentError, 'CLASSNAME parameter missing for table_remove_coprocessor method') unless classname
764+
if classname.is_a?(Array)
765+
classname.each do |key|
766+
htd.removeCoprocessor(key)
767+
end
768+
else
769+
htd.removeCoprocessor(classname)
770+
end
771+
hasTableUpdate = true
761772
# Unset table configuration
762773
elsif method == 'table_conf_unset'
763774
raise(ArgumentError, 'NAME parameter missing for table_conf_unset method') unless name

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module HBaseConstants
3939
BATCH = 'BATCH'.freeze
4040
CACHE = 'CACHE'.freeze
4141
CACHE_BLOCKS = 'CACHE_BLOCKS'.freeze
42+
CLASSNAME = 'CLASSNAME'.freeze
4243
CLUSTER_KEY = 'CLUSTER_KEY'.freeze
4344
COLUMN = 'COLUMN'.freeze
4445
COLUMNS = 'COLUMNS'.freeze

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
@@ -977,6 +977,25 @@ def teardown
977977
assert_no_match(eval("/" + key + "/"), admin.describe(@test_name))
978978
end
979979

980+
define_test "alter should be able to remove a coprocessor by class name" do
981+
drop_test_table(@test_name)
982+
create_test_table(@test_name)
983+
984+
cp_key = "coprocessor"
985+
class_name = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver"
986+
cp_value = "|" + class_name + "|12|arg1=1,arg2=2"
987+
988+
command(:alter, @test_name, 'METHOD' => 'table_att', cp_key => cp_value)
989+
describe_text = admin.describe(@test_name)
990+
assert_match(eval("/" + class_name + "/"), describe_text)
991+
assert_match(eval("/" + cp_key + "\\$(\\d+)/"), describe_text)
992+
assert_match(/arg1=1,arg2=2/, describe_text)
993+
994+
command(:alter, @test_name, 'METHOD' => 'table_remove_coprocessor', 'CLASSNAME' => class_name)
995+
describe_text = admin.describe(@test_name)
996+
assert_no_match(eval("/" + class_name + "/"), describe_text)
997+
end
998+
980999
define_test "alter should be able to remove a list of table attributes" do
9811000
drop_test_table(@test_name)
9821001

0 commit comments

Comments
 (0)