diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb index 01021186b14..f52438088a0 100644 --- a/hbase-shell/src/main/ruby/hbase/admin.rb +++ b/hbase-shell/src/main/ruby/hbase/admin.rb @@ -50,12 +50,17 @@ module Hbase end #---------------------------------------------------------------------------------------------- - # Requests a table or region flush - def flush(table_or_region_name) - @admin.flushRegion(table_or_region_name.to_java_bytes) - rescue java.lang.IllegalArgumentException => e + # Requests a table or region or region server flush + def flush(name) + @admin.flushRegion(name.to_java_bytes) + rescue java.lang.IllegalArgumentException # Unknown region. Try table. - @admin.flush(TableName.valueOf(table_or_region_name)) + begin + @admin.flush(TableName.valueOf(name)) + rescue java.lang.IllegalArgumentException + # Unknown table. Try region server. + @admin.flushRegionServer(ServerName.valueOf(name)) + end end #---------------------------------------------------------------------------------------------- @@ -1286,5 +1291,11 @@ module Hbase end @admin.clearDeadServers(servers).to_a end + + #---------------------------------------------------------------------------------------------- + # List live region servers + def list_liveservers + @admin.getClusterStatus.getServers.to_a + end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/flush.rb b/hbase-shell/src/main/ruby/shell/commands/flush.rb index 4165b84e385..1f6b3105a1d 100644 --- a/hbase-shell/src/main/ruby/shell/commands/flush.rb +++ b/hbase-shell/src/main/ruby/shell/commands/flush.rb @@ -23,11 +23,14 @@ module Shell def help <<-EOF Flush all regions in passed table or pass a region row to -flush an individual region. For example: +flush an individual region or a region server name whose format +is 'host,port,startcode', to flush all its regions. +For example: hbase> flush 'TABLENAME' hbase> flush 'REGIONNAME' hbase> flush 'ENCODED_REGIONNAME' + hbase> flush 'REGION_SERVER_NAME' EOF end diff --git a/hbase-shell/src/test/ruby/hbase/admin_test.rb b/hbase-shell/src/test/ruby/hbase/admin_test.rb index cbeb8b626f2..929484c51d2 100644 --- a/hbase-shell/src/test/ruby/hbase/admin_test.rb +++ b/hbase-shell/src/test/ruby/hbase/admin_test.rb @@ -101,6 +101,10 @@ module Hbase define_test "flush should work" do command(:flush, 'hbase:meta') + servers = admin.list_liveservers + servers.each do |s| + command(:flush, s.toString) + end end #-------------------------------------------------------------------------------