|
@@ -18,6 +18,7 @@
|
|
|
|
|
|
package org.apache.hadoop.hdfs.protocol;
|
|
package org.apache.hadoop.hdfs.protocol;
|
|
|
|
|
|
|
|
+import com.google.protobuf.ByteString;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
|
|
|
|
@@ -42,7 +43,9 @@ public class DatanodeID implements Comparable<DatanodeID> {
|
|
public static final DatanodeID[] EMPTY_ARRAY = {};
|
|
public static final DatanodeID[] EMPTY_ARRAY = {};
|
|
|
|
|
|
private String ipAddr; // IP address
|
|
private String ipAddr; // IP address
|
|
|
|
+ private ByteString ipAddrBytes; // ipAddr ByteString to save on PB serde
|
|
private String hostName; // hostname claimed by datanode
|
|
private String hostName; // hostname claimed by datanode
|
|
|
|
+ private ByteString hostNameBytes; // hostName ByteString to save on PB serde
|
|
private String peerHostName; // hostname from the actual connection
|
|
private String peerHostName; // hostname from the actual connection
|
|
private int xferPort; // data streaming port
|
|
private int xferPort; // data streaming port
|
|
private int infoPort; // info server port
|
|
private int infoPort; // info server port
|
|
@@ -56,6 +59,8 @@ public class DatanodeID implements Comparable<DatanodeID> {
|
|
* For newly formatted Datanodes it is a UUID.
|
|
* For newly formatted Datanodes it is a UUID.
|
|
*/
|
|
*/
|
|
private final String datanodeUuid;
|
|
private final String datanodeUuid;
|
|
|
|
+ // datanodeUuid ByteString to save on PB serde
|
|
|
|
+ private final ByteString datanodeUuidBytes;
|
|
|
|
|
|
public DatanodeID(DatanodeID from) {
|
|
public DatanodeID(DatanodeID from) {
|
|
this(from.getDatanodeUuid(), from);
|
|
this(from.getDatanodeUuid(), from);
|
|
@@ -64,8 +69,11 @@ public class DatanodeID implements Comparable<DatanodeID> {
|
|
@VisibleForTesting
|
|
@VisibleForTesting
|
|
public DatanodeID(String datanodeUuid, DatanodeID from) {
|
|
public DatanodeID(String datanodeUuid, DatanodeID from) {
|
|
this(from.getIpAddr(),
|
|
this(from.getIpAddr(),
|
|
|
|
+ from.getIpAddrBytes(),
|
|
from.getHostName(),
|
|
from.getHostName(),
|
|
|
|
+ from.getHostNameBytes(),
|
|
datanodeUuid,
|
|
datanodeUuid,
|
|
|
|
+ getByteString(datanodeUuid),
|
|
from.getXferPort(),
|
|
from.getXferPort(),
|
|
from.getInfoPort(),
|
|
from.getInfoPort(),
|
|
from.getInfoSecurePort(),
|
|
from.getInfoSecurePort(),
|
|
@@ -87,22 +95,43 @@ public class DatanodeID implements Comparable<DatanodeID> {
|
|
*/
|
|
*/
|
|
public DatanodeID(String ipAddr, String hostName, String datanodeUuid,
|
|
public DatanodeID(String ipAddr, String hostName, String datanodeUuid,
|
|
int xferPort, int infoPort, int infoSecurePort, int ipcPort) {
|
|
int xferPort, int infoPort, int infoSecurePort, int ipcPort) {
|
|
- setIpAndXferPort(ipAddr, xferPort);
|
|
|
|
|
|
+ this(ipAddr, getByteString(ipAddr),
|
|
|
|
+ hostName, getByteString(hostName),
|
|
|
|
+ datanodeUuid, getByteString(datanodeUuid),
|
|
|
|
+ xferPort, infoPort, infoSecurePort, ipcPort);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private DatanodeID(String ipAddr, ByteString ipAddrBytes,
|
|
|
|
+ String hostName, ByteString hostNameBytes,
|
|
|
|
+ String datanodeUuid, ByteString datanodeUuidBytes,
|
|
|
|
+ int xferPort, int infoPort, int infoSecurePort, int ipcPort) {
|
|
|
|
+ setIpAndXferPort(ipAddr, ipAddrBytes, xferPort);
|
|
this.hostName = hostName;
|
|
this.hostName = hostName;
|
|
|
|
+ this.hostNameBytes = hostNameBytes;
|
|
this.datanodeUuid = checkDatanodeUuid(datanodeUuid);
|
|
this.datanodeUuid = checkDatanodeUuid(datanodeUuid);
|
|
|
|
+ this.datanodeUuidBytes = datanodeUuidBytes;
|
|
this.infoPort = infoPort;
|
|
this.infoPort = infoPort;
|
|
this.infoSecurePort = infoSecurePort;
|
|
this.infoSecurePort = infoSecurePort;
|
|
this.ipcPort = ipcPort;
|
|
this.ipcPort = ipcPort;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static ByteString getByteString(String str) {
|
|
|
|
+ if (str != null) {
|
|
|
|
+ return ByteString.copyFromUtf8(str);
|
|
|
|
+ }
|
|
|
|
+ return ByteString.EMPTY;
|
|
|
|
+ }
|
|
|
|
+
|
|
public void setIpAddr(String ipAddr) {
|
|
public void setIpAddr(String ipAddr) {
|
|
//updated during registration, preserve former xferPort
|
|
//updated during registration, preserve former xferPort
|
|
- setIpAndXferPort(ipAddr, xferPort);
|
|
|
|
|
|
+ setIpAndXferPort(ipAddr, getByteString(ipAddr), xferPort);
|
|
}
|
|
}
|
|
|
|
|
|
- private void setIpAndXferPort(String ipAddr, int xferPort) {
|
|
|
|
|
|
+ private void setIpAndXferPort(String ipAddr, ByteString ipAddrBytes,
|
|
|
|
+ int xferPort) {
|
|
// build xferAddr string to reduce cost of frequent use
|
|
// build xferAddr string to reduce cost of frequent use
|
|
this.ipAddr = ipAddr;
|
|
this.ipAddr = ipAddr;
|
|
|
|
+ this.ipAddrBytes = ipAddrBytes;
|
|
this.xferPort = xferPort;
|
|
this.xferPort = xferPort;
|
|
this.xferAddr = ipAddr + ":" + xferPort;
|
|
this.xferAddr = ipAddr + ":" + xferPort;
|
|
}
|
|
}
|
|
@@ -118,6 +147,10 @@ public class DatanodeID implements Comparable<DatanodeID> {
|
|
return datanodeUuid;
|
|
return datanodeUuid;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public ByteString getDatanodeUuidBytes() {
|
|
|
|
+ return datanodeUuidBytes;
|
|
|
|
+ }
|
|
|
|
+
|
|
private String checkDatanodeUuid(String uuid) {
|
|
private String checkDatanodeUuid(String uuid) {
|
|
if (uuid == null || uuid.isEmpty()) {
|
|
if (uuid == null || uuid.isEmpty()) {
|
|
return null;
|
|
return null;
|
|
@@ -133,6 +166,10 @@ public class DatanodeID implements Comparable<DatanodeID> {
|
|
return ipAddr;
|
|
return ipAddr;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public ByteString getIpAddrBytes() {
|
|
|
|
+ return ipAddrBytes;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @return hostname
|
|
* @return hostname
|
|
*/
|
|
*/
|
|
@@ -140,6 +177,10 @@ public class DatanodeID implements Comparable<DatanodeID> {
|
|
return hostName;
|
|
return hostName;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public ByteString getHostNameBytes() {
|
|
|
|
+ return hostNameBytes;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @return hostname from the actual connection
|
|
* @return hostname from the actual connection
|
|
*/
|
|
*/
|
|
@@ -256,7 +297,8 @@ public class DatanodeID implements Comparable<DatanodeID> {
|
|
* Note that this does not update storageID.
|
|
* Note that this does not update storageID.
|
|
*/
|
|
*/
|
|
public void updateRegInfo(DatanodeID nodeReg) {
|
|
public void updateRegInfo(DatanodeID nodeReg) {
|
|
- setIpAndXferPort(nodeReg.getIpAddr(), nodeReg.getXferPort());
|
|
|
|
|
|
+ setIpAndXferPort(nodeReg.getIpAddr(), nodeReg.getIpAddrBytes(),
|
|
|
|
+ nodeReg.getXferPort());
|
|
hostName = nodeReg.getHostName();
|
|
hostName = nodeReg.getHostName();
|
|
peerHostName = nodeReg.getPeerHostName();
|
|
peerHostName = nodeReg.getPeerHostName();
|
|
infoPort = nodeReg.getInfoPort();
|
|
infoPort = nodeReg.getInfoPort();
|