You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by at...@apache.org on 2013/02/16 02:12:16 UTC
svn commit: r1446832 [2/3] - in
/hadoop/common/branches/HDFS-347/hadoop-hdfs-project:
hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/
hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/
hadoop-hdfs-httpfs/src/test/java...
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java Sat Feb 16 01:12:07 2013
@@ -126,15 +126,26 @@ public class DatanodeManager {
private final long heartbeatExpireInterval;
/** Ask Datanode only up to this many blocks to delete. */
final int blockInvalidateLimit;
-
- /** Whether or not to check stale DataNodes for read/write */
- private final boolean checkForStaleDataNodes;
/** The interval for judging stale DataNodes for read/write */
private final long staleInterval;
- /** Whether or not to avoid using stale DataNodes for writing */
- private volatile boolean avoidStaleDataNodesForWrite;
+ /** Whether or not to avoid using stale DataNodes for reading */
+ private final boolean avoidStaleDataNodesForRead;
+
+ /**
+ * Whether or not to avoid using stale DataNodes for writing.
+ * Note that, even if this is configured, the policy may be
+ * temporarily disabled when a high percentage of the nodes
+ * are marked as stale.
+ */
+ private final boolean avoidStaleDataNodesForWrite;
+
+ /**
+ * When the ratio of stale datanodes reaches this number, stop avoiding
+ * writing to stale datanodes, i.e., continue using stale nodes for writing.
+ */
+ private final float ratioUseStaleDataNodesForWrite;
/** The number of stale DataNodes */
private volatile int numStaleNodes;
@@ -183,14 +194,23 @@ public class DatanodeManager {
DFSConfigKeys.DFS_BLOCK_INVALIDATE_LIMIT_KEY, blockInvalidateLimit);
LOG.info(DFSConfigKeys.DFS_BLOCK_INVALIDATE_LIMIT_KEY
+ "=" + this.blockInvalidateLimit);
-
- checkForStaleDataNodes = conf.getBoolean(
- DFSConfigKeys.DFS_NAMENODE_CHECK_STALE_DATANODE_KEY,
- DFSConfigKeys.DFS_NAMENODE_CHECK_STALE_DATANODE_DEFAULT);
-
- staleInterval = getStaleIntervalFromConf(conf, heartbeatExpireInterval);
- avoidStaleDataNodesForWrite = getAvoidStaleForWriteFromConf(conf,
- checkForStaleDataNodes);
+
+ this.avoidStaleDataNodesForRead = conf.getBoolean(
+ DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_READ_KEY,
+ DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_READ_DEFAULT);
+ this.avoidStaleDataNodesForWrite = conf.getBoolean(
+ DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_WRITE_KEY,
+ DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_WRITE_DEFAULT);
+ this.staleInterval = getStaleIntervalFromConf(conf, heartbeatExpireInterval);
+ this.ratioUseStaleDataNodesForWrite = conf.getFloat(
+ DFSConfigKeys.DFS_NAMENODE_USE_STALE_DATANODE_FOR_WRITE_RATIO_KEY,
+ DFSConfigKeys.DFS_NAMENODE_USE_STALE_DATANODE_FOR_WRITE_RATIO_DEFAULT);
+ Preconditions.checkArgument(
+ (ratioUseStaleDataNodesForWrite > 0 &&
+ ratioUseStaleDataNodesForWrite <= 1.0f),
+ DFSConfigKeys.DFS_NAMENODE_USE_STALE_DATANODE_FOR_WRITE_RATIO_KEY +
+ " = '" + ratioUseStaleDataNodesForWrite + "' is invalid. " +
+ "It should be a positive non-zero float value, not greater than 1.0f.");
}
private static long getStaleIntervalFromConf(Configuration conf,
@@ -230,22 +250,6 @@ public class DatanodeManager {
return staleInterval;
}
- static boolean getAvoidStaleForWriteFromConf(Configuration conf,
- boolean checkForStale) {
- boolean avoid = conf.getBoolean(
- DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_WRITE_KEY,
- DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_WRITE_DEFAULT);
- boolean avoidStaleDataNodesForWrite = checkForStale && avoid;
- if (!checkForStale && avoid) {
- LOG.warn("Cannot set "
- + DFSConfigKeys.DFS_NAMENODE_CHECK_STALE_DATANODE_KEY
- + " as false while setting "
- + DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_WRITE_KEY
- + " as true.");
- }
- return avoidStaleDataNodesForWrite;
- }
-
void activate(final Configuration conf) {
final DecommissionManager dm = new DecommissionManager(namesystem, blockManager);
this.decommissionthread = new Daemon(dm.new Monitor(
@@ -299,7 +303,7 @@ public class DatanodeManager {
client = new NodeBase(rName + NodeBase.PATH_SEPARATOR_STR + targethost);
}
- Comparator<DatanodeInfo> comparator = checkForStaleDataNodes ?
+ Comparator<DatanodeInfo> comparator = avoidStaleDataNodesForRead ?
new DFSUtil.DecomStaleComparator(staleInterval) :
DFSUtil.DECOM_COMPARATOR;
@@ -825,32 +829,20 @@ public class DatanodeManager {
}
/* Getter and Setter for stale DataNodes related attributes */
-
- /**
- * @return whether or not to avoid writing to stale datanodes
- */
- public boolean isAvoidingStaleDataNodesForWrite() {
- return avoidStaleDataNodesForWrite;
- }
/**
- * Set the value of {@link DatanodeManager#avoidStaleDataNodesForWrite}.
- * The HeartbeatManager disable avoidStaleDataNodesForWrite when more than
- * half of the DataNodes are marked as stale.
+ * Whether stale datanodes should be avoided as targets on the write path.
+ * The result of this function may change if the number of stale datanodes
+ * eclipses a configurable threshold.
*
- * @param avoidStaleDataNodesForWrite
- * The value to set to
- * {@link DatanodeManager#avoidStaleDataNodesForWrite}
- */
- void setAvoidStaleDataNodesForWrite(boolean avoidStaleDataNodesForWrite) {
- this.avoidStaleDataNodesForWrite = avoidStaleDataNodesForWrite;
- }
-
- /**
- * @return Whether or not to check stale DataNodes for R/W
+ * @return whether stale datanodes should be avoided on the write path
*/
- boolean isCheckingForStaleDataNodes() {
- return checkForStaleDataNodes;
+ public boolean shouldAvoidStaleDataNodesForWrite() {
+ // If # stale exceeds maximum staleness ratio, disable stale
+ // datanode avoidance on the write path
+ return avoidStaleDataNodesForWrite &&
+ (numStaleNodes <= heartbeatManager.getLiveDatanodeCount()
+ * ratioUseStaleDataNodesForWrite);
}
/**
@@ -967,7 +959,7 @@ public class DatanodeManager {
port = DFSConfigKeys.DFS_DATANODE_DEFAULT_PORT;
} else {
hostStr = hostLine.substring(0, idx);
- port = Integer.valueOf(hostLine.substring(idx));
+ port = Integer.valueOf(hostLine.substring(idx+1));
}
if (InetAddresses.isInetAddress(hostStr)) {
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/HeartbeatManager.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/HeartbeatManager.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/HeartbeatManager.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/HeartbeatManager.java Sat Feb 16 01:12:07 2013
@@ -30,8 +30,6 @@ import org.apache.hadoop.hdfs.server.nam
import org.apache.hadoop.util.Daemon;
import org.apache.hadoop.util.Time;
-import com.google.common.base.Preconditions;
-
/**
* Manage the heartbeats received from datanodes.
* The datanode list and statistics are synchronized
@@ -56,16 +54,7 @@ class HeartbeatManager implements Datano
private final long heartbeatRecheckInterval;
/** Heartbeat monitor thread */
private final Daemon heartbeatThread = new Daemon(new Monitor());
- /**
- * The initial setting of end user which indicates whether or not to avoid
- * writing to stale datanodes.
- */
- private final boolean initialAvoidWriteStaleNodes;
- /**
- * When the ratio of stale datanodes reaches this number, stop avoiding
- * writing to stale datanodes, i.e., continue using stale nodes for writing.
- */
- private final float ratioUseStaleDataNodesForWrite;
+
final Namesystem namesystem;
final BlockManager blockManager;
@@ -74,30 +63,25 @@ class HeartbeatManager implements Datano
final BlockManager blockManager, final Configuration conf) {
this.namesystem = namesystem;
this.blockManager = blockManager;
- boolean checkStaleNodes = conf.getBoolean(
- DFSConfigKeys.DFS_NAMENODE_CHECK_STALE_DATANODE_KEY,
- DFSConfigKeys.DFS_NAMENODE_CHECK_STALE_DATANODE_DEFAULT);
+ boolean avoidStaleDataNodesForWrite = conf.getBoolean(
+ DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_WRITE_KEY,
+ DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_WRITE_DEFAULT);
long recheckInterval = conf.getInt(
- DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY,
+ DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY,
DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_DEFAULT); // 5 min
long staleInterval = conf.getLong(
- DFSConfigKeys.DFS_NAMENODE_STALE_DATANODE_INTERVAL_KEY,
+ DFSConfigKeys.DFS_NAMENODE_STALE_DATANODE_INTERVAL_KEY,
DFSConfigKeys.DFS_NAMENODE_STALE_DATANODE_INTERVAL_DEFAULT);// 30s
- this.initialAvoidWriteStaleNodes = DatanodeManager
- .getAvoidStaleForWriteFromConf(conf, checkStaleNodes);
- this.ratioUseStaleDataNodesForWrite = conf.getFloat(
- DFSConfigKeys.DFS_NAMENODE_USE_STALE_DATANODE_FOR_WRITE_RATIO_KEY,
- DFSConfigKeys.DFS_NAMENODE_USE_STALE_DATANODE_FOR_WRITE_RATIO_DEFAULT);
- Preconditions.checkArgument(
- (ratioUseStaleDataNodesForWrite > 0 &&
- ratioUseStaleDataNodesForWrite <= 1.0f),
- DFSConfigKeys.DFS_NAMENODE_USE_STALE_DATANODE_FOR_WRITE_RATIO_KEY +
- " = '" + ratioUseStaleDataNodesForWrite + "' is invalid. " +
- "It should be a positive non-zero float value, not greater than 1.0f.");
-
- this.heartbeatRecheckInterval = (checkStaleNodes
- && initialAvoidWriteStaleNodes
- && staleInterval < recheckInterval) ? staleInterval : recheckInterval;
+
+ if (avoidStaleDataNodesForWrite && staleInterval < recheckInterval) {
+ this.heartbeatRecheckInterval = staleInterval;
+ LOG.info("Setting heartbeat recheck interval to " + staleInterval
+ + " since " + DFSConfigKeys.DFS_NAMENODE_STALE_DATANODE_INTERVAL_KEY
+ + " is less than "
+ + DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY);
+ } else {
+ this.heartbeatRecheckInterval = recheckInterval;
+ }
}
void activate(Configuration conf) {
@@ -242,7 +226,6 @@ class HeartbeatManager implements Datano
if (namesystem.isInSafeMode()) {
return;
}
- boolean checkStaleNodes = dm.isCheckingForStaleDataNodes();
boolean allAlive = false;
while (!allAlive) {
// locate the first dead node.
@@ -254,29 +237,14 @@ class HeartbeatManager implements Datano
if (dead == null && dm.isDatanodeDead(d)) {
stats.incrExpiredHeartbeats();
dead = d;
- if (!checkStaleNodes) {
- break;
- }
}
- if (checkStaleNodes &&
- d.isStale(dm.getStaleInterval())) {
+ if (d.isStale(dm.getStaleInterval())) {
numOfStaleNodes++;
}
}
- // Change whether to avoid using stale datanodes for writing
- // based on proportion of stale datanodes
- if (checkStaleNodes) {
- dm.setNumStaleNodes(numOfStaleNodes);
- if (numOfStaleNodes >
- datanodes.size() * ratioUseStaleDataNodesForWrite) {
- dm.setAvoidStaleDataNodesForWrite(false);
- } else {
- if (this.initialAvoidWriteStaleNodes) {
- dm.setAvoidStaleDataNodesForWrite(true);
- }
- }
- }
+ // Set the number of stale nodes in the DatanodeManager
+ dm.setNumStaleNodes(numOfStaleNodes);
}
allAlive = dead == null;
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java Sat Feb 16 01:12:07 2013
@@ -905,7 +905,7 @@ public abstract class Storage extends St
props.setProperty("storageType", storageType.toString());
props.setProperty("namespaceID", String.valueOf(namespaceID));
// Set clusterID in version with federation support
- if (LayoutVersion.supports(Feature.FEDERATION, layoutVersion)) {
+ if (versionSupportsFederation()) {
props.setProperty("clusterID", clusterID);
}
props.setProperty("cTime", String.valueOf(cTime));
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/StorageInfo.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/StorageInfo.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/StorageInfo.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/StorageInfo.java Sat Feb 16 01:12:07 2013
@@ -18,6 +18,8 @@
package org.apache.hadoop.hdfs.server.common;
import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.hdfs.protocol.LayoutVersion;
+import org.apache.hadoop.hdfs.protocol.LayoutVersion.Feature;
import com.google.common.base.Joiner;
@@ -77,6 +79,10 @@ public class StorageInfo {
namespaceID = from.namespaceID;
cTime = from.cTime;
}
+
+ public boolean versionSupportsFederation() {
+ return LayoutVersion.supports(Feature.FEDERATION, layoutVersion);
+ }
@Override
public String toString() {
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java Sat Feb 16 01:12:07 2013
@@ -76,6 +76,7 @@ import org.apache.hadoop.hdfs.server.dat
import org.apache.hadoop.hdfs.server.protocol.BlockRecoveryCommand.RecoveringBlock;
import org.apache.hadoop.hdfs.server.protocol.ReplicaRecoveryInfo;
import org.apache.hadoop.io.IOUtils;
+import org.apache.hadoop.io.nativeio.NativeIO;
import org.apache.hadoop.metrics2.util.MBeans;
import org.apache.hadoop.util.DataChecksum;
import org.apache.hadoop.util.DiskChecker.DiskErrorException;
@@ -399,13 +400,17 @@ class FsDatasetImpl implements FsDataset
final File dstfile = new File(destdir, b.getBlockName());
final File srcmeta = FsDatasetUtil.getMetaFile(srcfile, b.getGenerationStamp());
final File dstmeta = FsDatasetUtil.getMetaFile(dstfile, b.getGenerationStamp());
- if (!srcmeta.renameTo(dstmeta)) {
+ try {
+ NativeIO.renameTo(srcmeta, dstmeta);
+ } catch (IOException e) {
throw new IOException("Failed to move meta file for " + b
- + " from " + srcmeta + " to " + dstmeta);
+ + " from " + srcmeta + " to " + dstmeta, e);
}
- if (!srcfile.renameTo(dstfile)) {
+ try {
+ NativeIO.renameTo(srcfile, dstfile);
+ } catch (IOException e) {
throw new IOException("Failed to move block file for " + b
- + " from " + srcfile + " to " + dstfile.getAbsolutePath());
+ + " from " + srcfile + " to " + dstfile.getAbsolutePath(), e);
}
if (LOG.isDebugEnabled()) {
LOG.debug("addBlock: Moved " + srcmeta + " to " + dstmeta
@@ -532,10 +537,12 @@ class FsDatasetImpl implements FsDataset
if (LOG.isDebugEnabled()) {
LOG.debug("Renaming " + oldmeta + " to " + newmeta);
}
- if (!oldmeta.renameTo(newmeta)) {
+ try {
+ NativeIO.renameTo(oldmeta, newmeta);
+ } catch (IOException e) {
throw new IOException("Block " + replicaInfo + " reopen failed. " +
" Unable to move meta file " + oldmeta +
- " to rbw dir " + newmeta);
+ " to rbw dir " + newmeta, e);
}
// rename block file to rbw directory
@@ -543,14 +550,18 @@ class FsDatasetImpl implements FsDataset
LOG.debug("Renaming " + blkfile + " to " + newBlkFile
+ ", file length=" + blkfile.length());
}
- if (!blkfile.renameTo(newBlkFile)) {
- if (!newmeta.renameTo(oldmeta)) { // restore the meta file
+ try {
+ NativeIO.renameTo(blkfile, newBlkFile);
+ } catch (IOException e) {
+ try {
+ NativeIO.renameTo(newmeta, oldmeta);
+ } catch (IOException ex) {
LOG.warn("Cannot move meta file " + newmeta +
- "back to the finalized directory " + oldmeta);
+ "back to the finalized directory " + oldmeta, ex);
}
throw new IOException("Block " + replicaInfo + " reopen failed. " +
" Unable to move block file " + blkfile +
- " to rbw dir " + newBlkFile);
+ " to rbw dir " + newBlkFile, e);
}
// Replace finalized replica by a RBW replica in replicas map
@@ -657,11 +668,13 @@ class FsDatasetImpl implements FsDataset
if (LOG.isDebugEnabled()) {
LOG.debug("Renaming " + oldmeta + " to " + newmeta);
}
- if (!oldmeta.renameTo(newmeta)) {
+ try {
+ NativeIO.renameTo(oldmeta, newmeta);
+ } catch (IOException e) {
replicaInfo.setGenerationStamp(oldGS); // restore old GS
throw new IOException("Block " + replicaInfo + " reopen failed. " +
" Unable to move meta file " + oldmeta +
- " to " + newmeta);
+ " to " + newmeta, e);
}
}
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CheckpointSignature.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CheckpointSignature.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CheckpointSignature.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CheckpointSignature.java Sat Feb 16 01:12:07 2013
@@ -123,6 +123,10 @@ public class CheckpointSignature extends
blockpoolID.equals(si.getBlockPoolID());
}
+ boolean namespaceIdMatches(FSImage si) {
+ return namespaceID == si.getStorage().namespaceID;
+ }
+
void validateStorageInfo(FSImage si) throws IOException {
if (!isSameCluster(si)
|| !storageVersionMatches(si.getStorage())) {
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ClusterJspHelper.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ClusterJspHelper.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ClusterJspHelper.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ClusterJspHelper.java Sat Feb 16 01:12:07 2013
@@ -569,12 +569,10 @@ class ClusterJspHelper {
toXmlItemBlock(doc, "DFS Remaining", StringUtils.byteDesc(free));
// dfsUsedPercent
- toXmlItemBlock(doc, "DFS Used%",
- StringUtils.limitDecimalTo2(dfsUsedPercent)+ "%");
+ toXmlItemBlock(doc, "DFS Used%", DFSUtil.percent2String(dfsUsedPercent));
// dfsRemainingPercent
- toXmlItemBlock(doc, "DFS Remaining%",
- StringUtils.limitDecimalTo2(dfsRemainingPercent) + "%");
+ toXmlItemBlock(doc, "DFS Remaining%", DFSUtil.percent2String(dfsRemainingPercent));
doc.endTag(); // storage
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java Sat Feb 16 01:12:07 2013
@@ -1985,7 +1985,8 @@ public class FSDirectory implements Clos
node.getUserName(),
node.getGroupName(),
node.isSymlink() ? ((INodeSymlink)node).getSymlink() : null,
- path);
+ path,
+ node.getId());
}
/**
@@ -2022,6 +2023,7 @@ public class FSDirectory implements Clos
node.getGroupName(),
node.isSymlink() ? ((INodeSymlink)node).getSymlink() : null,
path,
+ node.getId(),
loc);
}
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java Sat Feb 16 01:12:07 2013
@@ -127,6 +127,7 @@ import org.apache.hadoop.fs.permission.F
import org.apache.hadoop.fs.permission.PermissionStatus;
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
import org.apache.hadoop.ha.ServiceFailedException;
+import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSUtil;
import org.apache.hadoop.hdfs.HAUtil;
import org.apache.hadoop.hdfs.HdfsConfiguration;
@@ -422,51 +423,73 @@ public class FSNamesystem implements Nam
}
/**
-
- /**
- * Instantiates an FSNamesystem loaded from the image and edits
- * directories specified in the passed Configuration.
- *
- * @param conf the Configuration which specifies the storage directories
- * from which to load
- * @return an FSNamesystem which contains the loaded namespace
- * @throws IOException if loading fails
+ * Check the supplied configuration for correctness.
+ * @param conf Supplies the configuration to validate.
+ * @throws IOException if the configuration could not be queried.
+ * @throws IllegalArgumentException if the configuration is invalid.
*/
- public static FSNamesystem loadFromDisk(Configuration conf)
+ private static void checkConfiguration(Configuration conf)
throws IOException {
- Collection<URI> namespaceDirs = FSNamesystem.getNamespaceDirs(conf);
- List<URI> namespaceEditsDirs =
- FSNamesystem.getNamespaceEditsDirs(conf);
- return loadFromDisk(conf, namespaceDirs, namespaceEditsDirs);
- }
- /**
- * Instantiates an FSNamesystem loaded from the image and edits
- * directories passed.
- *
- * @param conf the Configuration which specifies the storage directories
- * from which to load
- * @param namespaceDirs directories to load the fsimages
- * @param namespaceEditsDirs directories to load the edits from
- * @return an FSNamesystem which contains the loaded namespace
- * @throws IOException if loading fails
- */
- public static FSNamesystem loadFromDisk(Configuration conf,
- Collection<URI> namespaceDirs, List<URI> namespaceEditsDirs)
- throws IOException {
+ final Collection<URI> namespaceDirs =
+ FSNamesystem.getNamespaceDirs(conf);
+ final Collection<URI> editsDirs =
+ FSNamesystem.getNamespaceEditsDirs(conf);
+ final Collection<URI> requiredEditsDirs =
+ FSNamesystem.getRequiredNamespaceEditsDirs(conf);
+ final Collection<URI> sharedEditsDirs =
+ FSNamesystem.getSharedEditsDirs(conf);
+
+ for (URI u : requiredEditsDirs) {
+ if (u.toString().compareTo(
+ DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_DEFAULT) == 0) {
+ continue;
+ }
+
+ // Each required directory must also be in editsDirs or in
+ // sharedEditsDirs.
+ if (!editsDirs.contains(u) &&
+ !sharedEditsDirs.contains(u)) {
+ throw new IllegalArgumentException(
+ "Required edits directory " + u.toString() + " not present in " +
+ DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY + ". " +
+ DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY + "=" +
+ editsDirs.toString() + "; " +
+ DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_REQUIRED_KEY + "=" +
+ requiredEditsDirs.toString() + ". " +
+ DFSConfigKeys.DFS_NAMENODE_SHARED_EDITS_DIR_KEY + "=" +
+ sharedEditsDirs.toString() + ".");
+ }
+ }
if (namespaceDirs.size() == 1) {
LOG.warn("Only one image storage directory ("
+ DFS_NAMENODE_NAME_DIR_KEY + ") configured. Beware of dataloss"
+ " due to lack of redundant storage directories!");
}
- if (namespaceEditsDirs.size() == 1) {
+ if (editsDirs.size() == 1) {
LOG.warn("Only one namespace edits storage directory ("
+ DFS_NAMENODE_EDITS_DIR_KEY + ") configured. Beware of dataloss"
+ " due to lack of redundant storage directories!");
}
+ }
+
+ /**
+ * Instantiates an FSNamesystem loaded from the image and edits
+ * directories specified in the passed Configuration.
+ *
+ * @param conf the Configuration which specifies the storage directories
+ * from which to load
+ * @return an FSNamesystem which contains the loaded namespace
+ * @throws IOException if loading fails
+ */
+ public static FSNamesystem loadFromDisk(Configuration conf)
+ throws IOException {
- FSImage fsImage = new FSImage(conf, namespaceDirs, namespaceEditsDirs);
+ checkConfiguration(conf);
+ FSImage fsImage = new FSImage(conf,
+ FSNamesystem.getNamespaceDirs(conf),
+ FSNamesystem.getNamespaceEditsDirs(conf));
FSNamesystem namesystem = new FSNamesystem(conf, fsImage);
StartupOption startOpt = NameNode.getStartupOption(conf);
if (startOpt == StartupOption.RECOVER) {
@@ -913,7 +936,8 @@ public class FSNamesystem implements Nam
"\n\t\t- use Backup Node as a persistent and up-to-date storage " +
"of the file system meta-data.");
} else if (dirNames.isEmpty()) {
- dirNames = Collections.singletonList("file:///tmp/hadoop/dfs/name");
+ dirNames = Collections.singletonList(
+ DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_DEFAULT);
}
return Util.stringCollectionAsURIs(dirNames);
}
@@ -1772,16 +1796,18 @@ public class FSNamesystem implements Nam
* Create a new file entry in the namespace.
*
* For description of parameters and exceptions thrown see
- * {@link ClientProtocol#create()}
+ * {@link ClientProtocol#create()}, except it returns valid file status
+ * upon success
*/
- void startFile(String src, PermissionStatus permissions, String holder,
- String clientMachine, EnumSet<CreateFlag> flag, boolean createParent,
- short replication, long blockSize) throws AccessControlException,
- SafeModeException, FileAlreadyExistsException, UnresolvedLinkException,
+ HdfsFileStatus startFile(String src, PermissionStatus permissions,
+ String holder, String clientMachine, EnumSet<CreateFlag> flag,
+ boolean createParent, short replication, long blockSize)
+ throws AccessControlException, SafeModeException,
+ FileAlreadyExistsException, UnresolvedLinkException,
FileNotFoundException, ParentNotDirectoryException, IOException {
try {
- startFileInt(src, permissions, holder, clientMachine, flag, createParent,
- replication, blockSize);
+ return startFileInt(src, permissions, holder, clientMachine, flag,
+ createParent, replication, blockSize);
} catch (AccessControlException e) {
if (isAuditEnabled() && isExternalInvocation()) {
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
@@ -1792,18 +1818,21 @@ public class FSNamesystem implements Nam
}
}
- private void startFileInt(String src, PermissionStatus permissions, String holder,
- String clientMachine, EnumSet<CreateFlag> flag, boolean createParent,
- short replication, long blockSize) throws AccessControlException,
- SafeModeException, FileAlreadyExistsException, UnresolvedLinkException,
+ private HdfsFileStatus startFileInt(String src, PermissionStatus permissions,
+ String holder, String clientMachine, EnumSet<CreateFlag> flag,
+ boolean createParent, short replication, long blockSize)
+ throws AccessControlException, SafeModeException,
+ FileAlreadyExistsException, UnresolvedLinkException,
FileNotFoundException, ParentNotDirectoryException, IOException {
boolean skipSync = false;
+ final HdfsFileStatus stat;
writeLock();
try {
checkOperation(OperationCategory.WRITE);
startFileInternal(src, permissions, holder, clientMachine, flag,
createParent, replication, blockSize);
+ stat = dir.getFileInfo(src, false);
} catch (StandbyException se) {
skipSync = true;
throw se;
@@ -1817,11 +1846,11 @@ public class FSNamesystem implements Nam
}
if (isAuditEnabled() && isExternalInvocation()) {
- final HdfsFileStatus stat = dir.getFileInfo(src, false);
logAuditEvent(UserGroupInformation.getCurrentUser(),
getRemoteIp(),
"create", src, null, stat);
}
+ return stat;
}
/**
@@ -2192,20 +2221,14 @@ public class FSNamesystem implements Nam
* are replicated. Will return an empty 2-elt array if we want the
* client to "try again later".
*/
- LocatedBlock getAdditionalBlock(String src,
- String clientName,
- ExtendedBlock previous,
- HashMap<Node, Node> excludedNodes
- )
+ LocatedBlock getAdditionalBlock(String src, long fileId, String clientName,
+ ExtendedBlock previous, HashMap<Node, Node> excludedNodes)
throws LeaseExpiredException, NotReplicatedYetException,
QuotaExceededException, SafeModeException, UnresolvedLinkException,
IOException {
- checkBlock(previous);
- Block previousBlock = ExtendedBlock.getLocalBlock(previous);
- long fileLength, blockSize;
+ long blockSize;
int replication;
DatanodeDescriptor clientNode = null;
- Block newBlock = null;
if(NameNode.stateChangeLog.isDebugEnabled()) {
NameNode.stateChangeLog.debug(
@@ -2213,119 +2236,61 @@ public class FSNamesystem implements Nam
+src+" for "+clientName);
}
- writeLock();
+ // Part I. Analyze the state of the file with respect to the input data.
+ readLock();
try {
- checkOperation(OperationCategory.WRITE);
-
- if (isInSafeMode()) {
- throw new SafeModeException("Cannot add block to " + src, safeMode);
- }
-
- // have we exceeded the configured limit of fs objects.
- checkFsObjectLimit();
-
- INodeFileUnderConstruction pendingFile = checkLease(src, clientName);
- BlockInfo lastBlockInFile = pendingFile.getLastBlock();
- if (!Block.matchingIdAndGenStamp(previousBlock, lastBlockInFile)) {
- // The block that the client claims is the current last block
- // doesn't match up with what we think is the last block. There are
- // three possibilities:
- // 1) This is the first block allocation of an append() pipeline
- // which started appending exactly at a block boundary.
- // In this case, the client isn't passed the previous block,
- // so it makes the allocateBlock() call with previous=null.
- // We can distinguish this since the last block of the file
- // will be exactly a full block.
- // 2) This is a retry from a client that missed the response of a
- // prior getAdditionalBlock() call, perhaps because of a network
- // timeout, or because of an HA failover. In that case, we know
- // by the fact that the client is re-issuing the RPC that it
- // never began to write to the old block. Hence it is safe to
- // abandon it and allocate a new one.
- // 3) This is an entirely bogus request/bug -- we should error out
- // rather than potentially appending a new block with an empty
- // one in the middle, etc
-
- BlockInfo penultimateBlock = pendingFile.getPenultimateBlock();
- if (previous == null &&
- lastBlockInFile != null &&
- lastBlockInFile.getNumBytes() == pendingFile.getPreferredBlockSize() &&
- lastBlockInFile.isComplete()) {
- // Case 1
- if (NameNode.stateChangeLog.isDebugEnabled()) {
- NameNode.stateChangeLog.debug(
- "BLOCK* NameSystem.allocateBlock: handling block allocation" +
- " writing to a file with a complete previous block: src=" +
- src + " lastBlock=" + lastBlockInFile);
- }
- } else if (Block.matchingIdAndGenStamp(penultimateBlock, previousBlock)) {
- // Case 2
- if (lastBlockInFile.getNumBytes() != 0) {
- throw new IOException(
- "Request looked like a retry to allocate block " +
- lastBlockInFile + " but it already contains " +
- lastBlockInFile.getNumBytes() + " bytes");
- }
-
- // The retry case ("b" above) -- abandon the old block.
- NameNode.stateChangeLog.info("BLOCK* allocateBlock: " +
- "caught retry for allocation of a new block in " +
- src + ". Abandoning old block " + lastBlockInFile);
- dir.removeBlock(src, pendingFile, lastBlockInFile);
- dir.persistBlocks(src, pendingFile);
- } else {
-
- throw new IOException("Cannot allocate block in " + src + ": " +
- "passed 'previous' block " + previous + " does not match actual " +
- "last block in file " + lastBlockInFile);
- }
+ LocatedBlock[] onRetryBlock = new LocatedBlock[1];
+ final INode[] inodes = analyzeFileState(
+ src, fileId, clientName, previous, onRetryBlock).getINodes();
+ final INodeFileUnderConstruction pendingFile =
+ (INodeFileUnderConstruction) inodes[inodes.length - 1];
+
+ if(onRetryBlock[0] != null) {
+ // This is a retry. Just return the last block.
+ return onRetryBlock[0];
}
- // commit the last block and complete it if it has minimum replicas
- commitOrCompleteLastBlock(pendingFile, previousBlock);
-
- //
- // If we fail this, bad things happen!
- //
- if (!checkFileProgress(pendingFile, false)) {
- throw new NotReplicatedYetException("Not replicated yet:" + src);
- }
- fileLength = pendingFile.computeContentSummary().getLength();
blockSize = pendingFile.getPreferredBlockSize();
clientNode = pendingFile.getClientNode();
replication = pendingFile.getBlockReplication();
} finally {
- writeUnlock();
+ readUnlock();
}
// choose targets for the new block to be allocated.
- final DatanodeDescriptor targets[] = blockManager.chooseTarget(
+ final DatanodeDescriptor targets[] = getBlockManager().chooseTarget(
src, replication, clientNode, excludedNodes, blockSize);
- // Allocate a new block and record it in the INode.
+ // Part II.
+ // Allocate a new block, add it to the INode and the BlocksMap.
+ Block newBlock = null;
+ long offset;
writeLock();
try {
- checkOperation(OperationCategory.WRITE);
- if (isInSafeMode()) {
- throw new SafeModeException("Cannot add block to " + src, safeMode);
+ // Run the full analysis again, since things could have changed
+ // while chooseTarget() was executing.
+ LocatedBlock[] onRetryBlock = new LocatedBlock[1];
+ INodesInPath inodesInPath =
+ analyzeFileState(src, fileId, clientName, previous, onRetryBlock);
+ INode[] inodes = inodesInPath.getINodes();
+ final INodeFileUnderConstruction pendingFile =
+ (INodeFileUnderConstruction) inodes[inodes.length - 1];
+
+ if(onRetryBlock[0] != null) {
+ // This is a retry. Just return the last block.
+ return onRetryBlock[0];
}
- final INodesInPath inodesInPath = dir.rootDir.getExistingPathINodes(src, true);
- final INode[] inodes = inodesInPath.getINodes();
- final INodeFileUnderConstruction pendingFile
- = checkLease(src, clientName, inodes[inodes.length - 1]);
-
- if (!checkFileProgress(pendingFile, false)) {
- throw new NotReplicatedYetException("Not replicated yet:" + src);
- }
+ // commit the last block and complete it if it has minimum replicas
+ commitOrCompleteLastBlock(pendingFile,
+ ExtendedBlock.getLocalBlock(previous));
+
+ // allocate new block, record block locations in INode.
+ newBlock = createNewBlock();
+ saveAllocatedBlock(src, inodesInPath, newBlock, targets);
- // allocate new block record block locations in INode.
- newBlock = allocateBlock(src, inodesInPath, targets);
-
- for (DatanodeDescriptor dn : targets) {
- dn.incBlocksScheduled();
- }
dir.persistBlocks(src, pendingFile);
+ offset = pendingFile.computeFileSize(true);
} finally {
writeUnlock();
}
@@ -2333,10 +2298,115 @@ public class FSNamesystem implements Nam
getEditLog().logSync();
}
- // Create next block
- LocatedBlock b = new LocatedBlock(getExtendedBlock(newBlock), targets, fileLength);
- blockManager.setBlockToken(b, BlockTokenSecretManager.AccessMode.WRITE);
- return b;
+ // Return located block
+ return makeLocatedBlock(newBlock, targets, offset);
+ }
+
+ INodesInPath analyzeFileState(String src,
+ long fileId,
+ String clientName,
+ ExtendedBlock previous,
+ LocatedBlock[] onRetryBlock)
+ throws IOException {
+ assert hasReadOrWriteLock();
+
+ checkBlock(previous);
+ onRetryBlock[0] = null;
+ checkOperation(OperationCategory.WRITE);
+ if (isInSafeMode()) {
+ throw new SafeModeException("Cannot add block to " + src, safeMode);
+ }
+
+ // have we exceeded the configured limit of fs objects.
+ checkFsObjectLimit();
+
+ Block previousBlock = ExtendedBlock.getLocalBlock(previous);
+ final INodesInPath inodesInPath =
+ dir.rootDir.getExistingPathINodes(src, true);
+ final INode[] inodes = inodesInPath.getINodes();
+ final INodeFileUnderConstruction pendingFile
+ = checkLease(src, fileId, clientName, inodes[inodes.length - 1]);
+ BlockInfo lastBlockInFile = pendingFile.getLastBlock();
+ if (!Block.matchingIdAndGenStamp(previousBlock, lastBlockInFile)) {
+ // The block that the client claims is the current last block
+ // doesn't match up with what we think is the last block. There are
+ // four possibilities:
+ // 1) This is the first block allocation of an append() pipeline
+ // which started appending exactly at a block boundary.
+ // In this case, the client isn't passed the previous block,
+ // so it makes the allocateBlock() call with previous=null.
+ // We can distinguish this since the last block of the file
+ // will be exactly a full block.
+ // 2) This is a retry from a client that missed the response of a
+ // prior getAdditionalBlock() call, perhaps because of a network
+ // timeout, or because of an HA failover. In that case, we know
+ // by the fact that the client is re-issuing the RPC that it
+ // never began to write to the old block. Hence it is safe to
+ // to return the existing block.
+ // 3) This is an entirely bogus request/bug -- we should error out
+ // rather than potentially appending a new block with an empty
+ // one in the middle, etc
+ // 4) This is a retry from a client that timed out while
+ // the prior getAdditionalBlock() is still being processed,
+ // currently working on chooseTarget().
+ // There are no means to distinguish between the first and
+ // the second attempts in Part I, because the first one hasn't
+ // changed the namesystem state yet.
+ // We run this analysis again in Part II where case 4 is impossible.
+
+ BlockInfo penultimateBlock = pendingFile.getPenultimateBlock();
+ if (previous == null &&
+ lastBlockInFile != null &&
+ lastBlockInFile.getNumBytes() == pendingFile.getPreferredBlockSize() &&
+ lastBlockInFile.isComplete()) {
+ // Case 1
+ if (NameNode.stateChangeLog.isDebugEnabled()) {
+ NameNode.stateChangeLog.debug(
+ "BLOCK* NameSystem.allocateBlock: handling block allocation" +
+ " writing to a file with a complete previous block: src=" +
+ src + " lastBlock=" + lastBlockInFile);
+ }
+ } else if (Block.matchingIdAndGenStamp(penultimateBlock, previousBlock)) {
+ if (lastBlockInFile.getNumBytes() != 0) {
+ throw new IOException(
+ "Request looked like a retry to allocate block " +
+ lastBlockInFile + " but it already contains " +
+ lastBlockInFile.getNumBytes() + " bytes");
+ }
+
+ // Case 2
+ // Return the last block.
+ NameNode.stateChangeLog.info("BLOCK* allocateBlock: " +
+ "caught retry for allocation of a new block in " +
+ src + ". Returning previously allocated block " + lastBlockInFile);
+ long offset = pendingFile.computeFileSize(true);
+ onRetryBlock[0] = makeLocatedBlock(lastBlockInFile,
+ ((BlockInfoUnderConstruction)lastBlockInFile).getExpectedLocations(),
+ offset);
+ return inodesInPath;
+ } else {
+ // Case 3
+ throw new IOException("Cannot allocate block in " + src + ": " +
+ "passed 'previous' block " + previous + " does not match actual " +
+ "last block in file " + lastBlockInFile);
+ }
+ }
+
+ // Check if the penultimate block is minimally replicated
+ if (!checkFileProgress(pendingFile, false)) {
+ throw new NotReplicatedYetException("Not replicated yet: " + src);
+ }
+ return inodesInPath;
+ }
+
+ LocatedBlock makeLocatedBlock(Block blk,
+ DatanodeInfo[] locs,
+ long offset) throws IOException {
+ LocatedBlock lBlk = new LocatedBlock(
+ getExtendedBlock(blk), locs, offset);
+ getBlockManager().setBlockToken(
+ lBlk, BlockTokenSecretManager.AccessMode.WRITE);
+ return lBlk;
}
/** @see NameNode#getAdditionalDatanode(String, ExtendedBlock, DatanodeInfo[], DatanodeInfo[], int, String) */
@@ -2424,14 +2494,17 @@ public class FSNamesystem implements Nam
}
// make sure that we still have the lease on this file.
- private INodeFileUnderConstruction checkLease(String src, String holder)
- throws LeaseExpiredException, UnresolvedLinkException {
+ private INodeFileUnderConstruction checkLease(String src, String holder)
+ throws LeaseExpiredException, UnresolvedLinkException,
+ FileNotFoundException {
assert hasReadOrWriteLock();
- return checkLease(src, holder, dir.getINode(src));
+ return checkLease(src, INodeId.GRANDFATHER_INODE_ID, holder,
+ dir.getINode(src));
}
-
- private INodeFileUnderConstruction checkLease(String src, String holder,
- INode file) throws LeaseExpiredException {
+
+ private INodeFileUnderConstruction checkLease(String src, long fileId,
+ String holder, INode file) throws LeaseExpiredException,
+ FileNotFoundException {
assert hasReadOrWriteLock();
if (file == null || !(file instanceof INodeFile)) {
Lease lease = leaseManager.getLease(holder);
@@ -2452,6 +2525,7 @@ public class FSNamesystem implements Nam
throw new LeaseExpiredException("Lease mismatch on " + src + " owned by "
+ pendingFile.getClientName() + " but is accessed by " + holder);
}
+ INodeId.checkId(fileId, pendingFile);
return pendingFile;
}
@@ -2528,22 +2602,33 @@ public class FSNamesystem implements Nam
}
/**
- * Allocate a block at the given pending filename
+ * Save allocated block at the given pending filename
*
* @param src path to the file
* @param inodesInPath representing each of the components of src.
* The last INode is the INode for the file.
* @throws QuotaExceededException If addition of block exceeds space quota
*/
- private Block allocateBlock(String src, INodesInPath inodesInPath,
- DatanodeDescriptor targets[]) throws IOException {
+ BlockInfo saveAllocatedBlock(String src, INodesInPath inodesInPath,
+ Block newBlock, DatanodeDescriptor targets[]) throws IOException {
+ assert hasWriteLock();
+ BlockInfo b = dir.addBlock(src, inodesInPath, newBlock, targets);
+ NameNode.stateChangeLog.info("BLOCK* allocateBlock: " + src + ". "
+ + getBlockPoolId() + " " + b);
+ for (DatanodeDescriptor dn : targets) {
+ dn.incBlocksScheduled();
+ }
+ return b;
+ }
+
+ /**
+ * Create new block with a unique block id and a new generation stamp.
+ */
+ Block createNewBlock() throws IOException {
assert hasWriteLock();
Block b = new Block(getFSImage().getUniqueBlockId(), 0, 0);
// Increment the generation stamp for every new block.
b.setGenerationStamp(nextGenerationStamp());
- b = dir.addBlock(src, inodesInPath, b, targets);
- NameNode.stateChangeLog.info("BLOCK* allocateBlock: " + src + ". "
- + blockPoolId + " " + b);
return b;
}
@@ -5582,7 +5667,7 @@ public class FSNamesystem implements Nam
@Override
public boolean isAvoidingStaleDataNodesForWrite() {
return this.blockManager.getDatanodeManager()
- .isAvoidingStaleDataNodesForWrite();
+ .shouldAvoidStaleDataNodesForWrite();
}
/**
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeId.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeId.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeId.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeId.java Sat Feb 16 01:12:07 2013
@@ -17,18 +17,21 @@
*/
package org.apache.hadoop.hdfs.server.namenode;
+import java.io.FileNotFoundException;
+
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.util.SequentialNumber;
/**
- * An id which uniquely identifies an inode
+ * An id which uniquely identifies an inode. Id 1 to 1000 are reserved for
+ * potential future usage. The id won't be recycled and is not expected to wrap
+ * around in a very long time. Root inode id is always 1001. Id 0 is used for
+ * backward compatibility support.
*/
@InterfaceAudience.Private
-class INodeId extends SequentialNumber {
+public class INodeId extends SequentialNumber {
/**
- * The last reserved inode id. Reserve id 1 to 1000 for potential future
- * usage. The id won't be recycled and is not expected to wrap around in a
- * very long time. Root inode id will be 1001.
+ * The last reserved inode id.
*/
public static final long LAST_RESERVED_ID = 1000L;
@@ -38,6 +41,19 @@ class INodeId extends SequentialNumber {
*/
public static final long GRANDFATHER_INODE_ID = 0;
+ /**
+ * To check if the request id is the same as saved id. Don't check fileId
+ * with GRANDFATHER_INODE_ID for backward compatibility.
+ */
+ public static void checkId(long requestId, INode inode)
+ throws FileNotFoundException {
+ if (requestId != GRANDFATHER_INODE_ID && requestId != inode.getId()) {
+ throw new FileNotFoundException(
+ "ID mismatch. Request id and saved id: " + requestId + " , "
+ + inode.getId());
+ }
+ }
+
INodeId() {
super(LAST_RESERVED_ID);
}
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NNStorage.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NNStorage.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NNStorage.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NNStorage.java Sat Feb 16 01:12:07 2013
@@ -587,7 +587,7 @@ public class NNStorage extends Storage i
}
// Set Block pool ID in version with federation support
- if (LayoutVersion.supports(Feature.FEDERATION, layoutVersion)) {
+ if (versionSupportsFederation()) {
String sbpid = props.getProperty("blockpoolID");
setBlockPoolID(sd.getRoot(), sbpid);
}
@@ -634,7 +634,7 @@ public class NNStorage extends Storage i
) throws IOException {
super.setPropertiesFromFields(props, sd);
// Set blockpoolID in version with federation support
- if (LayoutVersion.supports(Feature.FEDERATION, layoutVersion)) {
+ if (versionSupportsFederation()) {
props.setProperty("blockpoolID", blockpoolID);
}
}
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java Sat Feb 16 01:12:07 2013
@@ -78,6 +78,7 @@ import org.apache.hadoop.util.ServicePlu
import org.apache.hadoop.util.StringUtils;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
@@ -781,6 +782,26 @@ public class NameNode {
}
/**
+ * Clone the supplied configuration but remove the shared edits dirs.
+ *
+ * @param conf Supplies the original configuration.
+ * @return Cloned configuration without the shared edit dirs.
+ * @throws IOException on failure to generate the configuration.
+ */
+ private static Configuration getConfigurationWithoutSharedEdits(
+ Configuration conf)
+ throws IOException {
+ List<URI> editsDirs = FSNamesystem.getNamespaceEditsDirs(conf, false);
+ String editsDirsString = Joiner.on(",").join(editsDirs);
+
+ Configuration confWithoutShared = new Configuration(conf);
+ confWithoutShared.unset(DFSConfigKeys.DFS_NAMENODE_SHARED_EDITS_DIR_KEY);
+ confWithoutShared.setStrings(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY,
+ editsDirsString);
+ return confWithoutShared;
+ }
+
+ /**
* Format a new shared edits dir and copy in enough edit log segments so that
* the standby NN can start up.
*
@@ -809,11 +830,8 @@ public class NameNode {
NNStorage existingStorage = null;
try {
- Configuration confWithoutShared = new Configuration(conf);
- confWithoutShared.unset(DFSConfigKeys.DFS_NAMENODE_SHARED_EDITS_DIR_KEY);
- FSNamesystem fsns = FSNamesystem.loadFromDisk(confWithoutShared,
- FSNamesystem.getNamespaceDirs(conf),
- FSNamesystem.getNamespaceEditsDirs(conf, false));
+ FSNamesystem fsns =
+ FSNamesystem.loadFromDisk(getConfigurationWithoutSharedEdits(conf));
existingStorage = fsns.getFSImage().getStorage();
NamespaceInfo nsInfo = existingStorage.getNamespaceInfo();
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java Sat Feb 16 01:12:07 2013
@@ -422,13 +422,10 @@ class NameNodeRpcServer implements Namen
}
@Override // ClientProtocol
- public void create(String src,
- FsPermission masked,
- String clientName,
- EnumSetWritable<CreateFlag> flag,
- boolean createParent,
- short replication,
- long blockSize) throws IOException {
+ public HdfsFileStatus create(String src, FsPermission masked,
+ String clientName, EnumSetWritable<CreateFlag> flag,
+ boolean createParent, short replication, long blockSize)
+ throws IOException {
String clientMachine = getClientMachine();
if (stateChangeLog.isDebugEnabled()) {
stateChangeLog.debug("*DIR* NameNode.create: file "
@@ -438,12 +435,13 @@ class NameNodeRpcServer implements Namen
throw new IOException("create: Pathname too long. Limit "
+ MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
}
- namesystem.startFile(src,
- new PermissionStatus(UserGroupInformation.getCurrentUser().getShortUserName(),
- null, masked),
- clientName, clientMachine, flag.get(), createParent, replication, blockSize);
+ HdfsFileStatus fileStatus = namesystem.startFile(src, new PermissionStatus(
+ UserGroupInformation.getCurrentUser().getShortUserName(), null, masked),
+ clientName, clientMachine, flag.get(), createParent, replication,
+ blockSize);
metrics.incrFilesCreated();
metrics.incrCreateFileOps();
+ return fileStatus;
}
@Override // ClientProtocol
@@ -482,26 +480,24 @@ class NameNodeRpcServer implements Namen
throws IOException {
namesystem.setOwner(src, username, groupname);
}
-
- @Override // ClientProtocol
- public LocatedBlock addBlock(String src,
- String clientName,
- ExtendedBlock previous,
- DatanodeInfo[] excludedNodes)
+
+ @Override
+ public LocatedBlock addBlock(String src, String clientName,
+ ExtendedBlock previous, DatanodeInfo[] excludedNodes, long fileId)
throws IOException {
- if(stateChangeLog.isDebugEnabled()) {
- stateChangeLog.debug("*BLOCK* NameNode.addBlock: file "
- +src+" for "+clientName);
+ if (stateChangeLog.isDebugEnabled()) {
+ stateChangeLog.debug("*BLOCK* NameNode.addBlock: file " + src
+ + " fileId=" + fileId + " for " + clientName);
}
HashMap<Node, Node> excludedNodesSet = null;
if (excludedNodes != null) {
excludedNodesSet = new HashMap<Node, Node>(excludedNodes.length);
- for (Node node:excludedNodes) {
+ for (Node node : excludedNodes) {
excludedNodesSet.put(node, node);
}
}
- LocatedBlock locatedBlock =
- namesystem.getAdditionalBlock(src, clientName, previous, excludedNodesSet);
+ LocatedBlock locatedBlock = namesystem.getAdditionalBlock(src, fileId,
+ clientName, previous, excludedNodesSet);
if (locatedBlock != null)
metrics.incrAddBlockOps();
return locatedBlock;
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeJspHelper.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeJspHelper.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeJspHelper.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeJspHelper.java Sat Feb 16 01:12:07 2013
@@ -17,12 +17,15 @@
*/
package org.apache.hadoop.hdfs.server.namenode;
+import static org.apache.hadoop.hdfs.DFSUtil.percent2String;
+
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.net.URI;
import java.net.URLEncoder;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
@@ -64,6 +67,14 @@ import org.znerd.xmlenc.XMLOutputter;
import com.google.common.base.Preconditions;
class NamenodeJspHelper {
+ static String fraction2String(double value) {
+ return StringUtils.format("%.2f", value);
+ }
+
+ static String fraction2String(long numerator, long denominator) {
+ return fraction2String(numerator/(double)denominator);
+ }
+
static String getSafeModeText(FSNamesystem fsn) {
if (!fsn.isInSafeMode())
return "";
@@ -361,20 +372,20 @@ class NamenodeJspHelper {
+ "DFS Remaining" + colTxt() + ":" + colTxt()
+ StringUtils.byteDesc(remaining) + rowTxt() + colTxt() + "DFS Used%"
+ colTxt() + ":" + colTxt()
- + StringUtils.limitDecimalTo2(percentUsed) + " %" + rowTxt()
+ + percent2String(percentUsed) + rowTxt()
+ colTxt() + "DFS Remaining%" + colTxt() + ":" + colTxt()
- + StringUtils.limitDecimalTo2(percentRemaining) + " %"
+ + percent2String(percentRemaining)
+ rowTxt() + colTxt() + "Block Pool Used" + colTxt() + ":" + colTxt()
+ StringUtils.byteDesc(bpUsed) + rowTxt()
+ colTxt() + "Block Pool Used%"+ colTxt() + ":" + colTxt()
- + StringUtils.limitDecimalTo2(percentBpUsed) + " %"
+ + percent2String(percentBpUsed)
+ rowTxt() + colTxt() + "DataNodes usages" + colTxt() + ":" + colTxt()
+ "Min %" + colTxt() + "Median %" + colTxt() + "Max %" + colTxt()
+ "stdev %" + rowTxt() + colTxt() + colTxt() + colTxt()
- + StringUtils.limitDecimalTo2(min) + " %"
- + colTxt() + StringUtils.limitDecimalTo2(median) + " %"
- + colTxt() + StringUtils.limitDecimalTo2(max) + " %"
- + colTxt() + StringUtils.limitDecimalTo2(dev) + " %"
+ + percent2String(min)
+ + colTxt() + percent2String(median)
+ + colTxt() + percent2String(max)
+ + colTxt() + percent2String(dev)
+ rowTxt() + colTxt()
+ "<a href=\"dfsnodelist.jsp?whatNodes=LIVE\">Live Nodes</a> "
+ colTxt() + ":" + colTxt() + live.size()
@@ -443,7 +454,13 @@ class NamenodeJspHelper {
nodeToRedirect = nn.getHttpAddress().getHostName();
redirectPort = nn.getHttpAddress().getPort();
}
- String addr = nn.getNameNodeAddressHostPortString();
+
+ InetSocketAddress rpcAddr = nn.getNameNodeAddress();
+ String rpcHost = rpcAddr.getAddress().isAnyLocalAddress()
+ ? URI.create(request.getRequestURL().toString()).getHost()
+ : rpcAddr.getAddress().getHostAddress();
+ String addr = rpcHost + ":" + rpcAddr.getPort();
+
String fqdn = InetAddress.getByName(nodeToRedirect).getCanonicalHostName();
redirectLocation = HttpConfig.getSchemePrefix() + fqdn + ":" + redirectPort
+ "/browseDirectory.jsp?namenodeInfoPort="
@@ -562,9 +579,9 @@ class NamenodeJspHelper {
long u = d.getDfsUsed();
long nu = d.getNonDfsUsed();
long r = d.getRemaining();
- String percentUsed = StringUtils.limitDecimalTo2(d.getDfsUsedPercent());
- String percentRemaining = StringUtils.limitDecimalTo2(d
- .getRemainingPercent());
+ final double percentUsedValue = d.getDfsUsedPercent();
+ String percentUsed = fraction2String(percentUsedValue);
+ String percentRemaining = fraction2String(d.getRemainingPercent());
String adminState = d.getAdminState().toString();
@@ -572,32 +589,30 @@ class NamenodeJspHelper {
long currentTime = Time.now();
long bpUsed = d.getBlockPoolUsed();
- String percentBpUsed = StringUtils.limitDecimalTo2(d
- .getBlockPoolUsedPercent());
+ String percentBpUsed = fraction2String(d.getBlockPoolUsedPercent());
out.print("<td class=\"lastcontact\"> "
+ ((currentTime - timestamp) / 1000)
+ "<td class=\"adminstate\">"
+ adminState
+ "<td align=\"right\" class=\"capacity\">"
- + StringUtils.limitDecimalTo2(c * 1.0 / diskBytes)
+ + fraction2String(c, diskBytes)
+ "<td align=\"right\" class=\"used\">"
- + StringUtils.limitDecimalTo2(u * 1.0 / diskBytes)
+ + fraction2String(u, diskBytes)
+ "<td align=\"right\" class=\"nondfsused\">"
- + StringUtils.limitDecimalTo2(nu * 1.0 / diskBytes)
+ + fraction2String(nu, diskBytes)
+ "<td align=\"right\" class=\"remaining\">"
- + StringUtils.limitDecimalTo2(r * 1.0 / diskBytes)
+ + fraction2String(r, diskBytes)
+ "<td align=\"right\" class=\"pcused\">"
+ percentUsed
+ "<td class=\"pcused\">"
- + ServletUtil.percentageGraph((int) Double.parseDouble(percentUsed),
- 100)
+ + ServletUtil.percentageGraph((int)percentUsedValue, 100)
+ "<td align=\"right\" class=\"pcremaining\">"
+ percentRemaining
+ "<td title=" + "\"blocks scheduled : "
+ d.getBlocksScheduled() + "\" class=\"blocks\">" + d.numBlocks()+"\n"
+ "<td align=\"right\" class=\"bpused\">"
- + StringUtils.limitDecimalTo2(bpUsed * 1.0 / diskBytes)
+ + fraction2String(bpUsed, diskBytes)
+ "<td align=\"right\" class=\"pcbpused\">"
+ percentBpUsed
+ "<td align=\"right\" class=\"volfails\">"
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java Sat Feb 16 01:12:07 2013
@@ -475,14 +475,20 @@ public class SecondaryNameNode implement
// Returns a token that would be used to upload the merged image.
CheckpointSignature sig = namenode.rollEditLog();
- if ((checkpointImage.getNamespaceID() == 0) ||
- (sig.isSameCluster(checkpointImage) &&
+ boolean loadImage = false;
+ boolean isFreshCheckpointer = (checkpointImage.getNamespaceID() == 0);
+ boolean isSameCluster =
+ (dstStorage.versionSupportsFederation() && sig.isSameCluster(checkpointImage)) ||
+ (!dstStorage.versionSupportsFederation() && sig.namespaceIdMatches(checkpointImage));
+ if (isFreshCheckpointer ||
+ (isSameCluster &&
!sig.storageVersionMatches(checkpointImage.getStorage()))) {
// if we're a fresh 2NN, or if we're on the same cluster and our storage
// needs an upgrade, just take the storage info from the server.
dstStorage.setStorageInfo(sig);
dstStorage.setClusterID(sig.getClusterID());
dstStorage.setBlockPoolID(sig.getBlockpoolID());
+ loadImage = true;
}
sig.validateStorageInfo(checkpointImage);
@@ -492,7 +498,7 @@ public class SecondaryNameNode implement
RemoteEditLogManifest manifest =
namenode.getEditLogManifest(sig.mostRecentCheckpointTxId + 1);
- boolean loadImage = downloadCheckpointFiles(
+ loadImage |= downloadCheckpointFiles(
fsName, checkpointImage, sig, manifest); // Fetch fsimage and edits
doMerge(sig, manifest, loadImage, checkpointImage, namesystem);
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java Sat Feb 16 01:12:07 2013
@@ -316,8 +316,7 @@ public class DFSAdmin extends FsShell {
System.out.println("DFS Used: " + used
+ " (" + StringUtils.byteDesc(used) + ")");
System.out.println("DFS Used%: "
- + StringUtils.limitDecimalTo2(((1.0 * used) / presentCapacity) * 100)
- + "%");
+ + StringUtils.formatPercent(used/(double)presentCapacity, 2));
/* These counts are not always upto date. They are updated after
* iteration of an internal list. Should be updated in a few seconds to
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java Sat Feb 16 01:12:07 2013
@@ -219,6 +219,7 @@ public class JsonUtil {
m.put("modificationTime", status.getModificationTime());
m.put("blockSize", status.getBlockSize());
m.put("replication", status.getReplication());
+ m.put("fileId", status.getFileId());
return includeType ? toJsonString(FileStatus.class, m): JSON.toString(m);
}
@@ -243,9 +244,10 @@ public class JsonUtil {
final long mTime = (Long) m.get("modificationTime");
final long blockSize = (Long) m.get("blockSize");
final short replication = (short) (long) (Long) m.get("replication");
+ final long fileId = (Long) m.get("fileId");
return new HdfsFileStatus(len, type == PathType.DIRECTORY, replication,
blockSize, mTime, aTime, permission, owner, group,
- symlink, DFSUtil.string2Bytes(localName));
+ symlink, DFSUtil.string2Bytes(localName), fileId);
}
/** Convert an ExtendedBlock to a Json map. */
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/ConcatSourcesParam.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/ConcatSourcesParam.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/ConcatSourcesParam.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/ConcatSourcesParam.java Sat Feb 16 01:12:07 2013
@@ -21,7 +21,7 @@ package org.apache.hadoop.hdfs.web.resou
/** The concat source paths parameter. */
public class ConcatSourcesParam extends StringParam {
/** Parameter name. */
- public static final String NAME = "srcs";
+ public static final String NAME = "sources";
public static final String DEFAULT = NULL;
Propchange: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/native/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/native:r1440578-1446830
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/ClientNamenodeProtocol.proto
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/ClientNamenodeProtocol.proto?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/ClientNamenodeProtocol.proto (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/ClientNamenodeProtocol.proto Sat Feb 16 01:12:07 2013
@@ -67,7 +67,8 @@ message CreateRequestProto {
required uint64 blockSize = 7;
}
-message CreateResponseProto { // void response
+message CreateResponseProto {
+ optional HdfsFileStatusProto fs = 1;
}
message AppendRequestProto {
@@ -119,6 +120,7 @@ message AddBlockRequestProto {
required string clientName = 2;
optional ExtendedBlockProto previous = 3;
repeated DatanodeInfoProto excludeNodes = 4;
+ optional uint64 fileId = 5 [default = 0]; // default as a bogus id
}
message AddBlockResponseProto {
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/hdfs.proto
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/hdfs.proto?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/hdfs.proto (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/hdfs.proto Sat Feb 16 01:12:07 2013
@@ -170,6 +170,9 @@ message HdfsFileStatusProto {
optional uint32 block_replication = 10 [default = 0]; // only 16bits used
optional uint64 blocksize = 11 [default = 0];
optional LocatedBlocksProto locations = 12; // suppled only if asked by client
+
+ // Optional field for fileId
+ optional uint64 fileId = 13 [default = 0]; // default as an invalid id
}
/**
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml Sat Feb 16 01:12:07 2013
@@ -999,17 +999,14 @@
</property>
<property>
- <name>dfs.namenode.check.stale.datanode</name>
+ <name>dfs.namenode.avoid.read.stale.datanode</name>
<value>false</value>
<description>
- Indicate whether or not to check "stale" datanodes whose
+ Indicate whether or not to avoid reading from "stale" datanodes whose
heartbeat messages have not been received by the namenode
- for more than a specified time interval. If this configuration
- parameter is set as true, the system will keep track
- of the number of stale datanodes. The stale datanodes will be
+ for more than a specified time interval. Stale datanodes will be
moved to the end of the node list returned for reading. See
- dfs.namenode.avoid.write.stale.datanode for details on how this
- affects writes.
+ dfs.namenode.avoid.write.stale.datanode for a similar setting for writes.
</description>
</property>
@@ -1017,13 +1014,13 @@
<name>dfs.namenode.avoid.write.stale.datanode</name>
<value>false</value>
<description>
- Indicate whether or not to avoid writing to "stale" datanodes whose
+ Indicate whether or not to avoid writing to "stale" datanodes whose
heartbeat messages have not been received by the namenode
- for more than a specified time interval. If this configuration
- parameter and dfs.namenode.check.stale.datanode are both set as true,
- the writing will avoid using stale datanodes unless a high number
- of datanodes are marked as stale. See
- dfs.namenode.write.stale.datanode.ratio for details.
+ for more than a specified time interval. Writes will avoid using
+ stale datanodes unless more than a configured ratio
+ (dfs.namenode.write.stale.datanode.ratio) of datanodes are marked as
+ stale. See dfs.namenode.avoid.read.stale.datanode for a similar setting
+ for reads.
</description>
</property>
Propchange: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode:r1440578-1446830
Propchange: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs:r1440578-1446830
Propchange: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/secondary/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/secondary:r1440578-1446830
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/site/apt/WebHDFS.apt.vm
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/site/apt/WebHDFS.apt.vm?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/site/apt/WebHDFS.apt.vm (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/site/apt/WebHDFS.apt.vm Sat Feb 16 01:12:07 2013
@@ -109,6 +109,9 @@ WebHDFS REST API
* {{{Append to a File}<<<APPEND>>>}}
(see {{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.append)
+ * {{{Concat File(s)}<<<CONCAT>>>}}
+ (see {{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.concat)
+
* HTTP DELETE
* {{{Delete a File/Directory}<<<DELETE>>>}}
@@ -299,6 +302,32 @@ Content-Length: 0
{{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.append
+** {Concat File(s)}
+
+ * Submit a HTTP POST request.
+
++---------------------------------
+curl -i -X POST "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=CONCAT&sources=<SOURCES>"
++---------------------------------
+
+ The client receives a response with zero content length:
+
++---------------------------------
+HTTP/1.1 200 OK
+Content-Length: 0
++---------------------------------
+
+ []
+
+ This REST API call is available as of Hadoop version 2.0.3.
+ Please note that <SOURCES> is a comma seperated list of absolute paths.
+ (Example: sources=/test/file1,/test/file2,/test/file3)
+
+ See also:
+ {{{Sources}<<<sources>>>}},
+ {{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.concat
+
+
** {Open and Read a File}
* Submit a HTTP GET request with automatically following redirects.
@@ -1727,6 +1756,29 @@ var tokenProperties =
{{{Set Replication Factor}<<<SETREPLICATION>>>}}
+** {Sources}
+
+*----------------+-------------------------------------------------------------------+
+|| Name | <<<sources>>> |
+*----------------+-------------------------------------------------------------------+
+|| Description | The comma seperated absolute paths used for concatenation. |
+*----------------+-------------------------------------------------------------------+
+|| Type | String |
+*----------------+-------------------------------------------------------------------+
+|| Default Value | \<empty\> |
+*----------------+-------------------------------------------------------------------+
+|| Valid Values | A list of comma seperated absolute FileSystem paths without scheme and authority. |
+*----------------+-------------------------------------------------------------------+
+|| Syntax | See the note in {{Delegation}}. |
+*----------------+-------------------------------------------------------------------+
+
+ <<Note>> that sources are absolute FileSystem paths.
+
+
+ See also:
+ {{{Concat File(s)}<<<CONCAT>>>}}
+
+
** {Token}
*----------------+-------------------------------------------------------------------+
Propchange: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/test/hdfs/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/hdfs:r1440578-1446830
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/DFSTestUtil.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/DFSTestUtil.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/DFSTestUtil.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/DFSTestUtil.java Sat Feb 16 01:12:07 2013
@@ -33,6 +33,7 @@ import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
+import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URL;
@@ -620,6 +621,9 @@ public class DFSTestUtil {
*/
public static byte[] urlGetBytes(URL url) throws IOException {
URLConnection conn = url.openConnection();
+ HttpURLConnection hc = (HttpURLConnection)conn;
+
+ assertEquals(HttpURLConnection.HTTP_OK, hc.getResponseCode());
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copyBytes(conn.getInputStream(), out, 4096, true);
return out.toByteArray();
Modified: hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java?rev=1446832&r1=1446831&r2=1446832&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java (original)
+++ hadoop/common/branches/HDFS-347/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java Sat Feb 16 01:12:07 2013
@@ -23,22 +23,34 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
+import javax.net.SocketFactory;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider;
import org.apache.hadoop.hdfs.server.namenode.ha.HATestUtil;
+import org.apache.hadoop.io.IOUtils;
+import org.apache.hadoop.net.ConnectTimeoutException;
+import org.apache.hadoop.net.StandardSocketFactory;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.StringUtils;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
public class TestDFSClientFailover {
@@ -92,6 +104,63 @@ public class TestDFSClientFailover {
}
/**
+ * Test that even a non-idempotent method will properly fail-over if the
+ * first IPC attempt times out trying to connect. Regression test for
+ * HDFS-4404.
+ */
+ @Test
+ public void testFailoverOnConnectTimeout() throws Exception {
+ conf.setClass(CommonConfigurationKeysPublic.HADOOP_RPC_SOCKET_FACTORY_CLASS_DEFAULT_KEY,
+ InjectingSocketFactory.class, SocketFactory.class);
+ // Set up the InjectingSocketFactory to throw a ConnectTimeoutException
+ // when connecting to the first NN.
+ InjectingSocketFactory.portToInjectOn = cluster.getNameNodePort(0);
+
+ FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf);
+
+ // Make the second NN the active one.
+ cluster.shutdownNameNode(0);
+ cluster.transitionToActive(1);
+
+ // Call a non-idempotent method, and ensure the failover of the call proceeds
+ // successfully.
+ IOUtils.closeStream(fs.create(TEST_FILE));
+ }
+
+ private static class InjectingSocketFactory extends StandardSocketFactory {
+
+ static SocketFactory defaultFactory = SocketFactory.getDefault();
+
+ static int portToInjectOn;
+
+ @Override
+ public Socket createSocket() throws IOException {
+ Socket spy = Mockito.spy(defaultFactory.createSocket());
+ // Simplify our spying job by not having to also spy on the channel
+ Mockito.doReturn(null).when(spy).getChannel();
+ // Throw a ConnectTimeoutException when connecting to our target "bad"
+ // host.
+ Mockito.doThrow(new ConnectTimeoutException("injected"))
+ .when(spy).connect(
+ Mockito.argThat(new MatchesPort()),
+ Mockito.anyInt());
+ return spy;
+ }
+
+ private class MatchesPort extends BaseMatcher<SocketAddress> {
+ @Override
+ public boolean matches(Object arg0) {
+ return ((InetSocketAddress)arg0).getPort() == portToInjectOn;
+ }
+
+ @Override
+ public void describeTo(Description desc) {
+ desc.appendText("matches port " + portToInjectOn);
+ }
+ }
+ }
+
+ /**
* Regression test for HDFS-2683.
*/
@Test