HDFS-7457. DatanodeID generates excessive garbage. Contributed by Daryn Sharp.
This commit is contained in:
parent
44eed6cbc9
commit
780a6bf145
@ -515,6 +515,8 @@ Release 2.7.0 - UNRELEASED
|
||||
particular namenode in a federated cluster with multiple namenodes
|
||||
can be specified in the path parameter. (szetszwo)
|
||||
|
||||
HDFS-7457. DatanodeID generates excessive garbage. (daryn via kihwal)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
HDFS-7454. Reduce memory footprint for AclEntries in NameNode.
|
||||
|
@ -46,6 +46,8 @@ public class DatanodeID implements Comparable<DatanodeID> {
|
||||
private int infoPort; // info server port
|
||||
private int infoSecurePort; // info server port
|
||||
private int ipcPort; // IPC server port
|
||||
private String xferAddr;
|
||||
private int hashCode = -1;
|
||||
|
||||
/**
|
||||
* UUID identifying a given datanode. For upgraded Datanodes this is the
|
||||
@ -86,10 +88,12 @@ public DatanodeID(String ipAddr, String hostName, String datanodeUuid,
|
||||
this.infoPort = infoPort;
|
||||
this.infoSecurePort = infoSecurePort;
|
||||
this.ipcPort = ipcPort;
|
||||
updateXferAddrAndInvalidateHashCode();
|
||||
}
|
||||
|
||||
public void setIpAddr(String ipAddr) {
|
||||
this.ipAddr = ipAddr;
|
||||
updateXferAddrAndInvalidateHashCode();
|
||||
}
|
||||
|
||||
public void setPeerHostName(String peerHostName) {
|
||||
@ -106,6 +110,7 @@ public String getDatanodeUuid() {
|
||||
@VisibleForTesting
|
||||
public void setDatanodeUuidForTesting(String datanodeUuid) {
|
||||
this.datanodeUuid = datanodeUuid;
|
||||
updateXferAddrAndInvalidateHashCode();
|
||||
}
|
||||
|
||||
private String checkDatanodeUuid(String uuid) {
|
||||
@ -141,7 +146,7 @@ public String getPeerHostName() {
|
||||
* @return IP:xferPort string
|
||||
*/
|
||||
public String getXferAddr() {
|
||||
return ipAddr + ":" + xferPort;
|
||||
return xferAddr;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -237,7 +242,11 @@ public boolean equals(Object to) {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getXferAddr().hashCode()^ datanodeUuid.hashCode();
|
||||
if (hashCode == -1) {
|
||||
int newHashCode = xferAddr.hashCode() ^ datanodeUuid.hashCode();
|
||||
hashCode = newHashCode & Integer.MAX_VALUE;
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -257,6 +266,7 @@ public void updateRegInfo(DatanodeID nodeReg) {
|
||||
infoPort = nodeReg.getInfoPort();
|
||||
infoSecurePort = nodeReg.getInfoSecurePort();
|
||||
ipcPort = nodeReg.getIpcPort();
|
||||
updateXferAddrAndInvalidateHashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -269,4 +279,13 @@ public void updateRegInfo(DatanodeID nodeReg) {
|
||||
public int compareTo(DatanodeID that) {
|
||||
return getXferAddr().compareTo(that.getXferAddr());
|
||||
}
|
||||
|
||||
// NOTE: mutable hash codes are dangerous, however this class chooses to
|
||||
// use them. this method must be called when a value mutates that is used
|
||||
// to compute the hash, equality, or comparison of instances.
|
||||
private void updateXferAddrAndInvalidateHashCode() {
|
||||
xferAddr = ipAddr + ":" + xferPort;
|
||||
// can't compute new hash yet because uuid might still null...
|
||||
hashCode = -1;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user