HBASE-14941 locate_region shell command

This commit is contained in:
Matteo Bertozzi 2015-12-10 13:22:48 -08:00
parent 26ac60b03f
commit 6f8d5e86ce
3 changed files with 64 additions and 7 deletions

View File

@ -132,6 +132,15 @@ module Hbase
end
end
def locate_region(table_name, row_key)
locator = @connection.getRegionLocator(TableName.valueOf(table_name))
begin
return locator.getRegionLocation(Bytes.toBytesBinary(row_key))
ensure
locator.close()
end
end
#----------------------------------------------------------------------------------------------
# Requests a cluster balance
# Returns true if balancer ran
@ -469,10 +478,13 @@ module Hbase
def truncate_preserve(table_name, conf = @conf)
h_table = @connection.getTable(TableName.valueOf(table_name))
locator = @connection.getRegionLocator(TableName.valueOf(table_name))
splits = locator.getAllRegionLocations().
map{|i| Bytes.toString(i.getRegionInfo().getStartKey)}.
delete_if{|k| k == ""}.to_java :String
locator.close()
begin
splits = locator.getAllRegionLocations().
map{|i| Bytes.toString(i.getRegionInfo().getStartKey)}.
delete_if{|k| k == ""}.to_java :String
ensure
locator.close()
end
table_description = @admin.getTableDescriptor(TableName.valueOf(table_name))
yield 'Disabling table...' if block_given?
@ -707,7 +719,7 @@ module Hbase
end
elsif format == "replication"
#check whether replication is enabled or not
if (!@admin.getConfiguration().getBoolean(org.apache.hadoop.hbase.HConstants::REPLICATION_ENABLE_KEY,
if (!@admin.getConfiguration().getBoolean(org.apache.hadoop.hbase.HConstants::REPLICATION_ENABLE_KEY,
org.apache.hadoop.hbase.HConstants::REPLICATION_ENABLE_DEFAULT))
puts("Please enable replication first.")
else
@ -719,7 +731,7 @@ module Hbase
rSourceString = " SOURCE:"
rLoadSink = sl.getReplicationLoadSink()
rSinkString << " AgeOfLastAppliedOp=" + rLoadSink.getAgeOfLastAppliedOp().to_s
rSinkString << ", TimeStampsOfLastAppliedOp=" +
rSinkString << ", TimeStampsOfLastAppliedOp=" +
(java.util.Date.new(rLoadSink.getTimeStampsOfLastAppliedOp())).toString()
rLoadSourceList = sl.getReplicationLoadSourceList()
index = 0
@ -728,7 +740,7 @@ module Hbase
rSourceString << " PeerID=" + rLoadSource.getPeerID()
rSourceString << ", AgeOfLastShippedOp=" + rLoadSource.getAgeOfLastShippedOp().to_s
rSourceString << ", SizeOfLogQueue=" + rLoadSource.getSizeOfLogQueue().to_s
rSourceString << ", TimeStampsOfLastShippedOp=" +
rSourceString << ", TimeStampsOfLastShippedOp=" +
(java.util.Date.new(rLoadSource.getTimeStampOfLastShippedOp())).toString()
rSourceString << ", Replication Lag=" + rLoadSource.getReplicationLag().to_s
index = index + 1

View File

@ -267,6 +267,7 @@ Shell.load_command_group(
alter_status
alter_async
get_table
locate_region
],
:aliases => {
'describe' => ['desc']

View File

@ -0,0 +1,44 @@
#
# Copyright The Apache Software Foundation
#
# 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 LocateRegion < Command
def help
return <<-EOF
Locate the region given a table name and a row-key
hbase> locate_region 'tableName', 'key0'
EOF
end
def command(table, row_key)
now = Time.now
region_location = admin.locate_region(table, row_key)
hri = region_location.getRegionInfo()
formatter.header([ "HOST", "REGION" ])
formatter.row([region_location.getHostnamePort(), hri.toString()])
formatter.footer(now, 1)
end
end
end
end