HBASE-13839 Fix AssgnmentManagerTmpl.jamon issues (coloring, content etc.)

This commit is contained in:
stack 2016-02-12 15:06:38 -08:00
parent c8d133186b
commit 1419628881
2 changed files with 110 additions and 57 deletions

View File

@ -25,84 +25,111 @@ org.apache.hadoop.hbase.HBaseConfiguration;
org.apache.hadoop.hbase.HConstants; org.apache.hadoop.hbase.HConstants;
java.util.Iterator; java.util.Iterator;
java.util.Map; java.util.Map;
java.util.List;
java.util.ArrayList;
java.util.Map.Entry;
java.util.Arrays;
</%import> </%import>
<%args> <%args>
AssignmentManager assignmentManager; AssignmentManager assignmentManager;
int limit = 100; int limit = 100;
</%args> </%args>
<%java Map<String, RegionState> rit = assignmentManager
.getRegionStates().getRegionsInTransitionOrderedByTimestamp(); %>
<%if !rit.isEmpty() %>
<%java> <%java>
Map<String, RegionState> rit = assignmentManager List<String> ritsOverThreshold = new ArrayList<>();
.getRegionStates().getRegionsInTransition(); List<String> ritsTwiceThreshold = new ArrayList<>();
// process the map to find region in transition details // process the map to find region in transition details
Configuration conf = HBaseConfiguration.create(); Configuration conf = HBaseConfiguration.create();
int ritThreshold = conf.getInt(HConstants.METRICS_RIT_STUCK_WARNING_THRESHOLD, 60000); int ritThreshold = conf.getInt(HConstants.METRICS_RIT_STUCK_WARNING_THRESHOLD, 60000);
int numOfRITOverThreshold = 0; int numOfRITOverThreshold = 0;
long maxRITTime = Long.MIN_VALUE;
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
String regionIDForOldestRIT = ""; // avoiding null
for (Map.Entry<String, RegionState> e : rit.entrySet()) { for (Map.Entry<String, RegionState> e : rit.entrySet()) {
long ritTime = currentTime - e.getValue().getStamp(); long ritTime = currentTime - e.getValue().getStamp();
if(ritTime > ritThreshold) { if(ritTime > (ritThreshold * 2)) {
numOfRITOverThreshold++; numOfRITOverThreshold++;
} ritsTwiceThreshold.add(e.getKey());
if(maxRITTime < ritTime) { } else if (ritTime > ritThreshold) {
maxRITTime = ritTime; numOfRITOverThreshold++;
regionIDForOldestRIT = e.getKey(); ritsOverThreshold.add(e.getKey());
}
}
int totalRITs = rit.size();
int toRemove = rit.size() - limit;
int removed = 0;
if (toRemove > 0) {
// getRegionsInTransition returned a copy, so we can mutate it
for (Iterator<Map.Entry<String, RegionState>> it = rit.entrySet().iterator();
it.hasNext() && toRemove > 0;
) {
Map.Entry<String, RegionState> e = it.next();
if (HRegionInfo.FIRST_META_REGIONINFO.getEncodedName().equals(
e.getKey()) ||
regionIDForOldestRIT.equals(e.getKey())) {
// don't remove the meta & the oldest rit regions, they're too interesting!
continue;
}
it.remove();
toRemove--;
removed++;
} }
} }
int numOfRITs = rit.size();
int ritsPerPage = Math.min(5, numOfRITs);
int numOfPages = (int) Math.ceil(numOfRITs * 1.0 / ritsPerPage);
</%java> </%java>
<%if !rit.isEmpty() %>
<section> <section>
<h2>Regions in Transition</h2> <h2>Regions in Transition</h2>
<table class="table table-striped"> <p><% numOfRITs %> region(s) in transition.
<tr><th>Region</th><th>State</th><th>RIT time (ms)</th></tr> <%if !ritsTwiceThreshold.isEmpty() %>
<span class="label label-danger" style="font-size:100%;font-weight:normal">
<%elseif !ritsOverThreshold.isEmpty() %>
<span class="label label-warning" style="font-size:100%;font-weight:normal">
<%else>
<span>
</%if>
<% numOfRITOverThreshold %> region(s) in transition for
more than <% ritThreshold %> milliseconds.
</span>
</p>
<div class="tabbable">
<div class="tab-content">
<%java int recordItr = 0; %>
<%for Map.Entry<String, RegionState> entry : rit.entrySet() %> <%for Map.Entry<String, RegionState> entry : rit.entrySet() %>
<%if regionIDForOldestRIT.equals(entry.getKey()) %> <%if (recordItr % ritsPerPage) == 0 %>
<tr BGCOLOR="#FE2E2E" > <%if recordItr == 0 %>
<div class="tab-pane active" id="tab_rits<% (recordItr / ritsPerPage) + 1 %>">
<%else>
<div class="tab-pane" id="tab_rits<% (recordItr / ritsPerPage) + 1 %>">
</%if>
<table class="table table-striped" style="margin-bottom:0px;"><tr><th>Region</th>
<th>State</th><th>RIT time (ms)</th></tr>
</%if>
<%if ritsOverThreshold.contains(entry.getKey()) %>
<tr class="alert alert-warning" role="alert">
<%elseif ritsTwiceThreshold.contains(entry.getKey()) %>
<tr class="alert alert-danger" role="alert">
<%else> <%else>
<tr> <tr>
</%if> </%if>
<td><% entry.getKey() %></td><td> <td><% entry.getKey() %></td><td>
<% HRegionInfo.getDescriptiveNameFromRegionStateForDisplay( <% HRegionInfo.getDescriptiveNameFromRegionStateForDisplay(
entry.getValue(), conf) %></td> entry.getValue(), conf) %></td>
<td><% (currentTime - entry.getValue().getStamp()) %> </td></tr> <td><% (currentTime - entry.getValue().getStamp()) %> </td>
</%for>
<%if numOfRITOverThreshold > 0 %>
<tr BGCOLOR="#D7DF01" >
<%else>
<tr>
</%if>
<td>Total number of Regions in Transition for more than <% ritThreshold %> milliseconds</td><td> <% numOfRITOverThreshold %></td><td></td>
</tr> </tr>
<tr> <td> Total number of Regions in Transition</td><td><% totalRITs %> </td><td></td> <%java recordItr++; %>
<%if (recordItr % ritsPerPage) == 0 %>
</table> </table>
<%if removed > 0 %> </div>
(<% removed %> more regions in transition not shown)
</%if> </%if>
</%for>
<%if (recordItr % ritsPerPage) != 0 %>
<%for ; (recordItr % ritsPerPage) != 0 ; recordItr++ %>
<tr><td colspan="3" style="height:61px"></td></tr>
</%for>
</table>
</div>
</%if>
</div>
<nav>
<ul class="nav nav-pills pagination">
<%for int i = 1 ; i <= numOfPages; i++ %>
<%if i == 1 %>
<li class="active">
<%else>
<li>
</%if>
<a href="#tab_rits<% i %>"><% i %></a></li>
</%for>
</ul>
</nav>
</div>
</section> </section>
</%if> </%if>

