You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ta...@apache.org on 2021/12/01 22:48:32 UTC
[hbase] branch master updated: HBASE-26524 Support remove coprocessor by class name via alter table command (#3902)
This is an automated email from the ASF dual-hosted git repository.
taklwu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push:
new 19b0b2e HBASE-26524 Support remove coprocessor by class name via alter table command (#3902)
19b0b2e is described below
commit 19b0b2e8fc4877e11dfa8fd34bacf5db0bc5b1ad
Author: Tak Lon (Stephen) Wu <ta...@apache.org>
AuthorDate: Wed Dec 1 14:47:59 2021 -0800
HBASE-26524 Support remove coprocessor by class name via alter table command (#3902)
Signed-off-by: Nick Dimiduk <nd...@apache.org>
Signed-off-by: Wellington Chevreuil <wc...@apache.org>
---
.../hadoop/hbase/client/TableDescriptorBuilder.java | 4 ++++
.../hbase/client/TestTableDescriptorBuilder.java | 14 ++++++++++++++
hbase-shell/src/main/ruby/hbase/admin.rb | 11 +++++++++++
hbase-shell/src/main/ruby/shell/commands/alter.rb | 12 ++++++++++++
hbase-shell/src/test/ruby/hbase/admin_test.rb | 19 +++++++++++++++++++
5 files changed, 60 insertions(+)
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/TableDescriptorBuilder.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/TableDescriptorBuilder.java
index b33388f..0128458 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/TableDescriptorBuilder.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/TableDescriptorBuilder.java
@@ -1561,6 +1561,10 @@ public class TableDescriptorBuilder {
// if we found a match, remove it
if (match != null) {
ModifyableTableDescriptor.this.removeValue(match);
+ } else {
+ throw new IllegalArgumentException(String
+ .format("coprocessor with class name %s was not found in the table attribute",
+ className));
}
}
diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestTableDescriptorBuilder.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestTableDescriptorBuilder.java
index 508e9bd..a9b7cd9 100644
--- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestTableDescriptorBuilder.java
+++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestTableDescriptorBuilder.java
@@ -149,6 +149,20 @@ public class TestTableDescriptorBuilder {
}
/**
+ * Test removing cps in the table description that does not exist
+ * @throws Exception if removing a coprocessor fails other than IllegalArgumentException
+ */
+ @Test(expected = IllegalArgumentException.class)
+ 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));
+ TableDescriptorBuilder.newBuilder(desc).removeCoprocessor(className).build();
+ }
+
+ /**
* Test that we add and remove strings from settings properly.
*/
@Test
diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb
index 0d02dba..53d262a 100644
--- a/hbase-shell/src/main/ruby/hbase/admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/admin.rb
@@ -824,6 +824,17 @@ module Hbase
tdb.removeValue(name)
end
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|
+ tdb.removeCoprocessor(key)
+ end
+ else
+ tdb.removeCoprocessor(classname)
+ end
+ hasTableUpdate = true
# Unset table configuration
elsif method == 'table_conf_unset'
raise(ArgumentError, 'NAME parameter missing for table_conf_unset method') unless name
diff --git a/hbase-shell/src/main/ruby/shell/commands/alter.rb b/hbase-shell/src/main/ruby/shell/commands/alter.rb
index b06ada0..ad0cb5a 100644
--- a/hbase-shell/src/main/ruby/shell/commands/alter.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/alter.rb
@@ -82,6 +82,18 @@ You can also remove a table-scope attribute:
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:
hbase> alter 't1', {REGION_REPLICATION => 2}
diff --git a/hbase-shell/src/test/ruby/hbase/admin_test.rb b/hbase-shell/src/test/ruby/hbase/admin_test.rb
index 957c018..99fb27e 100644
--- a/hbase-shell/src/test/ruby/hbase/admin_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/admin_test.rb
@@ -1010,6 +1010,25 @@ module Hbase
assert_no_match(eval("/" + key + "/"), admin.describe(@test_name))
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
drop_test_table(@test_name)