简体   繁体   English

在java中设置HDFS的空间配额

[英]Set space quota of HDFS in java

I am tryging to set space quota for HDFS using Hadoop Java API, however, I can only find getSpaceQuota method in ContentSummary class.我正在尝试使用 Hadoop Java API 为 HDFS 设置空间配额,但是,我只能在 ContentSummary 类中找到 getSpaceQuota 方法。 Basically I want the code to achieve the same function as sudo -u hdfs hdfs dfsadmin -setSpaceQuota 1k /quotasdir command.基本上我希望代码实现与sudo -u hdfs hdfs dfsadmin -setSpaceQuota 1k /quotasdir命令相同的功能。 Is there any API having set space quota method?有没有设置空间配额方法的API? Or any better idea?或者有什么更好的主意? Thanks in advance.提前致谢。

In the Apache Hadoop codebase, the code for the hdfs dfsadmin -setSpaceQuota command is in the DFSAdmin class.在 Apache Hadoop 代码库中, hdfs dfsadmin -setSpaceQuota命令的代码位于DFSAdmin类中。 If you read through that code, you'll see that it ultimately delegates to the DistributedFileSystem#setQuota method.如果您通读该代码,您将看到它最终委托给DistributedFileSystem#setQuota方法。 That method implements an RPC to the NameNode to modify the quota.该方法实现到 NameNode 的 RPC 以修改配额。

If you want to reimplement this functionality in your own Java program, then you'll likely need to get an instance of FileSystem , downcast it to DistributedFileSystem , and then call DistributedFileSystem#setQuota .如果您想在您自己的 Java 程序中重新实现此功能,那么您可能需要获取FileSystem一个实例,将其向下转换为DistributedFileSystem ,然后调用DistributedFileSystem#setQuota

Please be aware that Apache Hadoop does not provide a strong backward compatibility guarantee for the DistributedFileSystem class.请注意,Apache Hadoop 没有为DistributedFileSystem类提供强大的向后兼容性保证。 That means that it would be possible for your code to break after an upgrade to a new Hadoop version.这意味着您的代码在升级到新的 Hadoop 版本后可能会中断。 The class is annotated as LimitedPrivate and Unstable .该类被注释为LimitedPrivateUnstable The Apache Hadoop Compatibility documentation describes the meaning of these annotations in detail. Apache Hadoop Compatibility文档详细描述了这些注释的含义。 There is currently no guaranteed public, stable API for changing quota from a custom program.目前没有保证公开、稳定的 API 来更改自定义程序的配额。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM