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 ha...@apache.org on 2010/11/17 06:49:32 UTC

svn commit: r1035924 - in /hadoop/hdfs/trunk: CHANGES.txt src/java/org/apache/hadoop/hdfs/DFSUtil.java src/test/hdfs/org/apache/hadoop/hdfs/TestDFSUtil.java

Author: hairong
Date: Wed Nov 17 05:49:32 2010
New Revision: 1035924

URL: http://svn.apache.org/viewvc?rev=1035924&view=rev
Log:
HDFS-1483. DFSClient.getBlockLocations returns BlockLocations with no indication that the corresponding blocks are corrupt. Contributed by Patrick Kling.

Added:
    hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSUtil.java
Modified:
    hadoop/hdfs/trunk/CHANGES.txt
    hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSUtil.java

Modified: hadoop/hdfs/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=1035924&r1=1035923&r2=1035924&view=diff
==============================================================================
--- hadoop/hdfs/trunk/CHANGES.txt (original)
+++ hadoop/hdfs/trunk/CHANGES.txt Wed Nov 17 05:49:32 2010
@@ -50,12 +50,6 @@ Trunk (unreleased changes)
     HDFS-895. Allow hflush/sync to occur in parallel with new writes
     to the file. (Todd Lipcon via hairong)
 
-    HDFS-1500. TestOfflineImageViewer failing on trunk. (Todd Lipcon
-    via hairong)
-
-    HDFS-1467. Append pipeline construction not succeeds with more than
-    one replica. (Todd Lipcon via hairong)
-
   IMPROVEMENTS
 
     HDFS-1304. Add a new unit test for HftpFileSystem.open(..).  (szetszwo)
@@ -209,6 +203,15 @@ Trunk (unreleased changes)
     HDFS-718. Configuration parameter to prevent accidental formatting of 
     HDFS filesystem. (Andrew Ryan via jghoman)
 
+    HDFS-1500. TestOfflineImageViewer failing on trunk. (Todd Lipcon
+    via hairong)
+
+    HDFS-1467. Append pipeline construction not succeeds with more than
+    one replica. (Todd Lipcon via hairong)
+
+    HDFS-1483. DFSClient.getBlockLocations should indicate if corresponding
+    blocks are corrupt. (Patrick Kling via hairong)
+
   OPTIMIZATIONS
 
     HDFS-1140. Speedup INode.getPathComponents. (Dmytro Molkov via shv)

Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSUtil.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSUtil.java?rev=1035924&r1=1035923&r2=1035924&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSUtil.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSUtil.java Wed Nov 17 05:49:32 2010
@@ -220,7 +220,8 @@ public class DFSUtil {
       }
       blkLocations[idx] = new BlockLocation(names, hosts, racks,
                                             blk.getStartOffset(),
-                                            blk.getBlockSize());
+                                            blk.getBlockSize(),
+                                            blk.isCorrupt());
       idx++;
     }
     return blkLocations;

Added: hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSUtil.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSUtil.java?rev=1035924&view=auto
==============================================================================
--- hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSUtil.java (added)
+++ hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSUtil.java Wed Nov 17 05:49:32 2010
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdfs;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
+import org.apache.hadoop.hdfs.protocol.LocatedBlock;
+import org.apache.hadoop.hdfs.protocol.Block;
+import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
+import org.apache.hadoop.fs.BlockLocation;
+
+public class TestDFSUtil {
+  /**
+   * Test conversion of LocatedBlock to BlockLocation
+   */
+  @Test
+  public void testLocatedBlocks2Locations() {
+    DatanodeInfo d = new DatanodeInfo();
+    DatanodeInfo[] ds = new DatanodeInfo[1];
+    ds[0] = d;
+
+    // ok
+    Block b1 = new Block(1, 1, 1);
+    LocatedBlock l1 = new LocatedBlock(b1, ds, 0, false);
+
+    // corrupt
+    Block b2 = new Block(2, 1, 1);
+    LocatedBlock l2 = new LocatedBlock(b2, ds, 0, true);
+
+    List<LocatedBlock> ls = Arrays.asList(l1, l2);
+    LocatedBlocks lbs = new LocatedBlocks(10, false, ls, l2, true);
+
+    BlockLocation[] bs = DFSUtil.locatedBlocks2Locations(lbs);
+
+    assertTrue("expected 2 blocks but got " + bs.length,
+               bs.length == 2);
+
+    int corruptCount = 0;
+    for (BlockLocation b: bs) {
+      if (b.isCorrupt()) {
+        corruptCount++;
+      }
+    }
+
+    assertTrue("expected 1 corrupt files but got " + corruptCount, 
+               corruptCount == 1);
+  }
+}
\ No newline at end of file