通过该命令可以来限定某个hdfs目录的大小:
hadoop dfsadmin -setSpaceQuota 3000 /group/d_sdo_data/user/liuxiaowen
但设定之后,put一个2000多字节的文件时候报错:
12/05/14 15:41:24 WARN hdfs.DFSClient: DataStreamer Exception: org.apache.hadoop.hdfs.protocol.DSQuotaExceededException: org.apache.hadoop.hdfs.protocol.DSQuotaExceededException: The DiskSpace quota of /group/d_sdo_data/user/liuxiaowen is exceeded: quota=3000 diskspace consumed=384.0m at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.apache.hadoop.ipc.RemoteException.instantiateException(RemoteException.java:95) at org.apache.hadoop.ipc.RemoteException.unwrapRemoteException(RemoteException.java:57) at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.locateFollowingBlock(DFSClient.java:3190) at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.nextBlockOutputStream(DFSClient.java:3055) at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.access$1900(DFSClient.java:2305) at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream$DataStreamer.run(DFSClient.java:2500) Caused by: org.apache.hadoop.ipc.RemoteException: org.apache.hadoop.hdfs.protocol.DSQuotaExceededException: The DiskSpace quota of /group/d_sdo_data/user/liuxiaowen is exceeded: quota=3000 diskspace consumed=384.0m at org.apache.hadoop.hdfs.server.namenode.INodeDirectoryWithQuota.verifyQuota(INodeDirectoryWithQuota.java:149) at org.apache.hadoop.hdfs.server.namenode.FSDirectory.verifyQuota(FSDirectory.java:1041) at org.apache.hadoop.hdfs.server.namenode.FSDirectory.updateCount(FSDirectory.java:859) at org.apache.hadoop.hdfs.server.namenode.FSDirectory.addBlock(FSDirectory.java:277) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.allocateBlock(FSNamesystem.java:1698) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:1543) at org.apache.hadoop.hdfs.server.namenode.NameNode.addBlock(NameNode.java:665) at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:557) at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1434) at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1430) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:396) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1157) at org.apache.hadoop.ipc.Server$Handler.run(Server.java:1428) at org.apache.hadoop.ipc.Client.call(Client.java:1104) at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:226) at $Proxy5.addBlock(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:82) at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:59) at $Proxy5.addBlock(Unknown Source) at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.locateFollowingBlock(DFSClient.java:3185) ... 3 more
后来发现原因:
这里统计空间的时候会将备份数也考虑在里面,因为集群设置了备份数为3,所以hadoop dfsadmin -setSpaceQuota也要讲备份数考虑进去,即 hadoop dfsadmin -setSpaceQuota 9000 /group/d_sdo_data/user/liuxiaowen
另外,这个动作会覆盖上一次的设置;
清除命令: hadoop dfsadmin -clrSpaceQuota /group/d_sdo_data/user/liuxiaowen
查看目录限额: hadoop fs -count -q /group/d_sdo_data/user/liuxiaowen
none inf 9000 8088 6 1 304 hdfs://nn.dc.sh-wgq.sdo.com/group/d_sdo_data/user/liuxiaowen
依次表示为:文件数限额 可用文件数 空间限额 可用空间 目录数 文件数 总大小 文件/目录名