HBASE-4360 Maintain information on the time a RS went dead (samar)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1498274 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
nkeywal 2013-07-01 07:42:05 +00:00
parent fc471152da
commit ed97685c75
4 changed files with 27 additions and 1 deletions

View File

@ -46,6 +46,7 @@ org.apache.hadoop.hbase.client.HConnectionManager;
org.apache.hadoop.hbase.HTableDescriptor;
org.apache.hadoop.hbase.HBaseConfiguration;
org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
org.apache.hadoop.hbase.master.DeadServer;
</%import>
<%if format.equals("json") %>
<& ../common/TaskMonitorTmpl; filter = filter; format = "json" &>
@ -346,17 +347,21 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
<h2>Dead Region Servers</h2>
<table class="table table-striped">
<tr>
<th rowspan="<% deadServers.size() + 1%>"></th>
<th></th>
<th>ServerName</th>
<th>Stop time</th>
</tr>
<%java>
DeadServer deadServerUtil = master.getServerManager().getDeadServers();
ServerName [] deadServerNames = deadServers.toArray(new ServerName[deadServers.size()]);
Arrays.sort(deadServerNames);
for (ServerName deadServerName: deadServerNames) {
int infoPort = master.getConfiguration().getInt("hbase.regionserver.info.port", 60030);
</%java>
<tr>
<th rowspan="<% deadServers.size() %>"></th>
<td><% deadServerName %></td>
<td><% deadServerUtil.getTimeOfDeath(deadServerName) %></td>
</tr>
<%java>
}
@ -364,6 +369,7 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
<tr>
<th>Total: </th>
<td>servers: <% deadServers.size() %></td>
<th></th>
</tr>
</table>
</%if>

View File

@ -26,6 +26,7 @@ import org.apache.hadoop.hbase.util.Pair;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -160,6 +161,16 @@ public class DeadServer {
Collections.sort(res, ServerNameDeathDateComparator);
return res;
}
/**
* Get the time when a server died
* @param deadServerName the dead server name
* @return the date when the server died
*/
public synchronized Date getTimeOfDeath(final ServerName deadServerName){
Long time = deadServers.get(deadServerName);
return time == null ? null : new Date(time);
}
private static Comparator<Pair<ServerName, Long>> ServerNameDeathDateComparator =
new Comparator<Pair<ServerName, Long>>(){

View File

@ -27,6 +27,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -62,6 +63,10 @@ public class TestDeadServer {
assertFalse(ds.cleanPreviousInstance(deadServer));
ds.add(deadServer);
assertTrue(ds.isDeadServer(deadServer));
Set<ServerName> deadServerNames = ds.copyServerNames();
for (ServerName eachDeadServer : deadServerNames) {
Assert.assertNotNull(ds.getTimeOfDeath(eachDeadServer));
}
final ServerName deadServerHostComingAlive =
new ServerName("127.0.0.1", 9090, 223341L);
assertTrue(ds.cleanPreviousInstance(deadServerHostComingAlive));

View File

@ -70,10 +70,13 @@ public class TestMasterStatusServlet {
Mockito.doReturn(FAKE_HOST).when(master).getServerName();
Mockito.doReturn(conf).when(master).getConfiguration();
//Fake DeadServer
DeadServer deadServer = Mockito.mock(DeadServer.class);
// Fake serverManager
ServerManager serverManager = Mockito.mock(ServerManager.class);
Mockito.doReturn(1.0).when(serverManager).getAverageLoad();
Mockito.doReturn(serverManager).when(master).getServerManager();
Mockito.doReturn(deadServer).when(serverManager).getDeadServers();
// Fake AssignmentManager and RIT
AssignmentManager am = Mockito.mock(AssignmentManager.class);
@ -85,6 +88,7 @@ public class TestMasterStatusServlet {
Mockito.doReturn(rs).when(am).getRegionStates();
Mockito.doReturn(regionsInTransition).when(rs).getRegionsInTransition();
Mockito.doReturn(am).when(master).getAssignmentManager();
Mockito.doReturn(serverManager).when(master).getServerManager();
// Fake ZKW
ZooKeeperWatcher zkw = Mockito.mock(ZooKeeperWatcher.class);