|
@@ -19,8 +19,7 @@ package org.apache.hadoop.hdfs.protocol;
|
|
|
|
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
|
-import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
-import org.apache.hadoop.hdfs.DFSUtil;
|
|
|
+import org.apache.hadoop.hdfs.DFSUtilClient;
|
|
|
import org.apache.hadoop.net.NetUtils;
|
|
|
import org.apache.hadoop.net.NetworkTopology;
|
|
|
import org.apache.hadoop.net.Node;
|
|
@@ -32,9 +31,9 @@ import java.util.Date;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import static org.apache.hadoop.hdfs.DFSUtil.percent2String;
|
|
|
+import static org.apache.hadoop.hdfs.DFSUtilClient.percent2String;
|
|
|
|
|
|
-/**
|
|
|
+/**
|
|
|
* This class extends the primary identifier of a Datanode with ephemeral
|
|
|
* state, eg usage information, current administrative state, and the
|
|
|
* network location that is communicated to clients.
|
|
@@ -54,12 +53,12 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
private String location = NetworkTopology.DEFAULT_RACK;
|
|
|
private String softwareVersion;
|
|
|
private List<String> dependentHostNames = new LinkedList<String>();
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
// Datanode administrative states
|
|
|
public enum AdminStates {
|
|
|
- NORMAL("In Service"),
|
|
|
- DECOMMISSION_INPROGRESS("Decommission In Progress"),
|
|
|
+ NORMAL("In Service"),
|
|
|
+ DECOMMISSION_INPROGRESS("Decommission In Progress"),
|
|
|
DECOMMISSIONED("Decommissioned");
|
|
|
|
|
|
final String value;
|
|
@@ -72,7 +71,7 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
public String toString() {
|
|
|
return value;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static AdminStates fromValue(final String value) {
|
|
|
for (AdminStates as : AdminStates.values()) {
|
|
|
if (as.value.equals(value)) return as;
|
|
@@ -109,14 +108,14 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
this.lastUpdate = 0L;
|
|
|
this.lastUpdateMonotonic = 0L;
|
|
|
this.xceiverCount = 0;
|
|
|
- this.adminState = null;
|
|
|
+ this.adminState = null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public DatanodeInfo(DatanodeID nodeID, String location) {
|
|
|
this(nodeID);
|
|
|
this.location = location;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public DatanodeInfo(DatanodeID nodeID, String location,
|
|
|
final long capacity, final long dfsUsed, final long remaining,
|
|
|
final long blockPoolUsed, final long cacheCapacity, final long cacheUsed,
|
|
@@ -152,16 +151,16 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
this.location = networkLocation;
|
|
|
this.adminState = adminState;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** Network location name */
|
|
|
@Override
|
|
|
public String getName() {
|
|
|
return getXferAddr();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** The raw capacity. */
|
|
|
public long getCapacity() { return capacity; }
|
|
|
-
|
|
|
+
|
|
|
/** The used space by the data node. */
|
|
|
public long getDfsUsed() { return dfsUsed; }
|
|
|
|
|
@@ -169,14 +168,14 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
public long getBlockPoolUsed() { return blockPoolUsed; }
|
|
|
|
|
|
/** The used space by the data node. */
|
|
|
- public long getNonDfsUsed() {
|
|
|
+ public long getNonDfsUsed() {
|
|
|
long nonDFSUsed = capacity - dfsUsed - remaining;
|
|
|
return nonDFSUsed < 0 ? 0 : nonDFSUsed;
|
|
|
}
|
|
|
|
|
|
/** The used space by the data node as percentage of present capacity */
|
|
|
- public float getDfsUsedPercent() {
|
|
|
- return DFSUtil.getPercentUsed(dfsUsed, capacity);
|
|
|
+ public float getDfsUsedPercent() {
|
|
|
+ return DFSUtilClient.getPercentUsed(dfsUsed, capacity);
|
|
|
}
|
|
|
|
|
|
/** The raw free space. */
|
|
@@ -184,12 +183,12 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
|
|
|
/** Used space by the block pool as percentage of present capacity */
|
|
|
public float getBlockPoolUsedPercent() {
|
|
|
- return DFSUtil.getPercentUsed(blockPoolUsed, capacity);
|
|
|
+ return DFSUtilClient.getPercentUsed(blockPoolUsed, capacity);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** The remaining space as percentage of configured capacity. */
|
|
|
- public float getRemainingPercent() {
|
|
|
- return DFSUtil.getPercentRemaining(remaining, capacity);
|
|
|
+ public float getRemainingPercent() {
|
|
|
+ return DFSUtilClient.getPercentRemaining(remaining, capacity);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -210,7 +209,7 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
* @return Cache used as a percentage of the datanode's total cache capacity
|
|
|
*/
|
|
|
public float getCacheUsedPercent() {
|
|
|
- return DFSUtil.getPercentUsed(cacheUsed, cacheCapacity);
|
|
|
+ return DFSUtilClient.getPercentUsed(cacheUsed, cacheCapacity);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -225,7 +224,7 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
* capacity
|
|
|
*/
|
|
|
public float getCacheRemainingPercent() {
|
|
|
- return DFSUtil.getPercentRemaining(getCacheRemaining(), cacheCapacity);
|
|
|
+ return DFSUtilClient.getPercentRemaining(getCacheRemaining(), cacheCapacity);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -234,10 +233,10 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
*/
|
|
|
public long getLastUpdate() { return lastUpdate; }
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* The time when this information was accurate. <br>
|
|
|
* Ps: So return value is ideal for calculation of time differences.
|
|
|
- * Should not be used to convert to Date.
|
|
|
+ * Should not be used to convert to Date.
|
|
|
*/
|
|
|
public long getLastUpdateMonotonic() { return lastUpdateMonotonic;}
|
|
|
|
|
@@ -252,23 +251,23 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
public int getXceiverCount() { return xceiverCount; }
|
|
|
|
|
|
/** Sets raw capacity. */
|
|
|
- public void setCapacity(long capacity) {
|
|
|
- this.capacity = capacity;
|
|
|
+ public void setCapacity(long capacity) {
|
|
|
+ this.capacity = capacity;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** Sets the used space for the datanode. */
|
|
|
public void setDfsUsed(long dfsUsed) {
|
|
|
this.dfsUsed = dfsUsed;
|
|
|
}
|
|
|
|
|
|
/** Sets raw free space. */
|
|
|
- public void setRemaining(long remaining) {
|
|
|
- this.remaining = remaining;
|
|
|
+ public void setRemaining(long remaining) {
|
|
|
+ this.remaining = remaining;
|
|
|
}
|
|
|
|
|
|
/** Sets block pool used space */
|
|
|
- public void setBlockPoolUsed(long bpUsed) {
|
|
|
- this.blockPoolUsed = bpUsed;
|
|
|
+ public void setBlockPoolUsed(long bpUsed) {
|
|
|
+ this.blockPoolUsed = bpUsed;
|
|
|
}
|
|
|
|
|
|
/** Sets cache capacity. */
|
|
@@ -282,38 +281,38 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
}
|
|
|
|
|
|
/** Sets time when this information was accurate. */
|
|
|
- public void setLastUpdate(long lastUpdate) {
|
|
|
- this.lastUpdate = lastUpdate;
|
|
|
+ public void setLastUpdate(long lastUpdate) {
|
|
|
+ this.lastUpdate = lastUpdate;
|
|
|
}
|
|
|
|
|
|
/** Sets number of active connections */
|
|
|
- public void setXceiverCount(int xceiverCount) {
|
|
|
- this.xceiverCount = xceiverCount;
|
|
|
+ public void setXceiverCount(int xceiverCount) {
|
|
|
+ this.xceiverCount = xceiverCount;
|
|
|
}
|
|
|
|
|
|
/** network location */
|
|
|
public synchronized String getNetworkLocation() {return location;}
|
|
|
-
|
|
|
+
|
|
|
/** Sets the network location */
|
|
|
public synchronized void setNetworkLocation(String location) {
|
|
|
this.location = NodeBase.normalize(location);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** Add a hostname to a list of network dependencies */
|
|
|
public void addDependentHostName(String hostname) {
|
|
|
dependentHostNames.add(hostname);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** List of Network dependencies */
|
|
|
public List<String> getDependentHostNames() {
|
|
|
return dependentHostNames;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** Sets the network dependencies */
|
|
|
public void setDependentHostNames(List<String> dependencyList) {
|
|
|
dependentHostNames = dependencyList;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** A formatted string for reporting the status of the DataNode. */
|
|
|
public String getDatanodeReport() {
|
|
|
StringBuilder buffer = new StringBuilder();
|
|
@@ -442,14 +441,13 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
}
|
|
|
return adminState;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * Check if the datanode is in stale state. Here if
|
|
|
- * the namenode has not received heartbeat msg from a
|
|
|
- * datanode for more than staleInterval (default value is
|
|
|
- * {@link DFSConfigKeys#DFS_NAMENODE_STALE_DATANODE_INTERVAL_DEFAULT}),
|
|
|
+ * Check if the datanode is in stale state. Here if
|
|
|
+ * the namenode has not received heartbeat msg from a
|
|
|
+ * datanode for more than staleInterval,
|
|
|
* the datanode will be treated as stale node.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param staleInterval
|
|
|
* the time interval for marking the node as stale. If the last
|
|
|
* update time is beyond the given time interval, the node will be
|
|
@@ -459,7 +457,7 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
public boolean isStale(long staleInterval) {
|
|
|
return (Time.monotonicNow() - lastUpdateMonotonic) >= staleInterval;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Sets the admin state of this node.
|
|
|
*/
|
|
@@ -480,7 +478,7 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
public Node getParent() { return parent; }
|
|
|
@Override
|
|
|
public void setParent(Node parent) {this.parent = parent;}
|
|
|
-
|
|
|
+
|
|
|
/** Return this node's level in the tree.
|
|
|
* E.g. the root of a tree returns 0 and its children return 1
|
|
|
*/
|
|
@@ -494,7 +492,7 @@ public class DatanodeInfo extends DatanodeID implements Node {
|
|
|
// Super implementation is sufficient
|
|
|
return super.hashCode();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean equals(Object obj) {
|
|
|
// Sufficient to use super equality as datanodes are uniquely identified
|