|
@@ -143,79 +143,7 @@ public class TestDatanodeRestart {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // test recovering unlinked tmp replicas
|
|
|
|
- @Test public void testRecoverReplicas() throws Exception {
|
|
|
|
- Configuration conf = new HdfsConfiguration();
|
|
|
|
- conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 1024L);
|
|
|
|
- conf.setInt(HdfsClientConfigKeys.DFS_CLIENT_WRITE_PACKET_SIZE_KEY, 512);
|
|
|
|
- MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
|
|
|
|
- cluster.waitActive();
|
|
|
|
- try {
|
|
|
|
- FileSystem fs = cluster.getFileSystem();
|
|
|
|
- for (int i=0; i<4; i++) {
|
|
|
|
- Path fileName = new Path("/test"+i);
|
|
|
|
- DFSTestUtil.createFile(fs, fileName, 1, (short)1, 0L);
|
|
|
|
- DFSTestUtil.waitReplication(fs, fileName, (short)1);
|
|
|
|
- }
|
|
|
|
- String bpid = cluster.getNamesystem().getBlockPoolId();
|
|
|
|
- DataNode dn = cluster.getDataNodes().get(0);
|
|
|
|
- Iterator<ReplicaInfo> replicasItor =
|
|
|
|
- dataset(dn).volumeMap.replicas(bpid).iterator();
|
|
|
|
- ReplicaInfo replica = replicasItor.next();
|
|
|
|
- createUnlinkTmpFile(replica, true, true); // rename block file
|
|
|
|
- createUnlinkTmpFile(replica, false, true); // rename meta file
|
|
|
|
- replica = replicasItor.next();
|
|
|
|
- createUnlinkTmpFile(replica, true, false); // copy block file
|
|
|
|
- createUnlinkTmpFile(replica, false, false); // copy meta file
|
|
|
|
- replica = replicasItor.next();
|
|
|
|
- createUnlinkTmpFile(replica, true, true); // rename block file
|
|
|
|
- createUnlinkTmpFile(replica, false, false); // copy meta file
|
|
|
|
-
|
|
|
|
- cluster.restartDataNodes();
|
|
|
|
- cluster.waitActive();
|
|
|
|
- dn = cluster.getDataNodes().get(0);
|
|
|
|
-
|
|
|
|
- // check volumeMap: 4 finalized replica
|
|
|
|
- Collection<ReplicaInfo> replicas = dataset(dn).volumeMap.replicas(bpid);
|
|
|
|
- Assert.assertEquals(4, replicas.size());
|
|
|
|
- replicasItor = replicas.iterator();
|
|
|
|
- while (replicasItor.hasNext()) {
|
|
|
|
- Assert.assertEquals(ReplicaState.FINALIZED,
|
|
|
|
- replicasItor.next().getState());
|
|
|
|
- }
|
|
|
|
- } finally {
|
|
|
|
- cluster.shutdown();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private static FsDatasetImpl dataset(DataNode dn) {
|
|
private static FsDatasetImpl dataset(DataNode dn) {
|
|
return (FsDatasetImpl)DataNodeTestUtils.getFSDataset(dn);
|
|
return (FsDatasetImpl)DataNodeTestUtils.getFSDataset(dn);
|
|
}
|
|
}
|
|
-
|
|
|
|
- private static void createUnlinkTmpFile(ReplicaInfo replicaInfo,
|
|
|
|
- boolean changeBlockFile,
|
|
|
|
- boolean isRename) throws IOException {
|
|
|
|
- File src;
|
|
|
|
- if (changeBlockFile) {
|
|
|
|
- src = replicaInfo.getBlockFile();
|
|
|
|
- } else {
|
|
|
|
- src = replicaInfo.getMetaFile();
|
|
|
|
- }
|
|
|
|
- File dst = DatanodeUtil.getUnlinkTmpFile(src);
|
|
|
|
- if (isRename) {
|
|
|
|
- src.renameTo(dst);
|
|
|
|
- } else {
|
|
|
|
- FileInputStream in = new FileInputStream(src);
|
|
|
|
- try {
|
|
|
|
- FileOutputStream out = new FileOutputStream(dst);
|
|
|
|
- try {
|
|
|
|
- IOUtils.copyBytes(in, out, 1);
|
|
|
|
- } finally {
|
|
|
|
- out.close();
|
|
|
|
- }
|
|
|
|
- } finally {
|
|
|
|
- in.close();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|