HBASE-10739 RS web UI NPE if master shuts down sooner

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1577415 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jxiang 2014-03-14 03:02:21 +00:00
parent 1160171e64
commit 6b2437de2c
10 changed files with 38 additions and 35 deletions

View File

@ -32,7 +32,7 @@ if (master.isActiveMaster()) {
ClusterStatus status = master.getClusterStatus();
masters = status.getBackupMasters();
} else{
ServerName sn = master.getMasterAddressManager().getMasterAddress();
ServerName sn = master.getMasterAddressTracker().getMasterAddress();
assert sn != null : "Failed to retreive master's ServerName!";
masters = Collections.singletonList(sn);
}

View File

@ -24,13 +24,12 @@ String format = "html";
<%import>
java.util.*;
org.apache.hadoop.hbase.regionserver.HRegionServer;
org.apache.hadoop.hbase.util.Bytes;
org.apache.hadoop.hbase.HRegionInfo;
org.apache.hadoop.hbase.ServerName;
org.apache.hadoop.hbase.HBaseConfiguration;
org.apache.hadoop.hbase.protobuf.ProtobufUtil;
org.apache.hadoop.hbase.protobuf.generated.AdminProtos.ServerInfo;
org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.RegionLoad;
org.apache.hadoop.hbase.zookeeper.MasterAddressTracker;
</%import>
<%if format.equals("json") %>
<& ../common/TaskMonitorTmpl; filter = filter; format = "json" &>
@ -41,6 +40,9 @@ org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.RegionLoad;
ServerName serverName = ProtobufUtil.toServerName(serverInfo.getServerName());
List<HRegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(regionServer);
int masterInfoPort = regionServer.getConfiguration().getInt("hbase.master.info.port", 16010);
MasterAddressTracker masterAddressTracker = regionServer.getMasterAddressTracker();
ServerName masterServerName = masterAddressTracker == null ? null
: masterAddressTracker.getMasterAddress();
</%java>
<!--[if IE]>
<!DOCTYPE html>
@ -146,9 +148,11 @@ org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.RegionLoad;
<td>
<%if (masterInfoPort < 0) %>
No hbase.master.info.port found
<%elseif masterServerName == null %>
No master found
<%else>
<%java>
String host = regionServer.getMasterAddressManager().getMasterAddress().getHostname() + ":" + masterInfoPort;
String host = masterServerName.getHostname() + ":" + masterInfoPort;
String url = "//" + host + "/";
</%java>
<a href="<% url %>"><% host %></a>

View File

