hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rang...@apache.org
Subject svn commit: r699425 - in /hadoop/core/branches/branch-0.19: ./ CHANGES.txt src/core/org/apache/hadoop/util/StringUtils.java src/hdfs/org/apache/hadoop/hdfs/tools/DFSAdmin.java src/test/org/apache/hadoop/hdfs/TestQuota.java
Date Fri, 26 Sep 2008 17:28:43 GMT
Author: rangadi
Date: Fri Sep 26 10:28:43 2008
New Revision: 699425

URL: http://svn.apache.org/viewvc?rev=699425&view=rev
Log:
HADOOP-4254. -setSpaceQuota command does not convert "TB" extenstion to
terabytes properly. Implementation now uses StringUtils for parsing this.

Modified:
    hadoop/core/branches/branch-0.19/   (props changed)
    hadoop/core/branches/branch-0.19/CHANGES.txt
    hadoop/core/branches/branch-0.19/src/core/org/apache/hadoop/util/StringUtils.java
    hadoop/core/branches/branch-0.19/src/hdfs/org/apache/hadoop/hdfs/tools/DFSAdmin.java
    hadoop/core/branches/branch-0.19/src/test/org/apache/hadoop/hdfs/TestQuota.java

Propchange: hadoop/core/branches/branch-0.19/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep 26 10:28:43 2008
@@ -1 +1 @@
-/hadoop/core/trunk:697306,698176,699056,699098,699415
+/hadoop/core/trunk:697306,698176,699056,699098,699415,699424

Modified: hadoop/core/branches/branch-0.19/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.19/CHANGES.txt?rev=699425&r1=699424&r2=699425&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.19/CHANGES.txt (original)
+++ hadoop/core/branches/branch-0.19/CHANGES.txt Fri Sep 26 10:28:43 2008
@@ -737,6 +737,10 @@
     HADOOP-4280. Fix conversions between seconds in C and milliseconds in 
     Java for access times for files. (Pete Wyckoff via rangadi)
 
+    HADOOP-4254. -setSpaceQuota command does not convert "TB" extenstion to
+    terabytes properly. Implementation now uses StringUtils for parsing this.
+    (Raghu Angadi)
+
 Release 0.18.2 - Unreleased
 
   BUG FIXES

Modified: hadoop/core/branches/branch-0.19/src/core/org/apache/hadoop/util/StringUtils.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.19/src/core/org/apache/hadoop/util/StringUtils.java?rev=699425&r1=699424&r2=699425&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.19/src/core/org/apache/hadoop/util/StringUtils.java (original)
+++ hadoop/core/branches/branch-0.19/src/core/org/apache/hadoop/util/StringUtils.java Fri
Sep 26 10:28:43 2008
@@ -563,7 +563,7 @@
     EXA(PETA.value << 10);
 
     public final long value;
-    public final long symbol;
+    public final char symbol;
 
     TraditionalBinaryPrefix(long value) {
       this.value = value;
@@ -601,9 +601,14 @@
       final char lastchar = s.charAt(lastpos);
       if (Character.isDigit(lastchar))
         return Long.parseLong(s);
-      else
-        return TraditionalBinaryPrefix.valueOf(lastchar).value
-               * Long.parseLong(s.substring(0, lastpos));
+      else {
+        long prefix = TraditionalBinaryPrefix.valueOf(lastchar).value;
+        long num = Long.parseLong(s.substring(0, lastpos));
+        if (num > (Long.MAX_VALUE/prefix) || num < (Long.MIN_VALUE/prefix)) {
+          throw new IllegalArgumentException(s + " does not fit in a Long");
+        }
+        return num * prefix;
+      }
     }
   }
   

Modified: hadoop/core/branches/branch-0.19/src/hdfs/org/apache/hadoop/hdfs/tools/DFSAdmin.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.19/src/hdfs/org/apache/hadoop/hdfs/tools/DFSAdmin.java?rev=699425&r1=699424&r2=699425&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.19/src/hdfs/org/apache/hadoop/hdfs/tools/DFSAdmin.java (original)
+++ hadoop/core/branches/branch-0.19/src/hdfs/org/apache/hadoop/hdfs/tools/DFSAdmin.java Fri
Sep 26 10:28:43 2008
@@ -36,6 +36,7 @@
 import org.apache.hadoop.fs.shell.CommandFormat;
 import org.apache.hadoop.ipc.RPC;
 import org.apache.hadoop.ipc.RemoteException;
