You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by as...@apache.org on 2017/04/28 08:36:47 UTC
hbase git commit: HBase-14925 Develop HBase shell command/tool to
list table's region info through command line
Repository: hbase
Updated Branches:
refs/heads/master c4cbb419a -> 68b2e0f7d
HBase-14925 Develop HBase shell command/tool to list table's region info through command line
Signed-off-by: Ashish Singhi <as...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/68b2e0f7
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/68b2e0f7
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/68b2e0f7
Branch: refs/heads/master
Commit: 68b2e0f7d94c02aa82ac89f2ec2f052bdcd58704
Parents: c4cbb41
Author: Karan Mehta <karanmehta93 at gmail dot com>
Authored: Fri Apr 28 14:06:03 2017 +0530
Committer: Ashish Singhi <as...@apache.org>
Committed: Fri Apr 28 14:06:03 2017 +0530
----------------------------------------------------------------------
hbase-shell/src/main/ruby/shell.rb | 1 +
.../main/ruby/shell/commands/list_regions.rb | 76 ++++++++++++++++++++
2 files changed, 77 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/68b2e0f7/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 fc55f94..a6aba76 100644
--- a/hbase-shell/src/main/ruby/shell.rb
+++ b/hbase-shell/src/main/ruby/shell.rb
@@ -285,6 +285,7 @@ Shell.load_command_group(
alter_async
get_table
locate_region
+ list_regions
],
:aliases => {
'describe' => ['desc']
http://git-wip-us.apache.org/repos/asf/hbase/blob/68b2e0f7/hbase-shell/src/main/ruby/shell/commands/list_regions.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/list_regions.rb b/hbase-shell/src/main/ruby/shell/commands/list_regions.rb
new file mode 100644
index 0000000..527a6cb
--- /dev/null
+++ b/hbase-shell/src/main/ruby/shell/commands/list_regions.rb
@@ -0,0 +1,76 @@
+#
+#
+# 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 ListRegions < Command
+ def help
+
+ return<<EOF
+ List all regions for a particular table as an array and also filter them by server name (optional) as prefix.
+ By default, it will return all the regions for the table
+
+ Examples:
+ hbase> list_regions 'table_name'
+ hbase> list_regions 'table_name', 'server_name'
+
+EOF
+ return
+ end
+
+ def command(table_name, region_server_name = "")
+ admin_instance = admin.instance_variable_get("@admin")
+ conn_instance = admin_instance.getConnection()
+ cluster_status = admin_instance.getClusterStatus()
+ hregion_locator_instance = conn_instance.getRegionLocator(TableName.valueOf(table_name))
+ hregion_locator_list = hregion_locator_instance.getAllRegionLocations()
+ results = Array.new
+
+ begin
+ hregion_locator_list.each do |hregion|
+ hregion_info = hregion.getRegionInfo()
+ server_name = hregion.getServerName()
+ if hregion.getServerName().toString.start_with? region_server_name
+ startKey = Bytes.toString(hregion.getRegionInfo().getStartKey())
+ endKey = Bytes.toString(hregion.getRegionInfo().getEndKey())
+ region_load_map = cluster_status.getLoad(server_name).getRegionsLoad()
+ region_load = region_load_map.get(hregion_info.getRegionName())
+ region_store_file_size = region_load.getStorefileSizeMB()
+ region_requests = region_load.getRequestsCount()
+ results << { "server" => hregion.getServerName().toString(), "name" => hregion_info.getRegionNameAsString(), "startkey" => startKey, "endkey" => endKey, "size" => region_store_file_size, "requests" => region_requests }
+ end
+ end
+ ensure
+ hregion_locator_instance.close()
+ end
+
+ @end_time = Time.now
+
+ printf("%-60s | %-60s | %-15s | %-15s | %-20s | %-20s", "SERVER_NAME", "REGION_NAME", "START_KEY", "END_KEY", "SIZE", "REQ");
+ printf("\n")
+ for result in results
+ printf("%-60s | %-60s | %-15s | %-15s | %-20s | %-20s", result["server"], result["name"], result["startkey"], result["endkey"], result["size"], result["requests"]);
+ printf("\n")
+ end
+ printf("%d rows", results.size)
+
+ end
+ end
+ end
+end