HBASE-22735 list_regions show basic info for region currently in transition with error handling

Signed-off-by: Andrew Purtell <apurtell@apache.org>
Signed-off-by: Michael Stack <stack@apache.org>
This commit is contained in:
Viraj Jasani 2019-07-29 00:29:59 +05:30 committed by Andrew Purtell
parent 35acf3cb78
commit 8cfc46d8d0
No known key found for this signature in database
GPG Key ID: 8597754DD5365CCD
1 changed files with 37 additions and 21 deletions

View File

@ -79,7 +79,6 @@ EOF
raise "#{cols} must be an array of strings. Possible values are SERVER_NAME, REGION_NAME, START_KEY, END_KEY, SIZE, REQ, LOCALITY." raise "#{cols} must be an array of strings. Possible values are SERVER_NAME, REGION_NAME, START_KEY, END_KEY, SIZE, REQ, LOCALITY."
end end
error = false
admin_instance = admin.instance_variable_get('@admin') admin_instance = admin.instance_variable_get('@admin')
conn_instance = admin_instance.getConnection conn_instance = admin_instance.getConnection
cluster_status = org.apache.hadoop.hbase.ClusterStatus.new(admin_instance.getClusterMetrics) cluster_status = org.apache.hadoop.hbase.ClusterStatus.new(admin_instance.getClusterMetrics)
@ -105,17 +104,24 @@ EOF
regions.each do |hregion| regions.each do |hregion|
hregion_info = hregion.getRegion hregion_info = hregion.getRegion
server_name = hregion.getServerName 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_name = hregion_info.getRegionNameAsString
region_load = region_load_map.get(hregion_info.getRegionName) region_load = region_load_map.get(hregion_info.getRegionName)
if region_load.nil? if region_load.nil?
puts "Can not find region: #{hregion_info.getRegionName} , it may be disabled or in transition\n" puts "Can not find all details for region: " \
error = true "#{region_name.strip} ," \
break " 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 end
# Ignore regions which exceed our locality threshold
next unless accept_region_for_locality? region_load.getDataLocality, locality_threshold
result_hash = {} result_hash = {}
if size_hash.key?('SERVER_NAME') if size_hash.key?('SERVER_NAME')
@ -124,36 +130,48 @@ EOF
end end
if size_hash.key?('REGION_NAME') if size_hash.key?('REGION_NAME')
result_hash.store('REGION_NAME', hregion_info.getRegionNameAsString.strip) result_hash.store('REGION_NAME', region_name.strip)
size_hash['REGION_NAME'] = [size_hash['REGION_NAME'], hregion_info.getRegionNameAsString.length].max size_hash['REGION_NAME'] = [size_hash['REGION_NAME'], region_name.length].max
end end
if size_hash.key?('START_KEY') if size_hash.key?('START_KEY')
startKey = Bytes.toStringBinary(hregion_info.getStartKey).strip start_key = Bytes.toStringBinary(hregion_info.getStartKey).strip
result_hash.store('START_KEY', startKey) result_hash.store('START_KEY', start_key)
size_hash['START_KEY'] = [size_hash['START_KEY'], startKey.length].max size_hash['START_KEY'] = [size_hash['START_KEY'], start_key.length].max
end end
if size_hash.key?('END_KEY') if size_hash.key?('END_KEY')
endKey = Bytes.toStringBinary(hregion_info.getEndKey).strip end_key = Bytes.toStringBinary(hregion_info.getEndKey).strip
result_hash.store('END_KEY', endKey) result_hash.store('END_KEY', end_key)
size_hash['END_KEY'] = [size_hash['END_KEY'], endKey.length].max size_hash['END_KEY'] = [size_hash['END_KEY'], end_key.length].max
end end
if size_hash.key?('SIZE') if size_hash.key?('SIZE')
region_store_file_size = region_load.getStorefileSizeMB.to_s.strip if region_load.nil?
region_store_file_size = ''
else
region_store_file_size = region_load.getStorefileSizeMB.to_s.strip
end
result_hash.store('SIZE', region_store_file_size) result_hash.store('SIZE', region_store_file_size)
size_hash['SIZE'] = [size_hash['SIZE'], region_store_file_size.length].max size_hash['SIZE'] = [size_hash['SIZE'], region_store_file_size.length].max
end end
if size_hash.key?('REQ') if size_hash.key?('REQ')
region_requests = region_load.getRequestsCount.to_s.strip if region_load.nil?
region_requests = ''
else
region_requests = region_load.getRequestsCount.to_s.strip
end
result_hash.store('REQ', region_requests) result_hash.store('REQ', region_requests)
size_hash['REQ'] = [size_hash['REQ'], region_requests.length].max size_hash['REQ'] = [size_hash['REQ'], region_requests.length].max
end end
if size_hash.key?('LOCALITY') if size_hash.key?('LOCALITY')
locality = region_load.getDataLocality.to_s.strip if region_load.nil?
locality = ''
else
locality = region_load.getDataLocality.to_s.strip
end
result_hash.store('LOCALITY', locality) result_hash.store('LOCALITY', locality)
size_hash['LOCALITY'] = [size_hash['LOCALITY'], locality.length].max size_hash['LOCALITY'] = [size_hash['LOCALITY'], locality.length].max
end end
@ -166,8 +184,6 @@ EOF
@end_time = Time.now @end_time = Time.now
return if error
size_hash.each do |param, length| size_hash.each do |param, length|
printf(" %#{length}s |", param) printf(" %#{length}s |", param)
end end