设置hdfs磁盘配额

设置磁盘配额

命令行:

hdfs dfsadmin -setQuota  5 /tmp

超额的错误提示为:

put: The NameSpacequota (directories and files) of directory /tmp is exceeded: quota=5 filecount=8


java代码:

public static void main(String[] args) {
        FileSystem hdfs = null;
        Configuration conf = new Configuration();
        try {
            hdfs = FileSystem.get(new URI("hdfs://192.xxx.xx.xx:9000"),conf,"username");
        } catch (Exception e) {
            e.printStackTrace();
        }
        Path filenamePath = new Path("/test/input");
        try {
            //会根据集群的配置输出,例如我这里输出3G
            System.out.println("SIZE OF THE HDFS DIRECTORY : " + hdfs.getContentSummary(filenamePath).getSpaceConsumed());
           // 显示实际的输出,例如这里显示 1G
            System.out.println("SIZE OF THE HDFS DIRECTORY : " + hdfs.getContentSummary(filenamePath).getLength());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


jni代码:

int64_t  hdfsa::getSpaceConsumed(hdfsFS dfs, const char* file_path) {
    JNIEnv* envJNI = getJNIEnv();
    if (envJNI == NULL) {
        Throw(Exception::ServerException, "Can't get JNIEnv from current thread", LIBHDFS_ERROR);
    }


    RAIIJObject_Path hdfsPath(envJNI, file_path);
    if (hdfsPath.jerror()) {
        Throw(
                Exception::ServerException,
                hdfsPath.jerrorStackTrace("Failed to construct a HDFS Path object"),
                LIBHDFS_ERROR);
    }
    // get class ContentSummary
    jvalue jContentSummary;
    jthrowable jthr = invokeMethod(
            envJNI, &jContentSummary, INSTANCE,
            (jobject)dfs,
            "org/apache/hadoop/hdfs/DistributedFileSystem",
            "getContentSummary",
            "(Lorg/apache/hadoop/fs/Path;)Lorg/apache/hadoop/fs/ContentSummary;", hdfsPath.get());
    checkAndThrow(jthr, "getContentSummary");


    // get the disk space usage
    jvalue jSpaceConsumed;
    jthr = invokeMethod(
            envJNI, &jSpaceConsumed, INSTANCE,
            jContentSummary.l,
            "org/apache/hadoop/fs/ContentSummary",
            "getSpaceConsumed", "()J");
    checkAndThrow(jthr, "getSpaceConsumed");
    return jSpaceConsumed.j;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值