From e45d6b31f721946f771bcc1137ed5d714a252308 Mon Sep 17 00:00:00 2001 From: Viraj Jasani Date: Mon, 29 Jul 2019 20:35:17 +0530 Subject: [PATCH] HBASE-22735 : list_regions show basic info for region currently in transition with error handling(branch-1) --- .../main/ruby/shell/commands/list_regions.rb | 88 ++++++++++++------- 1 file changed, 55 insertions(+), 33 deletions(-) diff --git a/hbase-shell/src/main/ruby/shell/commands/list_regions.rb b/hbase-shell/src/main/ruby/shell/commands/list_regions.rb index f2d4b41cc1..43aee1ccd0 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_regions.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_regions.rb @@ -103,55 +103,77 @@ EOF regions.each do |hregion| hregion_info = hregion.getRegionInfo() server_name = hregion.getServerName() - region_load_map = cluster_status.getLoad(server_name).getRegionsLoad() + server_load = cluster_status.getLoad(server_name) + if server_load.nil? + region_load_map = java.util.HashMap.new + else + region_load_map = server_load.getRegionsLoad() + end region_load = region_load_map.get(hregion_info.getRegionName()) - # Ignore regions which exceed our locality threshold - if accept_region_for_locality? region_load.getDataLocality(), locality_threshold - result_hash = Hash.new - if size_hash.key?("SERVER_NAME") - result_hash.store("SERVER_NAME", server_name.toString().strip) - size_hash["SERVER_NAME"] = [size_hash["SERVER_NAME"], server_name.toString().strip.length].max - end + if region_load.nil? + puts "Can not find region: #{hregion_info.getRegionNameAsString.strip} , it may be disabled or in transition\n" + else + # Ignore regions which exceed our locality threshold + next unless accept_region_for_locality? region_load.getDataLocality(), locality_threshold + end + result_hash = {} - if size_hash.key?("REGION_NAME") - result_hash.store("REGION_NAME", hregion_info.getRegionNameAsString().strip) - size_hash["REGION_NAME"] = [size_hash["REGION_NAME"], hregion_info.getRegionNameAsString().length].max - end + if size_hash.key?("SERVER_NAME") + result_hash.store("SERVER_NAME", server_name.toString().strip) + size_hash["SERVER_NAME"] = [size_hash["SERVER_NAME"], server_name.toString().strip.length].max + end - if size_hash.key?("START_KEY") - startKey = Bytes.toStringBinary(hregion_info.getStartKey()).strip - result_hash.store("START_KEY", startKey) - size_hash["START_KEY"] = [size_hash["START_KEY"], startKey.length].max - end + if size_hash.key?("REGION_NAME") + result_hash.store("REGION_NAME", hregion_info.getRegionNameAsString().strip) + size_hash["REGION_NAME"] = [size_hash["REGION_NAME"], hregion_info.getRegionNameAsString().length].max + end - if size_hash.key?("END_KEY") - endKey = Bytes.toStringBinary(hregion_info.getEndKey()).strip - result_hash.store("END_KEY", endKey) - size_hash["END_KEY"] = [size_hash["END_KEY"], endKey.length].max - end + if size_hash.key?("START_KEY") + startKey = Bytes.toStringBinary(hregion_info.getStartKey()).strip + result_hash.store("START_KEY", startKey) + size_hash["START_KEY"] = [size_hash["START_KEY"], startKey.length].max + end - if size_hash.key?("SIZE") + if size_hash.key?("END_KEY") + endKey = Bytes.toStringBinary(hregion_info.getEndKey()).strip + result_hash.store("END_KEY", endKey) + size_hash["END_KEY"] = [size_hash["END_KEY"], endKey.length].max + end + + if size_hash.key?("SIZE") + if region_load.nil? + region_store_file_size = '' + else region_store_file_size = region_load.getStorefileSizeMB().to_s.strip - result_hash.store("SIZE", region_store_file_size) - size_hash["SIZE"] = [size_hash["SIZE"], region_store_file_size.length].max end + result_hash.store("SIZE", region_store_file_size) + size_hash["SIZE"] = [size_hash["SIZE"], region_store_file_size.length].max + end - if size_hash.key?("REQ") + if size_hash.key?("REQ") + if region_load.nil? + region_requests = '' + else region_requests = region_load.getRequestsCount().to_s.strip - result_hash.store("REQ", region_requests) - size_hash["REQ"] = [size_hash["REQ"], region_requests.length].max end + result_hash.store("REQ", region_requests) + size_hash["REQ"] = [size_hash["REQ"], region_requests.length].max + end - if size_hash.key?("LOCALITY") + if size_hash.key?("LOCALITY") + if region_load.nil? + locality = '' + else locality = region_load.getDataLocality().to_s.strip - result_hash.store("LOCALITY", locality) - size_hash["LOCALITY"] = [size_hash["LOCALITY"], locality.length].max end - - results << result_hash + result_hash.store("LOCALITY", locality) + size_hash["LOCALITY"] = [size_hash["LOCALITY"], locality.length].max end + + results << result_hash + end ensure hregion_locator_instance.close() -- 2.17.2 (Apple Git-113)