SHARE
TWEET

list_regions

hivefans Mar 13th, 2019 (edited) 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def list_regions(table_name, region_server_name = "")
  2.   admin = @hbase.admin(@hbase)
  3.   admin_instance = admin.instance_variable_get("@admin")
  4.   conn_instance = admin_instance.getConnection()
  5.   cluster_status = admin_instance.getClusterStatus()
  6.   hregion_locator_instance = conn_instance.getRegionLocator(TableName.valueOf(table_name))
  7.   hregion_locator_list = hregion_locator_instance.getAllRegionLocations()
  8.   table_max_file_size = (admin_instance.getTableDescriptor(TableName.valueOf(table_name)).getMaxFileSize()/1024/1024).ceil
  9.   if table_max_file_size < 0
  10.     table_max_file_size = (admin_instance.getConfiguration.getLong("hbase.hregion.max.filesize",
  11. 5)/1024/1024).ceil
  12.   end
  13.   results = Array.new
  14.   begin
  15.     hregion_locator_list.each do |hregion|
  16.       hregion_info = hregion.getRegionInfo()
  17.       server_name = hregion.getServerName()
  18.       if hregion.getServerName().toString.start_with? region_server_name
  19.         startKey = Bytes.toString(hregion.getRegionInfo().getStartKey())
  20.         endKey = Bytes.toString(hregion.getRegionInfo().getEndKey())
  21.         region_load_map = cluster_status.getLoad(server_name).getRegionsLoad()
  22.         region_load = region_load_map.get(hregion_info.getRegionName())
  23.         region_store_file_size = region_load.getStorefileSizeMB()
  24.         occupancy = (region_store_file_size*100/table_max_file_size).ceil
  25.         region_requests = region_load.getRequestsCount()
  26.         results << { "server" => hregion.getServerName().toString(),
  27. "name" => hregion_info.getRegionNameAsString(), "startkey" => startKey, "endkey" =>
  28. endKey, "size" => region_store_file_size, "occupancy" => occupancy,
  29. "requests" => region_requests }
  30.       end
  31.     end
  32.   ensure
  33.     hregion_locator_instance.close()
  34.   end
  35.   @end_time = Time.now
  36.   printf("%-45s | %-75s | %-10s | %-10s", "SERVER_NAME", "REGION_NAME", "SIZE(MB)", "REQ");
  37.   printf("\n")
  38.   for result in results
  39.     printf("%-45s | %-75s | %-10s | %-10s", result["server"], result["name"], result["size"], result["requests"]);
  40.       printf("\n")
  41.   end
  42.   printf("%d rows", results.size)
  43. end
  44.  
  45. def filesize(size)
  46.         units = ['MB', 'GB', 'TB', 'PB', 'EB']
  47.  
  48.         return '0.0 B' if size == 0
  49.         exp = (Math.log(size) / Math.log(1024)).to_i
  50.         exp = 6 if exp > 6
  51.  
  52.         '%.1f %s' % [size.to_f / 1024 ** exp, units[exp]]
  53. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top