HBASE-12863 Master info port on RS UI is always 0
Signed-off-by: Enis Soztutar <enis@apache.org>
This commit is contained in:
parent
f1d1dbfaa4
commit
7309bb4317
|
@ -56,7 +56,7 @@ public class ActiveMasterManager extends ZooKeeperListener {
|
|||
final AtomicBoolean clusterShutDown = new AtomicBoolean(false);
|
||||
|
||||
private final ServerName sn;
|
||||
private final int infoPort;
|
||||
private int infoPort;
|
||||
private final Server master;
|
||||
|
||||
/**
|
||||
|
@ -64,14 +64,18 @@ public class ActiveMasterManager extends ZooKeeperListener {
|
|||
* @param sn ServerName
|
||||
* @param master In an instance of a Master.
|
||||
*/
|
||||
ActiveMasterManager(ZooKeeperWatcher watcher, ServerName sn, int infoPort, Server master) {
|
||||
ActiveMasterManager(ZooKeeperWatcher watcher, ServerName sn, Server master) {
|
||||
super(watcher);
|
||||
watcher.registerListener(this);
|
||||
this.sn = sn;
|
||||
this.infoPort = infoPort;
|
||||
this.master = master;
|
||||
}
|
||||
|
||||
// will be set after jetty server is started
|
||||
public void setInfoPort(int infoPort) {
|
||||
this.infoPort = infoPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nodeCreated(String path) {
|
||||
handle(path);
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.hadoop.hbase.master;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
|
@ -222,7 +221,7 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
|
|||
public static final String MASTER = "master";
|
||||
|
||||
// Manager and zk listener for master election
|
||||
private ActiveMasterManager activeMasterManager;
|
||||
private final ActiveMasterManager activeMasterManager;
|
||||
// Region server tracker
|
||||
RegionServerTracker regionServerTracker;
|
||||
// Draining region server tracker
|
||||
|
@ -303,7 +302,6 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
|
|||
/** jetty server for master to redirect requests to regionserver infoServer */
|
||||
private org.mortbay.jetty.Server masterJettyServer;
|
||||
|
||||
private int masterInfoPort;
|
||||
public static class RedirectServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 2894774810058302472L;
|
||||
private static int regionServerInfoPort;
|
||||
|
@ -380,19 +378,21 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
|
|||
Threads.setDaemonThreadRunning(clusterStatusPublisherChore.getThread());
|
||||
}
|
||||
}
|
||||
startActiveMasterManager();
|
||||
putUpJettyServer();
|
||||
activeMasterManager = new ActiveMasterManager(zooKeeper, this.serverName, this);
|
||||
int infoPort = putUpJettyServer();
|
||||
startActiveMasterManager(infoPort);
|
||||
}
|
||||
|
||||
private void putUpJettyServer() throws IOException {
|
||||
// return the actual infoPort, -1 means disable info server.
|
||||
private int putUpJettyServer() throws IOException {
|
||||
if (!conf.getBoolean("hbase.master.infoserver.redirect", true)) {
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
int infoPort = conf.getInt("hbase.master.info.port.orig",
|
||||
HConstants.DEFAULT_MASTER_INFOPORT);
|
||||
// -1 is for disabling info server, so no redirecting
|
||||
if (infoPort < 0 || infoServer == null) {
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
String addr = conf.get("hbase.master.info.bindAddress", "0.0.0.0");
|
||||
if (!Addressing.isLocalAddress(InetAddress.getByName(addr))) {
|
||||
|
@ -418,7 +418,7 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
|
|||
} catch (Exception e) {
|
||||
throw new IOException("Failed to start redirecting jetty server", e);
|
||||
}
|
||||
masterInfoPort = connector.getPort();
|
||||
return connector.getLocalPort();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1357,7 +1357,7 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
|
|||
}
|
||||
}
|
||||
|
||||
private void startActiveMasterManager() throws KeeperException {
|
||||
private void startActiveMasterManager(int infoPort) throws KeeperException {
|
||||
String backupZNode = ZKUtil.joinZNode(
|
||||
zooKeeper.backupMasterAddressesZNode, serverName.toString());
|
||||
/*
|
||||
|
@ -1372,12 +1372,11 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
|
|||
*/
|
||||
LOG.info("Adding backup master ZNode " + backupZNode);
|
||||
if (!MasterAddressTracker.setMasterAddress(zooKeeper, backupZNode,
|
||||
serverName, masterInfoPort)) {
|
||||
serverName, infoPort)) {
|
||||
LOG.warn("Failed create of " + backupZNode + " by " + serverName);
|
||||
}
|
||||
|
||||
activeMasterManager = new ActiveMasterManager(zooKeeper, this.serverName,
|
||||
masterInfoPort, this);
|
||||
activeMasterManager.setInfoPort(infoPort);
|
||||
// Start a thread to try to become the active master, so we won't block here
|
||||
Threads.setDaemonThreadRunning(new Thread(new Runnable() {
|
||||
@Override
|
||||
|
@ -2203,7 +2202,7 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
|
|||
}
|
||||
}
|
||||
|
||||
List<TableName> result = new ArrayList(descriptors.size());
|
||||
List<TableName> result = new ArrayList<TableName>(descriptors.size());
|
||||
for (HTableDescriptor htd: descriptors) {
|
||||
result.add(htd.getTableName());
|
||||
}
|
||||
|
|
|
@ -261,7 +261,7 @@ public class TestActiveMasterManager {
|
|||
clusterStatusTracker.start();
|
||||
|
||||
this.activeMasterManager =
|
||||
new ActiveMasterManager(zk, master, 0, this);
|
||||
new ActiveMasterManager(zk, master, this);
|
||||
zk.registerListener(activeMasterManager);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* 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.master;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.apache.hadoop.hbase.testclassification.MasterTests;
|
||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
/**
|
||||
* Trivial test to confirm that we do not get 0 infoPort. See HBASE-12863.
|
||||
*/
|
||||
@Category({ MasterTests.class, MediumTests.class })
|
||||
public class TestGetInfoPort {
|
||||
|
||||
private final HBaseTestingUtility testUtil = new HBaseTestingUtility();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
testUtil.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, 0);
|
||||
testUtil.startMiniCluster(1, 1);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
testUtil.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertTrue(testUtil.getMiniHBaseCluster().getRegionServer(0).getMasterAddressTracker()
|
||||
.getMasterInfoPort() > 0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue