Skip to content

Commit 3427999

Browse files
Karthik PalanisamyApache9
authored andcommitted
HBASE-23134 Enable_all and Disable_all table by Regex fail from Shell (#698)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
1 parent 54083a7 commit 3427999

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,17 @@ def enable(table_name)
308308
#----------------------------------------------------------------------------------------------
309309
# Enables all tables matching the given regex
310310
def enable_all(regex)
311-
regex = regex.to_s
312-
@admin.enableTables(Pattern.compile(regex))
311+
pattern = Pattern.compile(regex.to_s)
312+
failed = java.util.ArrayList.new
313+
@admin.listTableNames(pattern).each do |table_name|
314+
begin
315+
@admin.enableTable(table_name)
316+
rescue java.io.IOException => e
317+
puts "table:#{table_name}, error:#{e.toString}"
318+
failed.add(table_name)
319+
end
320+
end
321+
failed
313322
end
314323

315324
#----------------------------------------------------------------------------------------------
@@ -324,7 +333,16 @@ def disable(table_name)
324333
# Disables all tables matching the given regex
325334
def disable_all(regex)
326335
pattern = Pattern.compile(regex.to_s)
327-
@admin.disableTables(pattern).map { |t| t.getTableName.getNameAsString }
336+
failed = java.util.ArrayList.new
337+
@admin.listTableNames(pattern).each do |table_name|
338+
begin
339+
@admin.disableTable(table_name)
340+
rescue java.io.IOException => e
341+
puts "table:#{table_name}, error:#{e.toString}"
342+
failed.add(table_name)
343+
end
344+
end
345+
failed
328346
end
329347

330348
#---------------------------------------------------------------------------------------------

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,22 @@ def teardown
406406

407407
#-------------------------------------------------------------------------------
408408

409+
define_test 'enable and disable tables by regex' do
410+
@t1 = 't1'
411+
@t2 = 't11'
412+
@regex = 't1.*'
413+
command(:create, @t1, 'f')
414+
command(:create, @t2, 'f')
415+
admin.disable_all(@regex)
416+
assert(command(:is_disabled, @t1))
417+
assert(command(:is_disabled, @t2))
418+
admin.enable_all(@regex)
419+
assert(command(:is_enabled, @t1))
420+
assert(command(:is_enabled, @t2))
421+
end
422+
423+
#-------------------------------------------------------------------------------
424+
409425
define_test "list_regions should fail for disabled table" do
410426
drop_test_table(@create_test_name)
411427
admin.create(@create_test_name, 'a')

0 commit comments

Comments
 (0)