设置hdfs磁盘配额

来源:互联网 发布:淘宝商城舞蹈鞋 编辑:程序博客网 时间:2024/05/18 14:25

设置磁盘配额

命令行:

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;}

原创粉丝点击