You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ha...@apache.org on 2009/02/19 22:48:16 UTC
svn commit: r746010 - in /hadoop/core/trunk: CHANGES.txt
src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
src/test/org/apache/hadoop/hdfs/TestDatanodeBlockScanner.java
src/test/org/apache/hadoop/hdfs/TestReplication.java
Author: hairong
Date: Thu Feb 19 21:48:16 2009
New Revision: 746010
URL: http://svn.apache.org/viewvc?rev=746010&view=rev
Log:
HADOOP-4692. NameNode in infinite loop for replicating/deleting corrupt blocks. Constributed by Hairong Kuang.
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestDatanodeBlockScanner.java
hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestReplication.java
Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=746010&r1=746009&r2=746010&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Thu Feb 19 21:48:16 2009
@@ -795,6 +795,9 @@
HADOOP-5254. The Configuration class should be able to work with XML
parsers that do not support xmlinclude. (Steve Loughran via dhruba)
+ HADOOP-4692. Namenode in infinite loop for replicating/deleting corrupt
+ blocks. (hairong)
+
Release 0.19.1 - Unreleased
IMPROVEMENTS
Modified: hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java?rev=746010&r1=746009&r2=746010&view=diff
==============================================================================
--- hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java (original)
+++ hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java Thu Feb 19 21:48:16 2009
@@ -925,6 +925,7 @@
DatanodeInfo xferTargets[]
) throws IOException {
if (!data.isValidBlock(block)) {
+ // block does not exist or is under-construction
String errStr = "Can't send invalid block " + block;
LOG.info(errStr);
namenode.errorReport(dnRegistration,
@@ -933,6 +934,19 @@
return;
}
+ // Check if NN recorded length matches on-disk length
+ long onDiskLength = data.getLength(block);
+ if (block.getNumBytes() > onDiskLength) {
+ // Shorter on-disk len indicates corruption so report NN the corrupt block
+ namenode.reportBadBlocks(new LocatedBlock[]{
+ new LocatedBlock(block, new DatanodeInfo[] {
+ new DatanodeInfo(dnRegistration)})});
+ LOG.info("Can't replicate block " + block
+ + " because on-disk length " + onDiskLength
+ + " is shorter than NameNode recorded length " + block.getNumBytes());
+ return;
+ }
+
int numTargets = xferTargets.length;
if (numTargets > 0) {
if (LOG.isInfoEnabled()) {
@@ -1113,7 +1127,7 @@
out = new DataOutputStream(new BufferedOutputStream(baseStream,
SMALL_BUFFER_SIZE));
- blockSender = new BlockSender(b, 0, -1, false, false, false,
+ blockSender = new BlockSender(b, 0, b.getNumBytes(), false, false, false,
datanode);
DatanodeInfo srcNode = new DatanodeInfo(dnRegistration);
Modified: hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestDatanodeBlockScanner.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestDatanodeBlockScanner.java?rev=746010&r1=746009&r2=746010&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestDatanodeBlockScanner.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestDatanodeBlockScanner.java Thu Feb 19 21:48:16 2009
@@ -400,7 +400,7 @@
String block = DFSTestUtil.getFirstBlock(fs, fileName).getBlockName();
// Truncate replica of block
- truncateReplica(block, 0);
+ changeReplicaLength(block, 0, -1);
cluster.shutdown();
@@ -421,18 +421,22 @@
}
}
- private static void truncateReplica(String blockName, int dnIndex) throws IOException {
+ /**
+ * Change the length of a block at datanode dnIndex
+ */
+ static boolean changeReplicaLength(String blockName, int dnIndex, int lenDelta) throws IOException {
File baseDir = new File(System.getProperty("test.build.data"), "dfs/data");
for (int i=dnIndex*2; i<dnIndex*2+2; i++) {
File blockFile = new File(baseDir, "data" + (i+1)+ "/current/" +
blockName);
if (blockFile.exists()) {
RandomAccessFile raFile = new RandomAccessFile(blockFile, "rw");
- raFile.setLength(raFile.length()-1);
+ raFile.setLength(raFile.length()+lenDelta);
raFile.close();
- break;
+ return true;
}
}
+ return false;
}
private static void waitForBlockDeleted(String blockName, int dnIndex)
Modified: hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestReplication.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestReplication.java?rev=746010&r1=746009&r2=746010&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestReplication.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestReplication.java Thu Feb 19 21:48:16 2009
@@ -388,7 +388,66 @@
if (cluster != null) {
cluster.shutdown();
}
+ }
+ }
+
+ /**
+ * Test if replication can detect mismatched length on-disk blocks
+ * @throws Exception
+ */
+ public void testReplicateLenMismatchedBlock() throws Exception {
+ MiniDFSCluster cluster = new MiniDFSCluster(new Configuration(), 2, true, null);
+ try {
+ cluster.waitActive();
+ // test truncated block
+ changeBlockLen(cluster, -1);
+ // test extended block
+ changeBlockLen(cluster, 1);
+ } finally {
+ cluster.shutdown();
}
- }
+ }
+ private void changeBlockLen(MiniDFSCluster cluster,
+ int lenDelta) throws IOException, InterruptedException {
+ final Path fileName = new Path("/file1");
+ final short REPLICATION_FACTOR = (short)1;
+ final FileSystem fs = cluster.getFileSystem();
+ final int fileLen = fs.getConf().getInt("io.bytes.per.checksum", 512);
+ DFSTestUtil.createFile(fs, fileName, fileLen, REPLICATION_FACTOR, 0);
+ DFSTestUtil.waitReplication(fs, fileName, REPLICATION_FACTOR);
+
+ String block = DFSTestUtil.getFirstBlock(fs, fileName).getBlockName();
+
+ // Change the length of a replica
+ for (int i=0; i<cluster.getDataNodes().size(); i++) {
+ if (TestDatanodeBlockScanner.changeReplicaLength(block, i, lenDelta)) {
+ break;
+ }
+ }
+
+ // increase the file's replication factor
+ fs.setReplication(fileName, (short)(REPLICATION_FACTOR+1));
+
+ // block replication triggers corrupt block detection
+ DFSClient dfsClient = new DFSClient(new InetSocketAddress("localhost",
+ cluster.getNameNodePort()), fs.getConf());
+ LocatedBlocks blocks = dfsClient.namenode.getBlockLocations(
+ fileName.toString(), 0, fileLen);
+ if (lenDelta < 0) { // replica truncated
+ while (!blocks.get(0).isCorrupt() ||
+ REPLICATION_FACTOR != blocks.get(0).getLocations().length) {
+ Thread.sleep(100);
+ blocks = dfsClient.namenode.getBlockLocations(
+ fileName.toString(), 0, fileLen);
+ }
+ } else { // no corruption detected; block replicated
+ while (REPLICATION_FACTOR+1 != blocks.get(0).getLocations().length) {
+ Thread.sleep(100);
+ blocks = dfsClient.namenode.getBlockLocations(
+ fileName.toString(), 0, fileLen);
+ }
+ }
+ fs.delete(fileName, true);
+ }
}