Skip to content

Commit b265fe5

Browse files
2005hithljApache9
authored andcommitted
HBASE-26673 Implement a shell command for change SFT implementation (#4113)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
1 parent 5118e71 commit b265fe5

File tree

6 files changed

+230
-0
lines changed

6 files changed

+230
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,17 @@ def to_server_names(server_names)
17891789
end
17901790
end
17911791

1792+
#----------------------------------------------------------------------------------------------
1793+
# Change table's sft
1794+
def modify_table_sft(tableName, sft)
1795+
@admin.modifyTableStoreFileTracker(tableName, sft)
1796+
end
1797+
1798+
#----------------------------------------------------------------------------------------------
1799+
# Change table column family's sft
1800+
def modify_table_family_sft(tableName, family_bytes, sft)
1801+
@admin.modifyColumnFamilyStoreFileTracker(tableName, family_bytes, sft)
1802+
end
17921803
end
17931804
# rubocop:enable Metrics/ClassLength
17941805
end

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,3 +624,12 @@ def self.exception_handler(hide_traceback)
624624
get_namespace_rsgroup
625625
]
626626
)
627+
628+
Shell.load_command_group(
629+
'storefiletracker',
630+
full_name: 'StoreFileTracker',
631+
commands: %w[
632+
change_sft
633+
change_sft_all
634+
]
635+
)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
module Shell
21+
module Commands
22+
class ChangeSft < Command
23+
def help
24+
<<-EOF
25+
Change table's or table column family's sft. Examples:
26+
27+
hbase> change_sft 't1','FILE'
28+
hbase> change_sft 't2','cf1','FILE'
29+
EOF
30+
end
31+
32+
def command(*args)
33+
arg_length = args.length
34+
if arg_length == 2
35+
tableName = TableName.valueOf(args[0])
36+
sft = args[1]
37+
admin.modify_table_sft(tableName, sft)
38+
elsif arg_length == 3
39+
tableName = TableName.valueOf(args[0])
40+
family = args[1]
41+
family_bytes = family.to_java_bytes
42+
sft = args[2]
43+
admin.modify_table_family_sft(tableName, family_bytes, sft)
44+
else
45+
raise(ArgumentError, 'Argument length should be two or three.')
46+
end
47+
end
48+
end
49+
end
50+
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
module Shell
21+
module Commands
22+
class ChangeSftAll < Command
23+
def help
24+
<<-EOF
25+
Change all of the tables's sft matching the given regex:
26+
27+
hbase> change_sft_all 't.*','FILE'
28+
hbase> change_sft_all 'ns:.*','FILE'
29+
hbase> change_sft_all 'ns:t.*','FILE'
30+
EOF
31+
end
32+
33+
def command(*args)
34+
arg_length = args.length
35+
if arg_length == 2
36+
tableRegex = args[0]
37+
tableList = admin.list(tableRegex)
38+
count = tableList.size
39+
sft = args[1]
40+
tableList.each do |table|
41+
formatter.row([table])
42+
end
43+
puts "\nChange the above #{count} tables's sft (y/n)?" unless count == 0
44+
answer = 'n'
45+
answer = gets.chomp unless count == 0
46+
puts "No tables matched the regex #{tableRegex}" if count == 0
47+
return unless answer =~ /y.*/i
48+
tableList.each do |table|
49+
tableName = TableName.valueOf(table)
50+
admin.modify_table_sft(tableName, sft)
51+
end
52+
else
53+
raise(ArgumentError, 'Argument length should be two.')
54+
end
55+
end
56+
end
57+
end
58+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.client;
19+
20+
import org.apache.hadoop.hbase.HBaseClassTestRule;
21+
import org.apache.hadoop.hbase.testclassification.ClientTests;
22+
import org.apache.hadoop.hbase.testclassification.LargeTests;
23+
import org.junit.BeforeClass;
24+
import org.junit.ClassRule;
25+
import org.junit.experimental.categories.Category;
26+
27+
@Category({ ClientTests.class, LargeTests.class })
28+
public class TestChangeSftShell extends AbstractTestShell {
29+
@ClassRule
30+
public static final HBaseClassTestRule CLASS_RULE =
31+
HBaseClassTestRule.forClass(TestChangeSftShell.class);
32+
33+
@BeforeClass
34+
public static void setUpBeforeClass() throws Exception {
35+
setUpConfig();
36+
37+
TEST_UTIL.startMiniCluster(3);
38+
39+
setUpJRubyRuntime();
40+
}
41+
42+
@Override
43+
protected String getIncludeList() {
44+
return "sftchange_shell_test.rb";
45+
}
46+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
require 'hbase_constants'
21+
require 'hbase_shell'
22+
23+
class SftChangeTest < Test::Unit::TestCase
24+
def setup
25+
@hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration)
26+
@shell = Shell::Shell.new(@hbase)
27+
connection = $TEST_CLUSTER.getConnection
28+
@admin = connection.getAdmin
29+
end
30+
31+
define_test "Change table's sft" do
32+
table = 'test_table1'
33+
family = 'f1'
34+
change_sft = 'FILE'
35+
@shell.command('create', table, family)
36+
@shell.command('change_sft', table, change_sft)
37+
table_sft = @admin.getDescriptor(TableName.valueOf(table)).getValue('hbase.store.file-tracker.impl')
38+
assert_equal(change_sft, table_sft)
39+
@shell.command(:disable, table)
40+
@shell.command(:drop, table)
41+
end
42+
43+
define_test "Change table column family's sft" do
44+
table = 'test_table2'
45+
family = 'f1'
46+
change_sft = 'FILE'
47+
@shell.command('create', table, family)
48+
@shell.command('change_sft', table, family, change_sft)
49+
family_bytes = family.to_java_bytes
50+
cfd = @admin.getDescriptor(TableName.valueOf(table)).getColumnFamily(family_bytes)
51+
table_family_sft = cfd.getConfigurationValue('hbase.store.file-tracker.impl')
52+
assert_equal(change_sft, table_family_sft)
53+
@shell.command(:disable, table)
54+
@shell.command(:drop, table)
55+
end
56+
end

0 commit comments

Comments
 (0)