Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions hbase-shell/src/main/ruby/hbase/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,34 @@ def move(encoded_region_name, server = nil)
@admin.move(encoded_region_name.to_java_bytes, server ? server.to_java_bytes : nil)
end

#----------------------------------------------------------------------------------------------
# Reopen regions of a table
def reopen_regions(table_name, regions = nil)
table_name_obj = TableName.valueOf(table_name)
if regions.nil? || regions.empty?
@admin.reopenTableRegions(table_name_obj)
else
# Get all regions of the table
all_regions = @admin.getRegions(table_name_obj)
target_regions = java.util.ArrayList.new

regions.each do |r|
# r could be encoded name or full name
found = false
all_regions.each do |region_info|
if region_info.getEncodedName == r || region_info.getRegionNameAsString == r
target_regions.add(region_info)
found = true
break
end
end
raise ArgumentError, "Region #{r} not found in table #{table_name}" unless found
end

@admin.reopenTableRegions(table_name_obj, target_regions)
end
end

#----------------------------------------------------------------------------------------------
# Merge multiple regions
def merge_region(regions, force)
Expand Down
1 change: 1 addition & 0 deletions hbase-shell/src/main/ruby/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ def self.exception_handler(hide_traceback)
normalizer_enabled
is_in_maintenance_mode
clear_slowlog_responses
reopen_regions
close_region
compact
compaction_switch
Expand Down
37 changes: 37 additions & 0 deletions hbase-shell/src/main/ruby/shell/commands/reopen_regions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
#
# 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 ReopenRegions < Command
def help
<<-EOF
Reopen all regions of a table or specific regions of a table.
Examples:
hbase> reopen_regions 'TABLE_NAME'
hbase> reopen_regions 'TABLE_NAME', ['REGION_NAME1', 'REGION_NAME2']
EOF
end

def command(table_name, regions = nil)
admin.reopen_regions(table_name, regions)
end
end
end
end
66 changes: 66 additions & 0 deletions hbase-shell/src/test/ruby/hbase/reopen_regions_test_cluster.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#
#
# 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_shell'
require 'stringio'
require 'hbase_constants'
require 'hbase/hbase'
require 'hbase/table'

module Hbase
class ReopenRegionsTest < Test::Unit::TestCase
include TestHelpers

def setup
setup_hbase
# Create test table if it does not exist
@test_name = "hbase_reopen_regions_test_table"
create_test_table(@test_name)
end

def teardown
shutdown
end

define_test "reopen_regions should work for all regions" do
assert_nothing_raised do
command(:reopen_regions, @test_name)
end
end

define_test "reopen_regions should work for specific regions" do
# Get Java Admin to fetch regions
java_admin = admin.instance_variable_get(:@admin)
regions = java_admin.getRegions(org.apache.hadoop.hbase.TableName.valueOf(@test_name))

assert(regions.size > 0, "Test table should have regions")
region_encoded_name = regions.get(0).getEncodedName

assert_nothing_raised do
command(:reopen_regions, @test_name, [region_encoded_name])
end
end

define_test "reopen_regions should raise error for non-existent region" do
assert_raise(ArgumentError) do
command(:reopen_regions, @test_name, ['non-existent-region'])
end
end
end
end