浏览代码

HDFS-1072. Fix TestReadWhileWriting failure. Contributed by Erik Steffl.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hdfs/trunk@933426 13f79535-47bb-0310-9956-ffa450edef68
Konstantin Shvachko 15 年之前
父节点
当前提交
ecf96237d9

+ 15 - 6
src/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -1206,12 +1206,21 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean, FSClusterSt
                 "Failed to close file " + src +
                 ". Lease recovery is in progress. Try again later.");
 
-        } else
-          throw new AlreadyBeingCreatedException("failed to create file " +
-              src + " for " + holder + " on client " + clientMachine + 
-              ", because this file is already being created by " +
-              pendingFile.getClientName() + 
-              " on " + pendingFile.getClientMachine());
+        } else {
+          if(pendingFile.getLastBlock().getBlockUCState() ==
+            BlockUCState.UNDER_RECOVERY) {
+            throw new RecoveryInProgressException(
+              "Recovery in progress, file [" + src + "], " +
+              "lease owner [" + lease.getHolder() + "]");
+            } else {
+              throw new AlreadyBeingCreatedException(
+                "Failed to create file [" + src + "] for [" + holder +
+                "] on client [" + clientMachine +
+                "], because this file is already being created by [" +
+                pendingFile.getClientName() + "] on [" +
+                pendingFile.getClientMachine() + "]");
+            }
+         }
       }
 
       try {

+ 6 - 3
src/test/hdfs/org/apache/hadoop/hdfs/TestReadWhileWriting.java

@@ -45,7 +45,10 @@ public class TestReadWhileWriting {
   private static final String DIR = "/"
       + TestReadWhileWriting.class.getSimpleName() + "/";
   private static final int BLOCK_SIZE = 8192;
-  private static final long LEASE_LIMIT = 500;
+  // soft limit is short and hard limit is long, to test that
+  // another thread can lease file after soft limit expired
+  private static final long SOFT_LEASE_LIMIT = 500;
+  private static final long HARD_LEASE_LIMIT = 1000*600; 
   
   /** Test reading while writing. */
   @Test
@@ -59,7 +62,7 @@ public class TestReadWhileWriting {
     final MiniDFSCluster cluster = new MiniDFSCluster(conf, 3, true, null);
     try {
       //change the lease limits.
-      cluster.setLeasePeriod(LEASE_LIMIT, LEASE_LIMIT);
+      cluster.setLeasePeriod(SOFT_LEASE_LIMIT, HARD_LEASE_LIMIT);
 
       //wait for the cluster
       cluster.waitActive();
@@ -89,7 +92,7 @@ public class TestReadWhileWriting {
       //c. On M1, append another half block of data.  Close file on M1.
       {
         //sleep to let the lease is expired.
-        Thread.sleep(2*LEASE_LIMIT);
+        Thread.sleep(2*SOFT_LEASE_LIMIT);
   
         final DistributedFileSystem dfs = (DistributedFileSystem)FileSystem.newInstance(conf);
         final FSDataOutputStream out = append(dfs, p);