Help Center/
MapReduce Service/
Developer Guide (Normal_Earlier Than 3.x)/
HDFS Development Guide/
Developing an HDFS Application/
Setting HDFS Storage Policies
Updated on 2024-08-16 GMT+08:00
Setting HDFS Storage Policies
Function Description
Specify storage policies for a file or folder in HDFS.
Sample Code
- Set the following parameters in the Hdfs-site.xml file in ${HADOOP_HOME}/etc/hadoop/.
<name>dfs.storage.policy.enabled</name> <value>true</value>
- Restart HDFS, as shown in Figure 1.
- Log in to MRS Manager. Choose , and set Type to All.
- Check whether the value of dfs.storage.policy.enabled is true. If it is not, modify the value to true, click Save Configuration, and restart HDFS.
- View the code.
The following provides code snippets. For complete codes, see the HdfsMain class in com.huawei.bigdata.hdfs.examples.
/** * Set storage policies. * @param policyName * The policy name can be accepted. * <li>HOT * <li>WARM * <li>COLD * <li>LAZY_PERSIST * <li>ALL_SSD * <li>ONE_SSD * @throws IOException */ private void setStoragePolicy(String policyName) throws IOException{ if(fSystem instanceof DistributedFileSystem) { DistributedFileSystem dfs = (DistributedFileSystem) fSystem; Path destPath = new Path(DEST_PATH); Boolean flag = false; mkdir(); BlockStoragePolicySpi[] storage = dfs.getStoragePolicies(); for (BlockStoragePolicySpi bs : storage) { if (bs.getName().equals(policyName)) { flag = true; } System.out.println("StoragePolicy:" + bs.getName()); } if (!flag) { policyName = storage[0].getName(); } dfs.setStoragePolicy(destPath, policyName); System.out.println("success to set Storage Policy path " + DEST_PATH); rmdir(); } else{ System.out.println("Storage Policy is only supported in HDFS."); } }
Parent topic: Developing an HDFS Application
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot