HBASE-7332 [webui] HMaster webui should display the number of regions a table has. (Andrey Stepachev)
This commit is contained in:
parent
0fa6eedcdb
commit
adcb840e1b
|
@ -43,6 +43,8 @@ org.apache.hadoop.hbase.ServerLoad;
|
|||
org.apache.hadoop.hbase.ServerName;
|
||||
org.apache.hadoop.hbase.client.Admin;
|
||||
org.apache.hadoop.hbase.client.HConnectionManager;
|
||||
org.apache.hadoop.hbase.HRegionInfo;
|
||||
org.apache.hadoop.hbase.master.RegionState;
|
||||
org.apache.hadoop.hbase.HTableDescriptor;
|
||||
org.apache.hadoop.hbase.HBaseConfiguration;
|
||||
org.apache.hadoop.hbase.TableName;
|
||||
|
@ -363,17 +365,42 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
|
|||
<th title="Fragmentation - Will be 0% after a major compaction and fluctuate during normal usage.">Frag.</th>
|
||||
</%if>
|
||||
<th>Online Regions</th>
|
||||
<th>Offline Regions</th>
|
||||
<th>Failed Regions</th>
|
||||
<th>Split Regions</th>
|
||||
<th>Other Regions</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<%for HTableDescriptor htDesc : tables%>
|
||||
<%java>
|
||||
Map<RegionState.State, List<HRegionInfo>> tableRegions =
|
||||
master.getAssignmentManager().getRegionStates()
|
||||
.getRegionByStateOfTable(htDesc.getTableName());
|
||||
int openRegionsCount = tableRegions.get(RegionState.State.OPEN).size();
|
||||
int offlineRegionsCount = tableRegions.get(RegionState.State.OFFLINE).size();
|
||||
int splitRegionsCount = tableRegions.get(RegionState.State.SPLIT).size();
|
||||
int failedRegionsCount = tableRegions.get(RegionState.State.FAILED_OPEN).size()
|
||||
+ tableRegions.get(RegionState.State.FAILED_CLOSE).size();
|
||||
int otherRegionsCount = 0;
|
||||
for (List<HRegionInfo> list: tableRegions.values()) {
|
||||
otherRegionsCount += list.size();
|
||||
}
|
||||
// now subtract known states
|
||||
otherRegionsCount = otherRegionsCount - openRegionsCount
|
||||
- failedRegionsCount - offlineRegionsCount
|
||||
- splitRegionsCount;
|
||||
</%java>
|
||||
<tr>
|
||||
<td><% htDesc.getTableName().getNamespaceAsString() %></td>
|
||||
<td><a href=table.jsp?name=<% htDesc.getTableName().getNameAsString() %>><% htDesc.getTableName().getQualifierAsString() %></a> </td>
|
||||
<%if (frags != null) %>
|
||||
<td align="center"><% frags.get(htDesc.getTableName().getNameAsString()) != null ? frags.get(htDesc.getTableName().getQualifierAsString()).intValue() + "%" : "n/a" %></td>
|
||||
</%if>
|
||||
<td><% master.getAssignmentManager().getRegionStates().getRegionsOfTable(htDesc
|
||||
.getTableName()).size() %>
|
||||
<td><% openRegionsCount %></td>
|
||||
<td><% offlineRegionsCount %></td>
|
||||
<td><% failedRegionsCount %></td>
|
||||
<td><% splitRegionsCount %></td>
|
||||
<td><% otherRegionsCount %></td>
|
||||
<td><% htDesc.toStringCustomizedValues() %></td>
|
||||
</tr>
|
||||
</%for>
|
||||
|
|
|
@ -80,6 +80,12 @@ public class RegionStates {
|
|||
private final Map<String, RegionState> regionStates =
|
||||
new HashMap<String, RegionState>();
|
||||
|
||||
/**
|
||||
* Holds mapping of table -> region state
|
||||
*/
|
||||
private final Map<TableName, Map<String, RegionState>> regionStatesTableIndex =
|
||||
new HashMap<TableName, Map<String, RegionState>>();
|
||||
|
||||
/**
|
||||
* Server to regions assignment map.
|
||||
* Contains the set of regions currently assigned to a given server.
|
||||
|
@ -334,7 +340,7 @@ public class RegionStates {
|
|||
+ "used existing: " + regionState + ", ignored new: " + newState);
|
||||
} else {
|
||||
regionState = new RegionState(hri, newState, serverName);
|
||||
regionStates.put(encodedName, regionState);
|
||||
putRegionState(regionState);
|
||||
if (newState == State.OPEN) {
|
||||
if (!serverName.equals(lastHost)) {
|
||||
LOG.warn("Open region's last host " + lastHost
|
||||
|
@ -357,6 +363,20 @@ public class RegionStates {
|
|||
return regionState;
|
||||
}
|
||||
|
||||
private RegionState putRegionState(RegionState regionState) {
|
||||
HRegionInfo hri = regionState.getRegion();
|
||||
String encodedName = hri.getEncodedName();
|
||||
TableName table = hri.getTable();
|
||||
RegionState oldState = regionStates.put(encodedName, regionState);
|
||||
Map<String, RegionState> map = regionStatesTableIndex.get(table);
|
||||
if (map == null) {
|
||||
map = new HashMap<String, RegionState>();
|
||||
regionStatesTableIndex.put(table, map);
|
||||
}
|
||||
map.put(encodedName, regionState);
|
||||
return oldState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a region state. It will be put in transition if not already there.
|
||||
*/
|
||||
|
@ -682,6 +702,30 @@ public class RegionStates {
|
|||
return tableRegions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets current state of all regions of the table.
|
||||
* This method looks at the in-memory state. It does not go to <code>hbase:meta</code>.
|
||||
* Method guaranteed to return keys for all states
|
||||
* in {@link org.apache.hadoop.hbase.master.RegionState.State}
|
||||
*
|
||||
* @param tableName
|
||||
* @return Online regions from <code>tableName</code>
|
||||
*/
|
||||
public synchronized Map<RegionState.State, List<HRegionInfo>>
|
||||
getRegionByStateOfTable(TableName tableName) {
|
||||
Map<RegionState.State, List<HRegionInfo>> tableRegions =
|
||||
new HashMap<State, List<HRegionInfo>>();
|
||||
for (State state : State.values()) {
|
||||
tableRegions.put(state, new ArrayList<HRegionInfo>());
|
||||
}
|
||||
Map<String, RegionState> indexMap = regionStatesTableIndex.get(tableName);
|
||||
if (indexMap == null)
|
||||
return tableRegions;
|
||||
for (RegionState regionState : indexMap.values()) {
|
||||
tableRegions.get(regionState.getState()).add(regionState.getRegion());
|
||||
}
|
||||
return tableRegions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait on region to clear regions-in-transition.
|
||||
|
@ -741,6 +785,11 @@ public class RegionStates {
|
|||
String encodedName = hri.getEncodedName();
|
||||
regionsInTransition.remove(encodedName);
|
||||
regionStates.remove(encodedName);
|
||||
TableName table = hri.getTable();
|
||||
Map<String, RegionState> indexMap = regionStatesTableIndex.get(table);
|
||||
indexMap.remove(encodedName);
|
||||
if (indexMap.size() == 0)
|
||||
regionStatesTableIndex.remove(table);
|
||||
lastAssignments.remove(encodedName);
|
||||
ServerName sn = regionAssignments.remove(hri);
|
||||
if (sn != null) {
|
||||
|
@ -1047,7 +1096,7 @@ public class RegionStates {
|
|||
|
||||
synchronized (this) {
|
||||
regionsInTransition.put(encodedName, regionState);
|
||||
regionStates.put(encodedName, regionState);
|
||||
putRegionState(regionState);
|
||||
|
||||
// For these states, region should be properly closed.
|
||||
// There should be no log splitting issue.
|
||||
|
|
|
@ -361,9 +361,9 @@ public class TestAssignmentManagerOnCluster {
|
|||
|
||||
long timeoutTime = System.currentTimeMillis() + 800;
|
||||
while (true) {
|
||||
List<HRegionInfo> regions =
|
||||
regionStates.getRegionsOfTable(table);
|
||||
if (!regions.contains(hri)) break;
|
||||
if (regionStates.getRegionByStateOfTable(table)
|
||||
.get(RegionState.State.OFFLINE).contains(hri))
|
||||
break;
|
||||
long now = System.currentTimeMillis();
|
||||
if (now > timeoutTime) {
|
||||
fail("Failed to offline the region in time");
|
||||
|
|
Loading…
Reference in New Issue