Skip to content

Commit ce3fe01

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

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

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

Lines changed: 37 additions & 21 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,24 @@ 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
113+
region_name = hregion_info.getRegionNameAsString
109114
region_load = region_load_map.get(hregion_info.getRegionName)
110115

111116
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
117+
puts "Can not find all details for region: " \
118+
"#{region_name.strip} ," \
119+
" it may be disabled or in transition\n"
120+
else
121+
# Ignore regions which exceed our locality threshold
122+
next unless accept_region_for_locality? region_load.getDataLocality,
123+
locality_threshold
115124
end
116-
117-
# Ignore regions which exceed our locality threshold
118-
next unless accept_region_for_locality? region_load.getDataLocality, locality_threshold
119125
result_hash = {}
120126

121127
if size_hash.key?('SERVER_NAME')
@@ -124,36 +130,48 @@ def command(table_name, options = nil, cols = nil)
124130
end
125131

126132
if size_hash.key?('REGION_NAME')
127-
result_hash.store('REGION_NAME', hregion_info.getRegionNameAsString.strip)
128-
size_hash['REGION_NAME'] = [size_hash['REGION_NAME'], hregion_info.getRegionNameAsString.length].max
133+
result_hash.store('REGION_NAME', region_name.strip)
134+
size_hash['REGION_NAME'] = [size_hash['REGION_NAME'], region_name.length].max
129135
end
130136

131137
if size_hash.key?('START_KEY')
132-
startKey = Bytes.toStringBinary(hregion_info.getStartKey).strip
133-
result_hash.store('START_KEY', startKey)
134-
size_hash['START_KEY'] = [size_hash['START_KEY'], startKey.length].max
138+
start_key = Bytes.toStringBinary(hregion_info.getStartKey).strip
139+
result_hash.store('START_KEY', start_key)
140+
size_hash['START_KEY'] = [size_hash['START_KEY'], start_key.length].max
135141
end
136142

137143
if size_hash.key?('END_KEY')
138-
endKey = Bytes.toStringBinary(hregion_info.getEndKey).strip
139-
result_hash.store('END_KEY', endKey)
140-
size_hash['END_KEY'] = [size_hash['END_KEY'], endKey.length].max
144+
end_key = Bytes.toStringBinary(hregion_info.getEndKey).strip
145+
result_hash.store('END_KEY', end_key)
146+
size_hash['END_KEY'] = [size_hash['END_KEY'], end_key.length].max
141147
end
142148

143149
if size_hash.key?('SIZE')
144-
region_store_file_size = region_load.getStorefileSizeMB.to_s.strip
150+
if region_load.nil?
151+
region_store_file_size = ''
152+
else
153+
region_store_file_size = region_load.getStorefileSizeMB.to_s.strip
154+
end
145155
result_hash.store('SIZE', region_store_file_size)
146156
size_hash['SIZE'] = [size_hash['SIZE'], region_store_file_size.length].max
147157
end
148158

149159
if size_hash.key?('REQ')
150-
region_requests = region_load.getRequestsCount.to_s.strip
160+
if region_load.nil?
161+
region_requests = ''
162+
else
163+
region_requests = region_load.getRequestsCount.to_s.strip
164+
end
151165
result_hash.store('REQ', region_requests)
152166
size_hash['REQ'] = [size_hash['REQ'], region_requests.length].max
153167
end
154168

155169
if size_hash.key?('LOCALITY')
156-
locality = region_load.getDataLocality.to_s.strip
170+
if region_load.nil?
171+
locality = ''
172+
else
173+
locality = region_load.getDataLocality.to_s.strip
174+
end
157175
result_hash.store('LOCALITY', locality)
158176
size_hash['LOCALITY'] = [size_hash['LOCALITY'], locality.length].max
159177
end
@@ -166,8 +184,6 @@ def command(table_name, options = nil, cols = nil)
166184

167185
@end_time = Time.now
168186

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

0 commit comments

Comments
 (0)