You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by mb...@apache.org on 2015/12/10 22:34:04 UTC

[3/3] hbase git commit: HBASE-14941 locate_region shell command

HBASE-14941 locate_region shell command


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/512144ed
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/512144ed
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/512144ed

Branch: refs/heads/branch-1.2
Commit: 512144ed26c45d96638be78da8bde402940c6224
Parents: 54877cf
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Thu Dec 10 13:22:48 2015 -0800
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Thu Dec 10 13:30:58 2015 -0800

----------------------------------------------------------------------
 hbase-shell/src/main/ruby/hbase/admin.rb        | 26 ++++++++----
 hbase-shell/src/main/ruby/shell.rb              |  1 +
 .../main/ruby/shell/commands/locate_region.rb   | 44 ++++++++++++++++++++
 3 files changed, 64 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/512144ed/hbase-shell/src/main/ruby/hbase/admin.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb
index 527ead3..4e75ec4 100644
--- a/hbase-shell/src/main/ruby/hbase/admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/admin.rb
@@ -99,6 +99,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
@@ -436,10 +445,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?
@@ -674,7 +686,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
@@ -686,7 +698,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
@@ -695,7 +707,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

http://git-wip-us.apache.org/repos/asf/hbase/blob/512144ed/hbase-shell/src/main/ruby/shell.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb
index eb9fe89..06e4c72 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']

http://git-wip-us.apache.org/repos/asf/hbase/blob/512144ed/hbase-shell/src/main/ruby/shell/commands/locate_region.rb
----------------------------------------------------------------------
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