+import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.util.ToolRunner;
 
 /**
@@ -193,8 +194,8 @@
       "\tSet the dik space quota <quota> for each directory <dirName>.\n" + 
       "\t\tThe directory quota is a long integer that puts a hard limit " +
       "on the number of names in the directory tree.\n" +
-      "\t\tQuota can also be speciefied with MB, GB, or TB suffix" +
-      " (e.g. 100GB, 20TB).\n" + 
+      "\t\tQuota can also be speciefied with a binary prefix for terabytes, " +
+      " petabytes etc (e.g. 50t is 50TB, 5m is 5MB, 3p is 3PB).\n" + 
       "\t\tBest effort for the directory, with faults reported if\n" +
       "\t\t1. N is not a positive integer, or\n" +
       "\t\t2. user is not an administrator, or\n" +
@@ -208,24 +209,8 @@
       super(fs);
       CommandFormat c = new CommandFormat(NAME, 2, Integer.MAX_VALUE);
       List<String> parameters = c.parse(args, pos);
-      long multiplier = 1;
       String str = parameters.remove(0).trim();
-      if (str.endsWith("TB")) {
-        multiplier = 1024 * 1024 * 1024 * 1024;
-      } else if (str.endsWith("GB")) {
-        multiplier = 1024 * 1024 * 1024;
-      } else if (str.endsWith("MB")) {
-        multiplier = 1024 * 1024;
-      }
-      if (multiplier != 1) {
-        str = str.substring(0, str.length()-2);
-      }
-      
-      quota = Long.parseLong(str);
-      if (quota > Long.MAX_VALUE/multiplier) {
-        throw new IllegalArgumentException("quota exceeds Long.MAX_VALUE!");
-      }
-      quota *= multiplier;
+      quota = StringUtils.TraditionalBinaryPrefix.string2long(str);
       this.args = parameters.toArray(new String[parameters.size()]);
     }
     

Modified: hadoop/core/branches/branch-0.19/src/test/org/apache/hadoop/hdfs/TestQuota.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.19/src/test/org/apache/hadoop/hdfs/TestQuota.java?rev=699425&r1=699424&r2=699425&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.19/src/test/org/apache/hadoop/hdfs/TestQuota.java (original)
+++ hadoop/core/branches/branch-0.19/src/test/org/apache/hadoop/hdfs/TestQuota.java Fri Sep
26 10:28:43 2008
@@ -75,6 +75,10 @@
       String[] args = new String[]{"-setQuota", "3", parent.toString()};
       runCommand(admin, args, false);
 
+      //try setting space quota with a 'binary prefix'
+      runCommand(admin, false, "-setSpaceQuota", "2t", parent.toString());
+      assertEquals(2L<<40, dfs.getContentSummary(parent).getSpaceQuota());
+      
       // set diskspace quota to 10000 
       runCommand(admin, false, "-setSpaceQuota", 
                  Long.toString(spaceQuota), parent.toString());
@@ -188,7 +192,7 @@
       assertFalse(dfs.exists(nonExistentPath));
       args = new String[]{"-setQuota", "1", nonExistentPath.toString()};
       runCommand(admin, args, true);
-      runCommand(admin, true, "-setSpaceQuota", "1GB", // for space quota
+      runCommand(admin, true, "-setSpaceQuota", "1g", // for space quota
                  nonExistentPath.toString());
       
       // 14b: set quota on a file
@@ -196,7 +200,7 @@
       args[1] = childFile0.toString();
       runCommand(admin, args, true);
       // same for space quota
-      runCommand(admin, true, "-setSpaceQuota", "1GB", args[1]);
+      runCommand(admin, true, "-setSpaceQuota", "1t", args[1]);
       
       // 15a: clear quota on a file
       args[0] = "-clrQuota";
@@ -230,7 +234,7 @@
       
       // 16e: set space quota with a value larger than Long.MAX_VALUE
       runCommand(admin, true, "-setSpaceQuota", 
-                 (Long.MAX_VALUE/1024/1024 + 1024) + "TB", args[2]);
+                 (Long.MAX_VALUE/1024/1024 + 1024) + "m", args[2]);
       
       // 17:  setQuota by a non-administrator
       UnixUserGroupInformation.saveToConf(conf, 
@@ -239,7 +243,7 @@
       DFSAdmin userAdmin = new DFSAdmin(conf);
       args[1] = "100";
       runCommand(userAdmin, args, true);
-      runCommand(userAdmin, true, "-setSpaceQuota", "1GB", args[2]);
+      runCommand(userAdmin, true, "-setSpaceQuota", "1g", args[2]);
       
       // 18: clrQuota by a non-administrator
       args = new String[] {"-clrQuota", parent.toString()};



Mime
View raw message