Skip to content

Commit 5e57b0f

Browse files
committed
HBASE-22735 : list_regions show basic info for region currently in transition with error handling
1 parent 11f30de commit 5e57b0f

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

hbase-shell/src/main/ruby/shell/commands/list_regions.rb

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def command(table_name, options = nil, cols = nil)
7979
raise "#{cols} must be an array of strings. Possible values are SERVER_NAME, REGION_NAME, START_KEY, END_KEY, SIZE, REQ, LOCALITY."
8080
end
8181

82-
error = false
8382
admin_instance = admin.instance_variable_get('@admin')
8483
conn_instance = admin_instance.getConnection
8584
cluster_status = org.apache.hadoop.hbase.ClusterStatus.new(admin_instance.getClusterMetrics)
@@ -105,17 +104,20 @@ def command(table_name, options = nil, cols = nil)
105104
regions.each do |hregion|
106105
hregion_info = hregion.getRegion
107106
server_name = hregion.getServerName
108-
region_load_map = cluster_status.getLoad(server_name).getRegionsLoad
107+
server_load = cluster_status.getLoad(server_name)
108+
if server_load.nil?
109+
region_load_map = java.util.HashMap.new
110+
else
111+
region_load_map = server_load.getRegionsLoad
112+
end
109113
region_load = region_load_map.get(hregion_info.getRegionName)
110114

111115
if region_load.nil?
112-
puts "Can not find region: #{hregion_info.getRegionName} , it may be disabled or in transition\n"
113-
error = true
114-
break
116+
puts "Can not find all details for region: #{hregion_info.getRegionNameAsString.strip} , it may be disabled or in transition\n"
117+
else
118+
# Ignore regions which exceed our locality threshold
119+
next unless accept_region_for_locality? region_load.getDataLocality, locality_threshold
115120
end
116-
117-
# Ignore regions which exceed our locality threshold
118-
next unless accept_region_for_locality? region_load.getDataLocality, locality_threshold
119121
result_hash = {}
120122

121123
if size_hash.key?('SERVER_NAME')
@@ -141,19 +143,31 @@ def command(table_name, options = nil, cols = nil)
141143
end
142144

143145
if size_hash.key?('SIZE')
144-
region_store_file_size = region_load.getStorefileSizeMB.to_s.strip
146+
if region_load.nil?
147+
region_store_file_size = ''
148+
else
149+
region_store_file_size = region_load.getStorefileSizeMB.to_s.strip
150+
end
145151
result_hash.store('SIZE', region_store_file_size)
146152
size_hash['SIZE'] = [size_hash['SIZE'], region_store_file_size.length].max
147153
end
148154

149155
if size_hash.key?('REQ')
150-
region_requests = region_load.getRequestsCount.to_s.strip
156+
if region_load.nil?
157+
region_requests = ''
158+
else
159+
region_requests = region_load.getRequestsCount.to_s.strip
160+
end
151161
result_hash.store('REQ', region_requests)
152162
size_hash['REQ'] = [size_hash['REQ'], region_requests.length].max
153163
end
154164

155165
if size_hash.key?('LOCALITY')
156-
locality = region_load.getDataLocality.to_s.strip
166+
if region_load.nil?
167+
locality = ''
168+
else
169+
locality = region_load.getDataLocality.to_s.strip
170+
end
157171
result_hash.store('LOCALITY', locality)
158172
size_hash['LOCALITY'] = [size_hash['LOCALITY'], locality.length].max
159173
end
@@ -166,8 +180,6 @@ def command(table_name, options = nil, cols = nil)
166180

167181
@end_time = Time.now
168182

169-
return if error
170-
171183
size_hash.each do |param, length|
172184
printf(" %#{length}s |", param)
173185
end

0 commit comments

Comments
 (0)