hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jxi...@apache.org
Subject svn commit: r1577415 - in /hbase/trunk/hbase-server/src: main/jamon/org/apache/hadoop/hbase/tmpl/master/ main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/ main/java/org/apache/hadoop/hbase/master/ main/java/org/apache/hadoop/hbase/regionserver/ tes...
Date Fri, 14 Mar 2014 03:02:21 GMT
Author: jxiang
Date: Fri Mar 14 03:02:21 2014
New Revision: 1577415

URL: http://svn.apache.org/r1577415
Log:
HBASE-10739 RS web UI NPE if master shuts down sooner

Added:
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterAddressTracker.java
  (with props)
Removed:
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterAddressManager.java
Modified:
    hbase/trunk/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/BackupMasterStatusTmpl.jamon
    hbase/trunk/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/RSStatusTmpl.jamon
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSStatusServlet.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterStatusServlet.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitLogManager.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSStatusServlet.java

Modified: hbase/trunk/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/BackupMasterStatusTmpl.jamon
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/BackupMasterStatusTmpl.jamon?rev=1577415&r1=1577414&r2=1577415&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/BackupMasterStatusTmpl.jamon
(original)
+++ hbase/trunk/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/BackupMasterStatusTmpl.jamon
Fri Mar 14 03:02:21 2014
@@ -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);
 }

Modified: hbase/trunk/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/RSStatusTmpl.jamon
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/RSStatusTmpl.jamon?rev=1577415&r1=1577414&r2=1577415&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/RSStatusTmpl.jamon
(original)
+++ hbase/trunk/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/RSStatusTmpl.jamon
Fri Mar 14 03:02:21 2014
@@ -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.generat
   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.generat
             <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>

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1577415&r1=1577414&r2=1577415&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Fri
Mar 14 03:02:21 2014
@@ -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;
   }
 
   /*

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1577415&r1=1577414&r2=1577415&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Fri Mar 14 03:02:21 2014
@@ -429,8 +429,8 @@ public class HRegionServer implements Cl
   // 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 Cl
     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 Cl
   /**
    * @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 Cl
     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.

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSStatusServlet.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSStatusServlet.java?rev=1577415&r1=1577414&r2=1577415&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSStatusServlet.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSStatusServlet.java
Fri Mar 14 03:02:21 2014
@@ -53,7 +53,6 @@ public class RSStatusServlet extends Htt
       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);
   }
-
 }

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java?rev=1577415&r1=1577414&r2=1577415&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java Fri
Mar 14 03:02:21 2014
@@ -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;

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterStatusServlet.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterStatusServlet.java?rev=1577415&r1=1577414&r2=1577415&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterStatusServlet.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterStatusServlet.java
Fri Mar 14 03:02:21 2014
@@ -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

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitLogManager.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitLogManager.java?rev=1577415&r1=1577414&r2=1577415&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitLogManager.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitLogManager.java
Fri Mar 14 03:02:21 2014
@@ -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;

Added: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterAddressTracker.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterAddressTracker.java?rev=1577415&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterAddressTracker.java
(added)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterAddressTracker.java
Fri Mar 14 03:02:21 2014
@@ -0,0 +1,118 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.regionserver;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.Semaphore;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.*;
+import org.apache.hadoop.hbase.zookeeper.MasterAddressTracker;
+import org.apache.hadoop.hbase.zookeeper.ZKUtil;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperListener;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(MediumTests.class)
+public class TestMasterAddressTracker {
+  private static final Log LOG = LogFactory.getLog(TestMasterAddressTracker.class);
+
+  private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+    TEST_UTIL.startMiniZKCluster();
+  }
+
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception {
+    TEST_UTIL.shutdownMiniZKCluster();
+  }
+  /**
+   * Unit tests that uses ZooKeeper but does not use the master-side methods
+   * but rather acts directly on ZK.
+   * @throws Exception
+   */
+  @Test
+  public void testMasterAddressTrackerFromZK() throws Exception {
+
+    ZooKeeperWatcher zk = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
+        "testMasterAddressTrackerFromZK", null);
+    ZKUtil.createAndFailSilent(zk, zk.baseZNode);
+
+    // Should not have a master yet
+    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());
+    zk.registerListener(listener);
+
+    // Create the master node with a dummy address
+    String host = "localhost";
+    int port = 1234;
+    ServerName sn = ServerName.valueOf(host, port, System.currentTimeMillis());
+    LOG.info("Creating master node");
+    MasterAddressTracker.setMasterAddress(zk, zk.getMasterAddressZNode(), sn);
+
+    // Wait for the node to be created
+    LOG.info("Waiting for master address manager to be notified");
+    listener.waitForCreation();
+    LOG.info("Master node created");
+    assertTrue(addressTracker.hasMaster());
+    ServerName pulledAddress = addressTracker.getMasterAddress();
+    assertTrue(pulledAddress.equals(sn));
+
+  }
+
+  public static class NodeCreationListener extends ZooKeeperListener {
+    private static final Log LOG = LogFactory.getLog(NodeCreationListener.class);
+
+    private Semaphore lock;
+    private String node;
+
+    public NodeCreationListener(ZooKeeperWatcher watcher, String node) {
+      super(watcher);
+      lock = new Semaphore(0);
+      this.node = node;
+    }
+
+    @Override
+    public void nodeCreated(String path) {
+      if(path.equals(node)) {
+        LOG.debug("nodeCreated(" + path + ")");
+        lock.release();
+      }
+    }
+
+    public void waitForCreation() throws InterruptedException {
+      lock.acquire();
+    }
+  }
+
+}
+

Propchange: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterAddressTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSStatusServlet.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSStatusServlet.java?rev=1577415&r1=1577414&r2=1577415&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSStatusServlet.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSStatusServlet.java
Fri Mar 14 03:02:21 2014
@@ -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();



Mime
View raw message