-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBASE-26673 Implement a shell command for change SFT implementation (#…
…4113) Signed-off-by: Duo Zhang <[email protected]>
- Loading branch information
1 parent
5118e71
commit b265fe5
Showing
6 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
module Shell | ||
module Commands | ||
class ChangeSft < Command | ||
def help | ||
<<-EOF | ||
Change table's or table column family's sft. Examples: | ||
hbase> change_sft 't1','FILE' | ||
hbase> change_sft 't2','cf1','FILE' | ||
EOF | ||
end | ||
|
||
def command(*args) | ||
arg_length = args.length | ||
if arg_length == 2 | ||
tableName = TableName.valueOf(args[0]) | ||
sft = args[1] | ||
admin.modify_table_sft(tableName, sft) | ||
elsif arg_length == 3 | ||
tableName = TableName.valueOf(args[0]) | ||
family = args[1] | ||
family_bytes = family.to_java_bytes | ||
sft = args[2] | ||
admin.modify_table_family_sft(tableName, family_bytes, sft) | ||
else | ||
raise(ArgumentError, 'Argument length should be two or three.') | ||
end | ||
end | ||
end | ||
end | ||
end |
58 changes: 58 additions & 0 deletions
58
hbase-shell/src/main/ruby/shell/commands/change_sft_all.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
module Shell | ||
module Commands | ||
class ChangeSftAll < Command | ||
def help | ||
<<-EOF | ||
Change all of the tables's sft matching the given regex: | ||
hbase> change_sft_all 't.*','FILE' | ||
hbase> change_sft_all 'ns:.*','FILE' | ||
hbase> change_sft_all 'ns:t.*','FILE' | ||
EOF | ||
end | ||
|
||
def command(*args) | ||
arg_length = args.length | ||
if arg_length == 2 | ||
tableRegex = args[0] | ||
tableList = admin.list(tableRegex) | ||
count = tableList.size | ||
sft = args[1] | ||
tableList.each do |table| | ||
formatter.row([table]) | ||
end | ||
puts "\nChange the above #{count} tables's sft (y/n)?" unless count == 0 | ||
answer = 'n' | ||
answer = gets.chomp unless count == 0 | ||
puts "No tables matched the regex #{tableRegex}" if count == 0 | ||
return unless answer =~ /y.*/i | ||
tableList.each do |table| | ||
tableName = TableName.valueOf(table) | ||
admin.modify_table_sft(tableName, sft) | ||
end | ||
else | ||
raise(ArgumentError, 'Argument length should be two.') | ||
end | ||
end | ||
end | ||
end | ||
end |
46 changes: 46 additions & 0 deletions
46
hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestChangeSftShell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hbase.client; | ||
|
||
import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
import org.apache.hadoop.hbase.testclassification.ClientTests; | ||
import org.apache.hadoop.hbase.testclassification.LargeTests; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.experimental.categories.Category; | ||
|
||
@Category({ ClientTests.class, LargeTests.class }) | ||
public class TestChangeSftShell extends AbstractTestShell { | ||
@ClassRule | ||
public static final HBaseClassTestRule CLASS_RULE = | ||
HBaseClassTestRule.forClass(TestChangeSftShell.class); | ||
|
||
@BeforeClass | ||
public static void setUpBeforeClass() throws Exception { | ||
setUpConfig(); | ||
|
||
TEST_UTIL.startMiniCluster(3); | ||
|
||
setUpJRubyRuntime(); | ||
} | ||
|
||
@Override | ||
protected String getIncludeList() { | ||
return "sftchange_shell_test.rb"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require 'hbase_constants' | ||
require 'hbase_shell' | ||
|
||
class SftChangeTest < Test::Unit::TestCase | ||
def setup | ||
@hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration) | ||
@shell = Shell::Shell.new(@hbase) | ||
connection = $TEST_CLUSTER.getConnection | ||
@admin = connection.getAdmin | ||
end | ||
|
||
define_test "Change table's sft" do | ||
table = 'test_table1' | ||
family = 'f1' | ||
change_sft = 'FILE' | ||
@shell.command('create', table, family) | ||
@shell.command('change_sft', table, change_sft) | ||
table_sft = @admin.getDescriptor(TableName.valueOf(table)).getValue('hbase.store.file-tracker.impl') | ||
assert_equal(change_sft, table_sft) | ||
@shell.command(:disable, table) | ||
@shell.command(:drop, table) | ||
end | ||
|
||
define_test "Change table column family's sft" do | ||
table = 'test_table2' | ||
family = 'f1' | ||
change_sft = 'FILE' | ||
@shell.command('create', table, family) | ||
@shell.command('change_sft', table, family, change_sft) | ||
family_bytes = family.to_java_bytes | ||
cfd = @admin.getDescriptor(TableName.valueOf(table)).getColumnFamily(family_bytes) | ||
table_family_sft = cfd.getConfigurationValue('hbase.store.file-tracker.impl') | ||
assert_equal(change_sft, table_family_sft) | ||
@shell.command(:disable, table) | ||
@shell.command(:drop, table) | ||
end | ||
end |