View File

@ -23,9 +23,13 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Collections;
import java.util.Comparator;
import java.util.TreeMap; import java.util.TreeMap;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -206,6 +210,28 @@ public class RegionStates {
return (Map<String, RegionState>)regionsInTransition.clone(); return (Map<String, RegionState>)regionsInTransition.clone();
} }
@SuppressWarnings("unchecked")
public synchronized Map<String, RegionState> getRegionsInTransitionOrderedByTimestamp() {
Map<String, RegionState> rit = (Map<String, RegionState>)regionsInTransition.clone();
List<Map.Entry<String, RegionState>> list = new LinkedList<>(rit.entrySet());
// Compare the RITs' timestamps for ordering.
Comparator<Map.Entry<String, RegionState>> c =
new Comparator<Map.Entry<String, RegionState>>() {
@Override
public int compare(Map.Entry<String, RegionState> o1, Map.Entry<String, RegionState> o2) {
return ((Long)o1.getValue().getStamp()).compareTo((Long)o2.getValue().getStamp());
}
};
Collections.sort(list, c);
Map<String, RegionState> result = new LinkedHashMap<>();
for (Map.Entry<String, RegionState> entry : list) {
result.put(entry.getKey(), entry.getValue());
}
return result;
}
/** /**
* @return True if specified region in transition. * @return True if specified region in transition.
*/ */