hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szets...@apache.org
Subject svn commit: r1075571 - in /hadoop/hdfs/trunk: CHANGES.txt src/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java src/test/hdfs/org/apache/hadoop/hdfs/TestQuota.java
Date Mon, 28 Feb 2011 22:54:42 GMT
Author: szetszwo
Date: Mon Feb 28 22:54:42 2011
New Revision: 1075571

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

Modified:
    hadoop/hdfs/trunk/CHANGES.txt
    hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
    hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestQuota.java

Modified: hadoop/hdfs/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=1075571&r1=1075570&r2=1075571&view=diff
==============================================================================
--- hadoop/hdfs/trunk/CHANGES.txt (original)
+++ hadoop/hdfs/trunk/CHANGES.txt Mon Feb 28 22:54:42 2011
@@ -590,6 +590,9 @@ Release 0.21.1 - Unreleased
     block placement and checkpoint/backup node features.  (Joe Crobak
     via szetszwo)
 
+    HDFS-1189. Quota counts missed between clear quota and set quota.
+    (John George via szetszwo)
+
   INCOMPATIBLE CHANGES
 
     HDFS-538. Per the contract elucidated in HADOOP-6201, throw

Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java?rev=1075571&r1=1075570&r2=1075571&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java Mon
Feb 28 22:54:42 2011
@@ -1819,6 +1819,13 @@ class FSDirectory implements Closeable {
         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/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestQuota.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestQuota.java?rev=1075571&r1=1075570&r2=1075571&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestQuota.java (original)
+++ hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestQuota.java Mon Feb 28 22:54:42
2011
@@ -62,7 +62,8 @@ public class TestQuota {
     final Configuration conf = new HdfsConfiguration();
     // set a smaller block size so that we can test with smaller 
     // Space quotas
-    conf.set(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, "512");
+    final int DEFAULT_BLOCK_SIZE = 512;
+    conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, DEFAULT_BLOCK_SIZE);
     conf.setBoolean("dfs.support.append", true);
     final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
     final FileSystem fs = cluster.getFileSystem();
@@ -276,6 +277,60 @@ public class TestQuota {
 
       // 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();
     }



Mime
View raw message