@ -294,8 +294,8 @@ MasterServices, Server {
private DrainingServerTracker drainingServerTracker;
// Tracker for load balancer state
private LoadBalancerTracker loadBalancerTracker;
// master address manager and watcher
private MasterAddressTracker masterAddressManager;
// master address tracker
private MasterAddressTracker masterAddressTracker;
// RPC server for the HMaster
private final RpcServerInterface rpcServer;
@ -586,8 +586,8 @@ MasterServices, Server {
startupStatus.setDescription("Master startup");
masterStartTime = System.currentTimeMillis();
try {
this.masterAddressManager = new MasterAddressTracker(getZooKeeperWatcher(), this);
this.masterAddressManager.start();
this.masterAddressTracker = new MasterAddressTracker(getZooKeeperWatcher(), this);
this.masterAddressTracker.start();
// Put up info server.
int port = this.conf.getInt("hbase.master.info.port", HConstants.DEFAULT_MASTER_INFOPORT);
@ -1164,8 +1164,8 @@ MasterServices, Server {
return this.activeMasterManager;
}
public MasterAddressTracker getMasterAddressManager() {
return this.masterAddressManager;
public MasterAddressTracker getMasterAddressTracker() {
return this.masterAddressTracker;
}
/*

View File

@ -429,8 +429,8 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa
// zookeeper connection and watcher
private ZooKeeperWatcher zooKeeper;
// master address manager and watcher
private MasterAddressTracker masterAddressManager;
// master address tracker
private MasterAddressTracker masterAddressTracker;
// Cluster Status Tracker
private ClusterStatusTracker clusterStatusTracker;
@ -723,12 +723,12 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa
this.zooKeeper = new ZooKeeperWatcher(conf, REGIONSERVER + ":" +
this.isa.getPort(), this);
// Create the master address manager, register with zk, and start it. Then
// Create the master address tracker, register with zk, and start it. Then
// block until a master is available. No point in starting up if no master
// running.
this.masterAddressManager = new MasterAddressTracker(this.zooKeeper, this);
this.masterAddressManager.start();
blockAndCheckIfStopped(this.masterAddressManager);
this.masterAddressTracker = new MasterAddressTracker(this.zooKeeper, this);
this.masterAddressTracker.start();
blockAndCheckIfStopped(this.masterAddressTracker);
// Wait on cluster being up. Master will set this flag up in zookeeper
// when ready.
@ -1588,8 +1588,8 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa
/**
* @return Master address tracker instance.
*/
public MasterAddressTracker getMasterAddressManager() {
return this.masterAddressManager;
public MasterAddressTracker getMasterAddressTracker() {
return this.masterAddressTracker;
}
/*
@ -1960,7 +1960,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa
boolean interrupted = false;
try {
while (keepLooping() && master == null) {
sn = this.masterAddressManager.getMasterAddress(refresh);
sn = this.masterAddressTracker.getMasterAddress(refresh);
if (sn == null) {
if (!keepLooping()) {
// give up with no connection.

View File

@ -53,7 +53,6 @@ public class RSStatusServlet extends HttpServlet {
tmpl.setFormat(req.getParameter("format"));
if (req.getParameter("filter") != null)
tmpl.setFilter(req.getParameter("filter"));
if (hrs != null) tmpl.render(resp.getWriter(), hrs);
tmpl.render(resp.getWriter(), hrs);
}
}

View File

@ -388,7 +388,7 @@ public class TestZooKeeper {
// Assumes the root of the ZooKeeper space is writable as it creates a node
// wherever the cluster home is defined.
ZooKeeperWatcher zk2 = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
"testMasterAddressManagerFromZK", null);
"testCreateSilentIsReallySilent", null);
// Save the previous ACL
Stat s = null;

View File

@ -98,7 +98,7 @@ public class TestMasterStatusServlet {
// Fake MasterAddressTracker
MasterAddressTracker tracker = Mockito.mock(MasterAddressTracker.class);
Mockito.doReturn(tracker).when(master).getMasterAddressManager();
Mockito.doReturn(tracker).when(master).getMasterAddressTracker();
Mockito.doReturn(FAKE_HOST).when(tracker).getMasterAddress();
// Mock admin

View File

@ -58,7 +58,7 @@ import org.apache.hadoop.hbase.Stoppable;
import org.apache.hadoop.hbase.Waiter;
import org.apache.hadoop.hbase.master.SplitLogManager.Task;
import org.apache.hadoop.hbase.master.SplitLogManager.TaskBatch;
import org.apache.hadoop.hbase.regionserver.TestMasterAddressManager.NodeCreationListener;
import org.apache.hadoop.hbase.regionserver.TestMasterAddressTracker.NodeCreationListener;
import org.apache.hadoop.hbase.zookeeper.ZKSplitLog;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;

View File

@ -36,8 +36,8 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
@Category(MediumTests.class)
public class TestMasterAddressManager {
private static final Log LOG = LogFactory.getLog(TestMasterAddressManager.class);
public class TestMasterAddressTracker {
private static final Log LOG = LogFactory.getLog(TestMasterAddressTracker.class);
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@ -56,17 +56,17 @@ public class TestMasterAddressManager {
* @throws Exception
*/
@Test
public void testMasterAddressManagerFromZK() throws Exception {
public void testMasterAddressTrackerFromZK() throws Exception {
ZooKeeperWatcher zk = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
"testMasterAddressManagerFromZK", null);
"testMasterAddressTrackerFromZK", null);
ZKUtil.createAndFailSilent(zk, zk.baseZNode);
// Should not have a master yet
MasterAddressTracker addressManager = new MasterAddressTracker(zk, null);
addressManager.start();
assertFalse(addressManager.hasMaster());
zk.registerListener(addressManager);
MasterAddressTracker addressTracker = new MasterAddressTracker(zk, null);
addressTracker.start();
assertFalse(addressTracker.hasMaster());
zk.registerListener(addressTracker);
// Use a listener to capture when the node is actually created
NodeCreationListener listener = new NodeCreationListener(zk, zk.getMasterAddressZNode());
@ -83,8 +83,8 @@ public class TestMasterAddressManager {
LOG.info("Waiting for master address manager to be notified");
listener.waitForCreation();
LOG.info("Master node created");
assertTrue(addressManager.hasMaster());
ServerName pulledAddress = addressManager.getMasterAddress();
assertTrue(addressTracker.hasMaster());
ServerName pulledAddress = addressTracker.getMasterAddress();
assertTrue(pulledAddress.equals(sn));
}

View File

@ -78,7 +78,7 @@ public class TestRSStatusServlet {
// Fake MasterAddressTracker
MasterAddressTracker mat = Mockito.mock(MasterAddressTracker.class);
Mockito.doReturn(fakeMasterAddress).when(mat).getMasterAddress();
Mockito.doReturn(mat).when(rs).getMasterAddressManager();
Mockito.doReturn(mat).when(rs).getMasterAddressTracker();
MetricsRegionServer rms = Mockito.mock(MetricsRegionServer.class);
Mockito.doReturn(new MetricsRegionServerWrapperStub()).when(rms).getRegionServerWrapper();