Skip to content

Commit

Permalink
HBASE-25461 when the cluster has many tables, UI can be opened quickly
Browse files Browse the repository at this point in the history
  • Loading branch information
cuibo01 committed Jan 6, 2021
1 parent 600be60 commit 88ae68b
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ public boolean isReadyToOffline() {
|| isSplittingNew() || isMergingNew();
}

public boolean isSplitOrMerge() {
return isMerged() || isMergingNew() || isMerging()
|| isSplit() || isSplittingNew() || isSplitting();
}

/**
* Check if a region state can transition to online
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ org.apache.hadoop.hbase.zookeeper.MasterAddressTracker;
<%java return; %>
</%if>
<%java>
ServerInfo serverInfo = ProtobufUtil.getServerInfo(null, regionServer.getRSRpcServices());
ServerName serverName = ProtobufUtil.toServerName(serverInfo.getServerName());
List<RegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(regionServer.getRSRpcServices());
ServerName serverName = regionServer.getServerName();
List<RegionInfo> onlineRegions = regionServer.getOnlineRegionInfos();
MasterAddressTracker masterAddressTracker = regionServer.getMasterAddressTracker();
ServerName masterServerName = masterAddressTracker == null ? null
: masterAddressTracker.getMasterAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
Expand Down Expand Up @@ -543,10 +544,11 @@ public Map<RegionState.State, List<RegionInfo>> getRegionByStateOfTable(TableNam
tableRegions.put(states[i], new ArrayList<RegionInfo>());
}

for (RegionStateNode node: regionsMap.values()) {
if (node.getTable().equals(tableName)) {
tableRegions.get(node.getState()).add(node.getRegionInfo());
for (RegionStateNode node: regionsMap.tailMap(tableName.getName()).values()) {
if (!node.getTable().equals(tableName)) {
break;
}
tableRegions.get(node.getState()).add(node.getRegionInfo());
}
return tableRegions;
}
Expand Down Expand Up @@ -804,4 +806,21 @@ public static String regionNamesToString(final Collection<byte[]> regions) {
sb.append("]");
return sb.toString();
}

/**
* WEB UI
*/
public synchronized Map<RegionInfo, ServerName> getRegionLocations(TableName tableName) {
Map<RegionInfo, ServerName> tableRegions = new TreeMap<>();
for (RegionStateNode regionStateNode : regionsMap.tailMap(tableName.getName()).values()) {
if (!regionStateNode.getTable().equals(tableName)) {
break;
}
if (regionStateNode.toRegionState().isSplitOrMerge()) {
continue;
}
tableRegions.put(regionStateNode.getRegionInfo(), regionStateNode.getRegionLocation());
}
return tableRegions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2949,6 +2949,18 @@ protected Map<String, HRegion> getOnlineRegions() {
return this.onlineRegions;
}

/**
* WEB UI
*/
public List<RegionInfo> getOnlineRegionInfos() {
List<RegionInfo> allRegionInfos = new ArrayList<>();
synchronized (this.onlineRegions) {
allRegionInfos = onlineRegions.values().stream().map(HRegion::getRegionInfo)
.collect(Collectors.toList());
}
return allRegionInfos;
}

public int getNumberOfOnlineRegions() {
return this.onlineRegions.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,7 @@
</div>

<% if (rsGroupTables != null && rsGroupTables.size() > 0) {
List<TableDescriptor> tables;
try (Admin admin = master.getConnection().getAdmin()) {
tables = master.isInitialized() ? admin.listTableDescriptors(true) : null;
}
List<TableDescriptor> tables = master.isInitialized() ? master.listTableDescriptors(null, null, null, true) : new ArrayList<>();
Map<TableName, TableDescriptor> tableDescriptors = tables.stream().collect(
Collectors.toMap(TableDescriptor::getTableName, Function.identity()));
%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import="java.util.Date"
import="org.apache.hadoop.conf.Configuration"
import="org.apache.hadoop.hbase.client.Admin"
import="org.apache.hadoop.hbase.client.SnapshotDescription"
import="org.apache.hadoop.hbase.http.InfoServer"
import="org.apache.hadoop.hbase.master.HMaster"
import="org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription"
import="org.apache.hadoop.hbase.snapshot.SnapshotInfo"
import="org.apache.hadoop.util.StringUtils"
import="org.apache.hadoop.hbase.TableName"
Expand All @@ -40,11 +40,11 @@
long snapshotTtl = 0;
if(snapshotName != null && master.isInitialized()) {
try (Admin admin = master.getConnection().getAdmin()) {
for (SnapshotDescription snapshotDesc: admin.listSnapshots()) {
for (SnapshotDescription snapshotDesc: master.getSnapshotManager().getCompletedSnapshots()) {
if (snapshotName.equals(snapshotDesc.getName())) {
snapshot = snapshotDesc;
stats = SnapshotInfo.getSnapshotStats(conf, snapshot);
snapshotTable = snapshot.getTableName();
stats = SnapshotInfo.getSnapshotStats(conf, snapshot, null);
snapshotTable = TableName.valueOf(snapshot.getTable());
snapshotTtl = snapshot.getTtl();
tableExists = admin.tableExists(snapshotTable);
break;
Expand Down
22 changes: 10 additions & 12 deletions hbase-server/src/main/resources/hbase-webapps/master/table.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@
stateMap.put(regionInfo.getEncodedName(), regionState);
}
}
RegionLocator r = master.getConnection().getRegionLocator(table.getName());
try {
%>
Expand Down Expand Up @@ -820,12 +819,11 @@
String totalLocalityForSsd = "";
Map<ServerName, Integer> regDistribution = new TreeMap<>();
Map<ServerName, Integer> primaryRegDistribution = new TreeMap<>();
List<HRegionLocation> regions = r.getAllRegionLocations();
Map<RegionInfo, RegionMetrics> regionsToLoad = new LinkedHashMap<>();
Map<RegionInfo, ServerName> regionsToServer = new LinkedHashMap<>();
for (HRegionLocation hriEntry : regions) {
RegionInfo regionInfo = hriEntry.getRegion();
ServerName addr = hriEntry.getServerName();
Map<RegionInfo, ServerName> regionsToServer = master.getAssignmentManager().getRegionStates().getRegionLocations(table.getName());
for (Map.Entry<RegionInfo, ServerName> hriEntry : regionsToServer.entrySet()) {
RegionInfo regionInfo = hriEntry.getKey();
ServerName addr = hriEntry.getValue();
regionsToServer.put(regionInfo, addr);
if (addr != null) {
Expand Down Expand Up @@ -874,7 +872,7 @@
totalLocalityForSsd = String.format("%.1f",
((float) totalBlocksLocalWithSsdWeight / totalBlocksTotalWeight));
}
if(regions != null && regions.size() > 0) { %>
if(regionsToServer != null && regionsToServer.size() > 0) { %>
<h2>Table Regions</h2>
<div class="tabbable">
<ul class="nav nav-pills">
Expand All @@ -887,7 +885,7 @@
<table id="tableBaseStatsTable" class="tablesorter table table-striped">
<thead>
<tr>
<th>Name(<%= String.format("%,1d", regions.size())%>)</th>
<th>Name(<%= String.format("%,1d", regionsToServer.size())%>)</th>
<th>Region Server</th>
<th>ReadRequests<br>(<%= String.format("%,1d", totalReadReq)%>)</th>
<th>WriteRequests<br>(<%= String.format("%,1d", totalWriteReq)%>)</th>
Expand All @@ -903,9 +901,9 @@
<tbody>
<%
List<Map.Entry<RegionInfo, RegionMetrics>> entryList = new ArrayList<>(regionsToLoad.entrySet());
numRegions = regions.size();
numRegions = regionsToServer.size();
int numRegionsRendered = 0;
// render all regions
// render all regionsToServer
if (numRegionsToRender < 0) {
numRegionsToRender = numRegions;
}
Expand Down Expand Up @@ -976,7 +974,7 @@
<table id="tableLocalityStatsTable" class="tablesorter table table-striped">
<thead>
<tr>
<th>Name(<%= String.format("%,1d", regions.size())%>)</th>
<th>Name(<%= String.format("%,1d", regionsToServer.size())%>)</th>
<th>Region Server</th>
<th>Locality<br>(<%= totalLocality %>)</th>
<th>LocalityForSsd<br>(<%= totalLocalityForSsd %>)</th>
Expand Down Expand Up @@ -1016,7 +1014,7 @@
<table id="tableCompactStatsTable" class="tablesorter table table-striped">
<thead>
<tr>
<th>Name(<%= String.format("%,1d", regions.size())%>)</th>
<th>Name(<%= String.format("%,1d", regionsToServer.size())%>)</th>
<th>Region Server</th>
<th>Num. Compacting Cells<br>(<%= String.format("%,1d", totalCompactingCells)%>)</th>
<th>Num. Compacted Cells<br>(<%= String.format("%,1d", totalCompactedCells)%>)</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void setupBasicMocks() throws IOException, ServiceException {
MetricsRegionServer rms = Mockito.mock(MetricsRegionServer.class);
Mockito.doReturn(new MetricsRegionServerWrapperStub()).when(rms).getRegionServerWrapper();
Mockito.doReturn(rms).when(rs).getMetrics();
Mockito.doReturn(fakeServerName).when(rs).getServerName();

MetricsHBaseServer ms = Mockito.mock(MetricsHBaseServer.class);
Mockito.doReturn(new MetricsHBaseServerWrapperStub()).when(ms).getHBaseServerWrapper();
Expand Down

0 comments on commit 88ae68b

Please sign in to comment.