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 sz...@apache.org on 2011/04/02 00:43:29 UTC

svn commit: r1087926 - in /hadoop/common/branches/branch-0.20-security: CHANGES.txt src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java src/test/org/apache/hadoop/hdfs/TestQuota.java

Author: szetszwo
Date: Fri Apr  1 22:43:29 2011
New Revision: 1087926

URL: http://svn.apache.org/viewvc?rev=1087926&view=rev
Log:
HDFS-1189. Quota counts missed between clear quota and set quota.  Contributed by John George

Modified:
    hadoop/common/branches/branch-0.20-security/CHANGES.txt
    hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
    hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestQuota.java

Modified: hadoop/common/branches/branch-0.20-security/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/CHANGES.txt?rev=1087926&r1=1087925&r2=1087926&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.20-security/CHANGES.txt Fri Apr  1 22:43:29 2011
@@ -33,6 +33,9 @@ Release 0.20.204.0 - unreleased
 
     HADOOP-7215. RPC clients must use network interface corresponding to 
     the host in the client's kerberos principal key. (suresh)
+
+    HDFS-1189. Quota counts missed between clear quota and set quota.
+    (John George via szetszwo)
   
   IMPROVEMENTS
 

Modified: hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java?rev=1087926&r1=1087925&r2=1087926&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java (original)
+++ hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java Fri Apr  1 22:43:29 2011
@@ -1296,6 +1296,13 @@ class FSDirectory implements FSConstants
       if (dirNode instanceof INodeDirectoryWithQuota) { 
         // a directory with quota; so set the quota to the new value
         ((INodeDirectoryWithQuota)dirNode).setQuota(nsQuota, dsQuota);
+        if (!dirNode.isQuotaSet()) {
+          // will not come here for root because root's nsQuota is always set
+          INodeDirectory newNode = new INodeDirectory(dirNode);
+          INodeDirectory parent = (INodeDirectory)inodes[inodes.length-2];
+          dirNode = newNode;
+          parent.replaceChild(newNode);
+        }
       } else {
         // a non-quota directory; so replace it with a directory with quota
         INodeDirectoryWithQuota newNode = 

Modified: hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestQuota.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestQuota.java?rev=1087926&r1=1087925&r2=1087926&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestQuota.java (original)
+++ hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestQuota.java Fri Apr  1 22:43:29 2011
@@ -59,7 +59,8 @@ public class TestQuota extends TestCase 
     final Configuration conf = new Configuration();
     // set a smaller block size so that we can test with smaller 
     // Space quotas
-    conf.set("dfs.block.size", "512");
+    final int DEFAULT_BLOCK_SIZE = 512;
+    conf.setLong("dfs.block.size", DEFAULT_BLOCK_SIZE);
     conf.setBoolean("dfs.support.append", true);
     final MiniDFSCluster cluster = new MiniDFSCluster(conf, 2, true, null);
     final FileSystem fs = cluster.getFileSystem();
@@ -273,6 +274,60 @@ public class TestQuota extends TestCase 
 
       // 20: setQuota on the root directory ("/") should succeed
       runCommand(admin, false, "-setQuota", "1000000", "/");
+ 
+      runCommand(admin, true, "-clrQuota", "/");
+      runCommand(admin, false, "-clrSpaceQuota", "/");
+      runCommand(admin, new String[]{"-clrQuota", parent.toString()}, false);
+      runCommand(admin, false, "-clrSpaceQuota", parent.toString());
+ 
+ 
+      // 2: create directory /test/data2
+      final Path childDir2 = new Path(parent, "data2");
+      assertTrue(dfs.mkdirs(childDir2));
+
+
+      final Path childFile2 = new Path(childDir2, "datafile2");
+      final Path childFile3 = new Path(childDir2, "datafile3");
+      final long spaceQuota2 = DEFAULT_BLOCK_SIZE * replication;
+      final long fileLen2 = DEFAULT_BLOCK_SIZE;
+      // set space quota to a real low value 
+      runCommand(admin, false, "-setSpaceQuota", Long.toString(spaceQuota2), childDir2.toString());
+      // clear space quota
+      runCommand(admin, false, "-clrSpaceQuota", childDir2.toString());
+      // create a file that is greater than the size of space quota
+      DFSTestUtil.createFile(fs, childFile2, fileLen2, replication, 0);
+
+      // now set space quota again. This should succeed
+      runCommand(admin, false, "-setSpaceQuota", Long.toString(spaceQuota2), childDir2.toString());
+
+      hasException = false;
+      try {
+        DFSTestUtil.createFile(fs, childFile3, fileLen2, replication, 0);
+      } catch (DSQuotaExceededException e) {
+        hasException = true;
+      }
+      assertTrue(hasException);
+
+      // now test the same for root
+      final Path childFile4 = new Path("/", "datafile2");
+      final Path childFile5 = new Path("/", "datafile3");
+
+      runCommand(admin, true, "-clrQuota", "/");
+      runCommand(admin, false, "-clrSpaceQuota", "/");
+      // set space quota to a real low value 
+      runCommand(admin, false, "-setSpaceQuota", Long.toString(spaceQuota2), "/");
+      runCommand(admin, false, "-clrSpaceQuota", "/");
+      DFSTestUtil.createFile(fs, childFile4, fileLen2, replication, 0);
+      runCommand(admin, false, "-setSpaceQuota", Long.toString(spaceQuota2), "/");
+
+      hasException = false;
+      try {
+        DFSTestUtil.createFile(fs, childFile5, fileLen2, replication, 0);
+      } catch (DSQuotaExceededException e) {
+        hasException = true;
+      }
+      assertTrue(hasException);
+
     } finally {
       cluster.shutdown();
     }