|
@@ -26,6 +26,7 @@ import java.util.*;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.fs.FSDataOutputStream;
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.fs.StorageType;
|
|
@@ -1177,4 +1178,48 @@ public class TestBlockStoragePolicy {
|
|
|
cluster.shutdown();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testGetFileStoragePolicyAfterRestartNN() throws Exception {
|
|
|
+ //HDFS8219
|
|
|
+ final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
|
|
|
+ .numDataNodes(REPLICATION)
|
|
|
+ .storageTypes(
|
|
|
+ new StorageType[] {StorageType.DISK, StorageType.ARCHIVE})
|
|
|
+ .build();
|
|
|
+ cluster.waitActive();
|
|
|
+ final DistributedFileSystem fs = cluster.getFileSystem();
|
|
|
+ try {
|
|
|
+ final String file = "/testScheduleWithinSameNode/file";
|
|
|
+ Path dir = new Path("/testScheduleWithinSameNode");
|
|
|
+ fs.mkdirs(dir);
|
|
|
+ // 2. Set Dir policy
|
|
|
+ fs.setStoragePolicy(dir, "COLD");
|
|
|
+ // 3. Create file
|
|
|
+ final FSDataOutputStream out = fs.create(new Path(file));
|
|
|
+ out.writeChars("testScheduleWithinSameNode");
|
|
|
+ out.close();
|
|
|
+ // 4. Set Dir policy
|
|
|
+ fs.setStoragePolicy(dir, "HOT");
|
|
|
+ HdfsFileStatus status = fs.getClient().getFileInfo(file);
|
|
|
+ // 5. get file policy, it should be parent policy.
|
|
|
+ Assert
|
|
|
+ .assertTrue(
|
|
|
+ "File storage policy should be HOT",
|
|
|
+ status.getStoragePolicy()
|
|
|
+ == HdfsServerConstants.HOT_STORAGE_POLICY_ID);
|
|
|
+ // 6. restart NameNode for reloading edits logs.
|
|
|
+ cluster.restartNameNode(true);
|
|
|
+ // 7. get file policy, it should be parent policy.
|
|
|
+ status = fs.getClient().getFileInfo(file);
|
|
|
+ Assert
|
|
|
+ .assertTrue(
|
|
|
+ "File storage policy should be HOT",
|
|
|
+ status.getStoragePolicy()
|
|
|
+ == HdfsServerConstants.HOT_STORAGE_POLICY_ID);
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ cluster.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|