HBASE-26215 The backup master status page should use ActiveMasterManager instead of MasterAddressTracker (#3621)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
parent
2ce2f9336f
commit
4b0a64033a
|
@ -24,25 +24,19 @@ java.util.*;
|
||||||
org.apache.hadoop.hbase.ServerName;
|
org.apache.hadoop.hbase.ServerName;
|
||||||
org.apache.hadoop.hbase.ClusterMetrics;
|
org.apache.hadoop.hbase.ClusterMetrics;
|
||||||
org.apache.hadoop.hbase.master.HMaster;
|
org.apache.hadoop.hbase.master.HMaster;
|
||||||
org.apache.hadoop.hbase.zookeeper.MasterAddressTracker;
|
|
||||||
</%import>
|
</%import>
|
||||||
<%java>
|
|
||||||
MasterAddressTracker masterAddressTracker = master.getMasterAddressTracker();
|
|
||||||
</%java>
|
|
||||||
|
|
||||||
<%if (!master.isActiveMaster()) %>
|
<%if (!master.isActiveMaster()) %>
|
||||||
<%java>
|
<%java>
|
||||||
ServerName active_master =
|
ServerName active_master = master.getActiveMaster().orElse(null);
|
||||||
(masterAddressTracker == null) ? null : masterAddressTracker.getMasterAddress();
|
assert active_master != null : "Failed to retrieve active master's ServerName!";
|
||||||
assert active_master != null : "Failed to retrieve master's ServerName!";
|
int activeInfoPort = active_master == null ? 0 : master.getActiveMasterInfoPort();
|
||||||
int infoPort = (masterAddressTracker == null) ? 0 : masterAddressTracker.getMasterInfoPort();
|
|
||||||
</%java>
|
</%java>
|
||||||
<div class="row inner_header">
|
<div class="row inner_header">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>Backup Master <small><% master.getServerName().getHostname() %></small></h1>
|
<h1>Backup Master <small><% master.getServerName().getHostname() %></small></h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h4>Current Active Master: <a href="//<% active_master.getHostname() %>:<% infoPort %>/master-status"
|
<h4>Current Active Master: <a href="//<% active_master.getHostname() %>:<% activeInfoPort %>/master-status"
|
||||||
target="_blank"><% active_master.getHostname() %></a><h4>
|
target="_blank"><% active_master.getHostname() %></a><h4>
|
||||||
<%else>
|
<%else>
|
||||||
<h2>Backup Masters</h2>
|
<h2>Backup Masters</h2>
|
||||||
|
@ -54,13 +48,11 @@ MasterAddressTracker masterAddressTracker = master.getMasterAddressTracker();
|
||||||
<th>Start Time</th>
|
<th>Start Time</th>
|
||||||
</tr>
|
</tr>
|
||||||
<%java>
|
<%java>
|
||||||
Collection<ServerName> backup_masters = master.getClusterMetricsWithoutCoprocessor(
|
Collection<ServerName> backup_masters = master.getBackupMasters();
|
||||||
EnumSet.of(ClusterMetrics.Option.BACKUP_MASTERS)).getBackupMasterNames();
|
|
||||||
ServerName [] backupServerNames = backup_masters.toArray(new ServerName[backup_masters.size()]);
|
ServerName [] backupServerNames = backup_masters.toArray(new ServerName[backup_masters.size()]);
|
||||||
Arrays.sort(backupServerNames);
|
Arrays.sort(backupServerNames);
|
||||||
for (ServerName serverName : backupServerNames) {
|
for (ServerName serverName : backupServerNames) {
|
||||||
int infoPort = (masterAddressTracker == null) ? 0 : masterAddressTracker
|
int infoPort = master.getBackupMasterInfoPort(serverName);
|
||||||
.getBackupMasterInfoPort(serverName);
|
|
||||||
</%java>
|
</%java>
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="//<% serverName.getHostname() %>:<% infoPort %>/master-status"
|
<td><a href="//<% serverName.getHostname() %>:<% infoPort %>/master-status"
|
||||||
|
|
|
@ -158,6 +158,24 @@ public class ActiveMasterManager extends ZKListener {
|
||||||
return Optional.ofNullable(activeMasterServerName);
|
return Optional.ofNullable(activeMasterServerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getActiveMasterInfoPort() {
|
||||||
|
try {
|
||||||
|
return MasterAddressTracker.getMasterInfoPort(watcher);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("Failed to get active master's info port.", e);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBackupMasterInfoPort(final ServerName sn) {
|
||||||
|
try {
|
||||||
|
return MasterAddressTracker.getBackupMasterInfoPort(watcher, sn);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("Failed to get backup master: " + sn + "'s info port.", e);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a change in the master node. Doesn't matter whether this was called
|
* Handle a change in the master node. Doesn't matter whether this was called
|
||||||
* from a nodeCreated or nodeDeleted event because there are no guarantees
|
* from a nodeCreated or nodeDeleted event because there are no guarantees
|
||||||
|
|
|
@ -2710,6 +2710,21 @@ public class HMaster extends HRegionServer implements MasterServices {
|
||||||
return activeMasterManager.getBackupMasters();
|
return activeMasterManager.getBackupMasters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return info port of active master or 0 if any exception occurs.
|
||||||
|
*/
|
||||||
|
public int getActiveMasterInfoPort() {
|
||||||
|
return activeMasterManager.getActiveMasterInfoPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param sn is ServerName of the backup master
|
||||||
|
* @return info port of backup master or 0 if any exception occurs.
|
||||||
|
*/
|
||||||
|
public int getBackupMasterInfoPort(final ServerName sn) {
|
||||||
|
return activeMasterManager.getBackupMasterInfoPort(sn);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ServerName> getRegionServers() {
|
public List<ServerName> getRegionServers() {
|
||||||
return serverManager.getOnlineServersList();
|
return serverManager.getOnlineServersList();
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||||
|
@ -116,6 +117,9 @@ public class TestMasterStatusServlet {
|
||||||
Mockito.doReturn(tracker).when(master).getMasterAddressTracker();
|
Mockito.doReturn(tracker).when(master).getMasterAddressTracker();
|
||||||
Mockito.doReturn(FAKE_HOST).when(tracker).getMasterAddress();
|
Mockito.doReturn(FAKE_HOST).when(tracker).getMasterAddress();
|
||||||
|
|
||||||
|
// Fake ActiveMaster
|
||||||
|
Mockito.doReturn(Optional.of(FAKE_HOST)).when(master).getActiveMaster();
|
||||||
|
|
||||||
MetricsRegionServer rms = Mockito.mock(MetricsRegionServer.class);
|
MetricsRegionServer rms = Mockito.mock(MetricsRegionServer.class);
|
||||||
Mockito.doReturn(new MetricsRegionServerWrapperStub()).when(rms).getRegionServerWrapper();
|
Mockito.doReturn(new MetricsRegionServerWrapperStub()).when(rms).getRegionServerWrapper();
|
||||||
Mockito.doReturn(rms).when(master).getMetrics();
|
Mockito.doReturn(rms).when(master).getMetrics();
|
||||||
|
|
|
@ -222,6 +222,43 @@ public class MasterAddressTracker extends ZKNodeTracker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get backup master info port.
|
||||||
|
* Use this instead of {@link #getBackupMasterInfoPort(ServerName)} if you do not have an
|
||||||
|
* instance of this tracker in your context.
|
||||||
|
*
|
||||||
|
* @param zkw ZKWatcher to use
|
||||||
|
* @param sn ServerName of the backup master
|
||||||
|
* @return backup master info port in the the master address znode or 0 if no
|
||||||
|
* znode present.
|
||||||
|
* @throws KeeperException if a ZooKeeper operation fails
|
||||||
|
* @throws IOException if the address of the ZooKeeper master cannot be retrieved
|
||||||
|
*/
|
||||||
|
public static int getBackupMasterInfoPort(ZKWatcher zkw, final ServerName sn)
|
||||||
|
throws KeeperException, IOException {
|
||||||
|
byte[] data;
|
||||||
|
try {
|
||||||
|
data = ZKUtil.getData(zkw,
|
||||||
|
ZNodePaths.joinZNode(zkw.getZNodePaths().backupMasterAddressesZNode, sn.toString()));
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new InterruptedIOException();
|
||||||
|
}
|
||||||
|
if (data == null) {
|
||||||
|
throw new IOException("Can't get backup master address from ZooKeeper; znode data == null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final ZooKeeperProtos.Master backup = parse(data);
|
||||||
|
if (backup == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return backup.getInfoPort();
|
||||||
|
} catch (DeserializationException e) {
|
||||||
|
KeeperException ke = new KeeperException.DataInconsistencyException();
|
||||||
|
ke.initCause(e);
|
||||||
|
throw ke;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set master address into the <code>master</code> znode or into the backup
|
* Set master address into the <code>master</code> znode or into the backup
|
||||||
* subdirectory of backup masters; switch off the passed in <code>znode</code>
|
* subdirectory of backup masters; switch off the passed in <code>znode</code>
|
||||||
|
|
Loading…
Reference in New Issue