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

svn commit: r1181486 - /hbase/branches/0.89/bin/list_regions.rb

Author: nspiegelberg
Date: Tue Oct 11 02:12:42 2011
New Revision: 1181486

URL: http://svn.apache.org/viewvc?rev=1181486&view=rev
Log:
List all Regions in a Table

Summary:
quick script to list all regions in a table

Test Plan:
- bin/hbase org.jruby.Main list_regions.rb 'table'

DiffCamp Revision: 213083
Reviewed By: kannan
Reviewers: kannan
CC: nspiegelberg, kannan
Revert Plan:
OK

Added:
    hbase/branches/0.89/bin/list_regions.rb

Added: hbase/branches/0.89/bin/list_regions.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/bin/list_regions.rb?rev=1181486&view=auto
==============================================================================
--- hbase/branches/0.89/bin/list_regions.rb (added)
+++ hbase/branches/0.89/bin/list_regions.rb Tue Oct 11 02:12:42 2011
@@ -0,0 +1,47 @@
+# List regions belonging to a table + what server they're on
+# To use this script, run:
+#
+#  ${HBASE_HOME}/bin/hbase org.jruby.Main list_regions.rb
+
+TABLE_NAME=ARGV[0]
+
+unless TABLE_NAME
+  print "USAGE: #{$0} TABLE \n"
+  exit 1
+end
+
+require 'java'
+
+import org.apache.hadoop.hbase.HBaseConfiguration
+import org.apache.hadoop.hbase.HConstants
+import org.apache.hadoop.hbase.client.HTable
+import org.apache.hadoop.hbase.client.Scan
+import org.apache.hadoop.hbase.util.Bytes
+import org.apache.hadoop.hbase.util.Writables
+
+config = HBaseConfiguration.new
+config.set 'fs.default.name', config.get(HConstants::HBASE_DIR)
+JAVA_TABLE_NAME=TABLE_NAME.to_java_bytes
+INFO_FAMILY = 'info'.to_java_bytes
+REGION_INFO_COLUMN = 'regioninfo'.to_java_bytes
+SERVER_COLUMN = 'server'.to_java_bytes
+
+table = HTable.new config, '.META.'.to_java_bytes
+
+scan = Scan.new
+scan.addColumn INFO_FAMILY, REGION_INFO_COLUMN
+scan.addColumn INFO_FAMILY, SERVER_COLUMN
+scanner = table.getScanner scan
+
+print "Finding regions in %s...\n" % [TABLE_NAME]
+  while row = scanner.next
+  region = Writables.getHRegionInfo row.getValue(INFO_FAMILY, REGION_INFO_COLUMN)
+  next unless Bytes.equals(region.getTableDesc.getName, JAVA_TABLE_NAME)
+  server_bytes = row.getValue(INFO_FAMILY, SERVER_COLUMN)
+  server = server_bytes ? String.from_java_bytes(server_bytes) : 'no server'
+
+  table =  String.from_java_bytes region.getTableDesc.getName
+  print "%s - %s\n"  % [region.getRegionNameAsString, server]
+end
+scanner.close
+print "Finished."