最近需要使用到HDFS的磁盘配额(Quotas)功能,故稍微学习了一下,并做了一些简单的测试。
HDFS的Quotas分为两种:
- Name Quotas :用于限制HDFS指定目录下的文件或文件夹的数量;
- Space Quotas:用于限制HDFS指定目录的最大使用空间,这里要特别注意:如果你的HDFS复制因子是2,那么你上传一个1G的文件,则可用 Space Quotas会减少2G.
hadoop@mt-15:/opt/hadoop/sbin$ hadoop fs -mkdir /quato1
hadoop@mt-15:/opt/hadoop/sbin$ hadoop dfsadmin -setQuota 2 /quota1
hadoop@mt-15:/opt/hadoop/sbin$ hadoop fs -put start-dfs.sh /quota1
hadoop@mt-15:/opt/hadoop/sbin$ hadoop fs -put stop-dfs.sh /quota1
put: The NameSpace quota (directories and files) of directory /quota1 is exceeded: quota=2 file count=3
the name quota value set for each directory, the available name quota remaining, the space quota value set, and the available space quota remaining
hadoop@mt-15:/opt/hadoop/sbin$ hadoop fs -count -q /quota1
All-Name-Quo Remain-Name-Quo All-Space-Quo Remain-Space-Quo File-Num Directory-Num Size/Name
2 0 none inf 1 1 3705 /quota1
hadoop@mt-15:/opt/hadoop/sbin$ hadoop dfsadmin -setQuota 4 /quota1
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.
hadoop@mt-15:/opt/hadoop/sbin$ hadoop fs -count -q /quota1
4 2 none inf 1 1 3705 /quota1
hadoop@mt-15:/opt/hadoop/sbin$ hadoop fs -put stop-dfs.sh /quota1
hadoop@mt-15:/opt/hadoop/sbin$ hadoop fs -count -q /quota1
4 1 none inf 1 2 6911 /quota1
hadoop@mt-15:/opt/hadoop/sbin$ hadoop dfsadmin -setSpaceQuota 10M /quota1
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.
hadoop@mt-15:/opt/hadoop/sbin$ hadoop fs -count -q /quota1
4 1 10485760 10471938 1 2 6911 /quota1
hadoop@mt-15:/opt/hadoop$ du -sh mesos-hadoop-mr1-0.1.1-SNAPSHOT.jar
6.1M mesos-hadoop-mr1-0.1.1-SNAPSHOT.jar
hadoop@mt-15:/opt/hadoop$ hadoop fs -put mesos-hadoop-mr1-0.1.1-SNAPSHOT.jar /quota1/
15/08/19 10:46:31 WARN hdfs.DFSClient: DataStreamer Exception
org.apache.hadoop.hdfs.protocol.DSQuotaExceededException: The DiskSpace quota of /quota1 is exceeded: quota = 10485760 B = 10 MB but diskspace consumed = 268449278 B = 256.01 MB
......
put: The DiskSpace quota of /quota1 is exceeded: quota = 10485760 B = 10 MB but diskspace consumed = 268449278 B = 256.01 MB