diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb index 46c9d95..67675a5 100644 --- a/hbase-shell/src/main/ruby/hbase/admin.rb +++ b/hbase-shell/src/main/ruby/hbase/admin.rb @@ -99,6 +99,13 @@ module Hbase end end + def locate_region(table_name, row_key) + locator = @connection.getRegionLocator(TableName.valueOf(table_name)) + region_location = locator.getRegionLocation(Bytes.toBytesBinary(row_key)) + locator.close() + return region_location + end + #---------------------------------------------------------------------------------------------- # Requests a cluster balance # Returns true if balancer ran @@ -668,7 +675,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 @@ -680,7 +687,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 @@ -689,7 +696,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 diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index 7bcc60e5b..0671118 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -267,6 +267,7 @@ Shell.load_command_group( alter_status alter_async get_table + locate_region ], :aliases => { 'describe' => ['desc'] diff --git a/hbase-shell/src/main/ruby/shell/commands/locate_region.rb b/hbase-shell/src/main/ruby/shell/commands/locate_region.rb new file mode 100644 index 0000000..b1e8c7b --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/locate_region.rb @@ -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