HBASE-13314 Fix NPE in HMaster.getClusterStatus()
This commit is contained in:
parent
5459008ccd
commit
80d230e1fb
|
@ -118,6 +118,9 @@ public class ClusterStatus extends VersionedWritable {
|
||||||
* @return the names of region servers on the dead list
|
* @return the names of region servers on the dead list
|
||||||
*/
|
*/
|
||||||
public Collection<ServerName> getDeadServerNames() {
|
public Collection<ServerName> getDeadServerNames() {
|
||||||
|
if (deadServers == null) {
|
||||||
|
return Collections.<ServerName>emptyList();
|
||||||
|
}
|
||||||
return Collections.unmodifiableCollection(deadServers);
|
return Collections.unmodifiableCollection(deadServers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,14 +128,14 @@ public class ClusterStatus extends VersionedWritable {
|
||||||
* @return the number of region servers in the cluster
|
* @return the number of region servers in the cluster
|
||||||
*/
|
*/
|
||||||
public int getServersSize() {
|
public int getServersSize() {
|
||||||
return liveServers.size();
|
return liveServers != null ? liveServers.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the number of dead region servers in the cluster
|
* @return the number of dead region servers in the cluster
|
||||||
*/
|
*/
|
||||||
public int getDeadServers() {
|
public int getDeadServers() {
|
||||||
return deadServers.size();
|
return deadServers != null ? deadServers.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,9 +151,11 @@ public class ClusterStatus extends VersionedWritable {
|
||||||
*/
|
*/
|
||||||
public int getRegionsCount() {
|
public int getRegionsCount() {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
if (liveServers != null && !liveServers.isEmpty()) {
|
||||||
for (Map.Entry<ServerName, ServerLoad> e: this.liveServers.entrySet()) {
|
for (Map.Entry<ServerName, ServerLoad> e: this.liveServers.entrySet()) {
|
||||||
count += e.getValue().getNumberOfRegions();
|
count += e.getValue().getNumberOfRegions();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,9 +164,11 @@ public class ClusterStatus extends VersionedWritable {
|
||||||
*/
|
*/
|
||||||
public int getRequestsCount() {
|
public int getRequestsCount() {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
if (liveServers != null && !liveServers.isEmpty()) {
|
||||||
for (Map.Entry<ServerName, ServerLoad> e: this.liveServers.entrySet()) {
|
for (Map.Entry<ServerName, ServerLoad> e: this.liveServers.entrySet()) {
|
||||||
count += e.getValue().getNumberOfRequests();
|
count += e.getValue().getNumberOfRequests();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,6 +229,9 @@ public class ClusterStatus extends VersionedWritable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<ServerName> getServers() {
|
public Collection<ServerName> getServers() {
|
||||||
|
if (liveServers == null) {
|
||||||
|
return Collections.<ServerName>emptyList();
|
||||||
|
}
|
||||||
return Collections.unmodifiableCollection(this.liveServers.keySet());
|
return Collections.unmodifiableCollection(this.liveServers.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,13 +247,16 @@ public class ClusterStatus extends VersionedWritable {
|
||||||
* @return the number of backup masters in the cluster
|
* @return the number of backup masters in the cluster
|
||||||
*/
|
*/
|
||||||
public int getBackupMastersSize() {
|
public int getBackupMastersSize() {
|
||||||
return this.backupMasters.size();
|
return backupMasters != null ? backupMasters.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the names of backup masters
|
* @return the names of backup masters
|
||||||
*/
|
*/
|
||||||
public Collection<ServerName> getBackupMasters() {
|
public Collection<ServerName> getBackupMasters() {
|
||||||
|
if (backupMasters == null) {
|
||||||
|
return Collections.<ServerName>emptyList();
|
||||||
|
}
|
||||||
return Collections.unmodifiableCollection(this.backupMasters);
|
return Collections.unmodifiableCollection(this.backupMasters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +265,7 @@ public class ClusterStatus extends VersionedWritable {
|
||||||
* @return Server's load or null if not found.
|
* @return Server's load or null if not found.
|
||||||
*/
|
*/
|
||||||
public ServerLoad getLoad(final ServerName sn) {
|
public ServerLoad getLoad(final ServerName sn) {
|
||||||
return this.liveServers.get(sn);
|
return liveServers != null ? liveServers.get(sn) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
|
@ -303,28 +316,42 @@ public class ClusterStatus extends VersionedWritable {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder(1024);
|
StringBuilder sb = new StringBuilder(1024);
|
||||||
sb.append("Master: " + master);
|
sb.append("Master: " + master);
|
||||||
sb.append("\nNumber of backup masters: " + backupMasters.size());
|
|
||||||
|
int backupMastersSize = getBackupMastersSize();
|
||||||
|
sb.append("\nNumber of backup masters: " + backupMastersSize);
|
||||||
|
if (backupMastersSize > 0) {
|
||||||
for (ServerName serverName: backupMasters) {
|
for (ServerName serverName: backupMasters) {
|
||||||
sb.append("\n " + serverName);
|
sb.append("\n " + serverName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sb.append("\nNumber of live region servers: " + liveServers.size());
|
int serversSize = getServersSize();
|
||||||
|
sb.append("\nNumber of live region servers: " + serversSize);
|
||||||
|
if (serversSize > 0) {
|
||||||
for (ServerName serverName: liveServers.keySet()) {
|
for (ServerName serverName: liveServers.keySet()) {
|
||||||
sb.append("\n " + serverName.getServerName());
|
sb.append("\n " + serverName.getServerName());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sb.append("\nNumber of dead region servers: " + deadServers.size());
|
int deadServerSize = getDeadServers();
|
||||||
|
sb.append("\nNumber of dead region servers: " + deadServerSize);
|
||||||
|
if (deadServerSize > 0) {
|
||||||
for (ServerName serverName: deadServers) {
|
for (ServerName serverName: deadServers) {
|
||||||
sb.append("\n " + serverName);
|
sb.append("\n " + serverName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sb.append("\nAverage load: " + getAverageLoad());
|
sb.append("\nAverage load: " + getAverageLoad());
|
||||||
sb.append("\nNumber of requests: " + getRequestsCount());
|
sb.append("\nNumber of requests: " + getRequestsCount());
|
||||||
sb.append("\nNumber of regions: " + getRegionsCount());
|
sb.append("\nNumber of regions: " + getRegionsCount());
|
||||||
sb.append("\nNumber of regions in transition: " + intransition.size());
|
|
||||||
|
int ritSize = (intransition != null) ? intransition.size() : 0;
|
||||||
|
sb.append("\nNumber of regions in transition: " + ritSize);
|
||||||
|
if (ritSize > 0) {
|
||||||
for (RegionState state: intransition.values()) {
|
for (RegionState state: intransition.values()) {
|
||||||
sb.append("\n " + state.toDescriptiveString());
|
sb.append("\n " + state.toDescriptiveString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1721,10 +1721,12 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
|
||||||
this.zooKeeper.backupMasterAddressesZNode);
|
this.zooKeeper.backupMasterAddressesZNode);
|
||||||
} catch (KeeperException e) {
|
} catch (KeeperException e) {
|
||||||
LOG.warn(this.zooKeeper.prefix("Unable to list backup servers"), e);
|
LOG.warn(this.zooKeeper.prefix("Unable to list backup servers"), e);
|
||||||
backupMasterStrings = new ArrayList<String>(0);
|
backupMasterStrings = null;
|
||||||
}
|
}
|
||||||
List<ServerName> backupMasters = new ArrayList<ServerName>(
|
|
||||||
backupMasterStrings.size());
|
List<ServerName> backupMasters = null;
|
||||||
|
if (backupMasterStrings != null && !backupMasterStrings.isEmpty()) {
|
||||||
|
backupMasters = new ArrayList<ServerName>(backupMasterStrings.size());
|
||||||
for (String s: backupMasterStrings) {
|
for (String s: backupMasterStrings) {
|
||||||
try {
|
try {
|
||||||
byte [] bytes;
|
byte [] bytes;
|
||||||
|
@ -1754,6 +1756,7 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
|
||||||
public int compare(ServerName s1, ServerName s2) {
|
public int compare(ServerName s1, ServerName s2) {
|
||||||
return s1.getServerName().compareTo(s2.getServerName());
|
return s1.getServerName().compareTo(s2.getServerName());
|
||||||
}});
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
String clusterId = fileSystemManager != null ?
|
String clusterId = fileSystemManager != null ?
|
||||||
fileSystemManager.getClusterId().toString() : null;
|
fileSystemManager.getClusterId().toString() : null;
|
||||||
|
|
Loading…
Reference in New Issue