mySetup(1, 1);
Path dir = new Path("/user/test/raidtest");
Path file1 = new Path(dir + "/file1");
HashMap<String, PolicyInfo> infos = new HashMap<String, PolicyInfo>();
for (Codec code: Codec.getCodecs()) {
PolicyInfo pi = new PolicyInfo("testPurgePreference", conf);
pi.setSrcPath("/user/test/raidtest");
pi.setCodecId(code.id);
pi.setDescription("test policy");
pi.setProperty("targetReplication", "1");
pi.setProperty("metaReplication", "1");
infos.put(code.id, pi);
}
try {
LOG.info("Create a old file");
TestRaidNode.createOldFile(fileSys, file1, 1, 9, 8192L);
FileStatus stat = fileSys.getFileStatus(file1);
FileStatus dirStat = fileSys.getFileStatus(dir);
HashMap<String, Path> parityFiles = new HashMap<String, Path>();
// Create the parity files.
LOG.info("Start Raiding");
for (PolicyInfo pi: infos.values()){
Codec code = Codec.getCodec(pi.getCodecId());
FileStatus fsStat = (code.isDirRaid)? dirStat: stat;
RaidNode.doRaid(
conf, pi, fsStat, new RaidNode.Statistics(), Reporter.NULL);
Path parity = RaidNode.getOriginalParityFile(new Path(code.parityDirectory),
fsStat.getPath());
assertTrue(fileSys.exists(parity));
parityFiles.put(pi.getCodecId(), parity);
}
LOG.info("Finished Raiding");
// Check purge of a single parity file.
PurgeMonitor purgeMonitor = new PurgeMonitor(conf, null);
LOG.info("Purge testrs");
purgeMonitor.purgeCode(Codec.getCodec("testrs"));
// Simulate code couldn't purge normal code even with higher priority
assertTrue(fileSys.exists(parityFiles.get("testrs")));
assertTrue(fileSys.exists(parityFiles.get("dir-rs")));
assertTrue(fileSys.exists(parityFiles.get("rs")));
assertTrue(fileSys.exists(parityFiles.get("dir-xor")));
assertTrue(fileSys.exists(parityFiles.get("xor")));
LOG.info("Purge dir-rs");
purgeMonitor.purgeCode(Codec.getCodec("dir-rs"));
// Calling purge under the Dir-RS path has no effect.
assertTrue(fileSys.exists(parityFiles.get("testrs")));
assertTrue(fileSys.exists(parityFiles.get("dir-rs")));
assertTrue(fileSys.exists(parityFiles.get("rs")));
assertTrue(fileSys.exists(parityFiles.get("dir-xor")));
assertTrue(fileSys.exists(parityFiles.get("xor")));
LOG.info("Purge rs");
purgeMonitor.purgeCode(Codec.getCodec("rs"));
// Calling purge under the rs path will delete rs
assertTrue(fileSys.exists(parityFiles.get("testrs")));
assertTrue(fileSys.exists(parityFiles.get("dir-rs")));
assertFalse(fileSys.exists(parityFiles.get("rs")));
assertTrue(fileSys.exists(parityFiles.get("dir-xor")));
assertTrue(fileSys.exists(parityFiles.get("xor")));
LOG.info("Purge dir-xor");
purgeMonitor.purgeCode(Codec.getCodec("dir-xor"));
// Calling purge under the Dir-xor path will delete dir-xor
assertTrue(fileSys.exists(parityFiles.get("testrs")));
assertTrue(fileSys.exists(parityFiles.get("dir-rs")));
assertFalse(fileSys.exists(parityFiles.get("dir-xor")));
assertTrue(fileSys.exists(parityFiles.get("xor")));
LOG.info("Purge xor");
purgeMonitor.purgeCode(Codec.getCodec("xor"));
assertFalse(fileSys.exists(parityFiles.get("xor")));
assertTrue(fileSys.exists(parityFiles.get("testrs")));
assertTrue(fileSys.exists(parityFiles.get("dir-rs")));
LOG.info("delete dir-rs parity file");
fileSys.delete(parityFiles.get("dir-rs"), true);
assertFalse(fileSys.exists(parityFiles.get("dir-rs")));
//Recreate RS and Dir-XOR
LOG.info("Raid rs");
RaidNode.doRaid(
conf, infos.get("rs"), stat, new RaidNode.Statistics(),
Reporter.NULL);
assertTrue(fileSys.exists(parityFiles.get("rs")));
LOG.info("Raid dir-xor");
RaidNode.doRaid(
conf, infos.get("dir-xor"), dirStat, new RaidNode.Statistics(),
Reporter.NULL);
assertTrue(fileSys.exists(parityFiles.get("dir-xor")));
LOG.info("Raid xor");
RaidNode.doRaid(
conf, infos.get("xor"), stat, new RaidNode.Statistics(),
Reporter.NULL);
assertTrue(fileSys.exists(parityFiles.get("xor")));
LOG.info("Purge dir-xor should fail because rs doesn't have parity " +
"file for directory, only dir-rs could purge dir-xor");
purgeMonitor.purgeCode(Codec.getCodec("dir-xor"));
// Calling purge under the Dir-XOR path succeeds
assertTrue(fileSys.exists(parityFiles.get("testrs")));
assertTrue(fileSys.exists(parityFiles.get("rs")));
assertTrue(fileSys.exists(parityFiles.get("dir-xor")));
assertTrue(fileSys.exists(parityFiles.get("xor")));
LOG.info("delete dir-xor parity file");
fileSys.delete(parityFiles.get("dir-xor"), true);
assertFalse(fileSys.exists(parityFiles.get("dir-xor")));
LOG.info("Purge xor");
purgeMonitor.purgeCode(Codec.getCodec("xor"));
// Calling purge under the Dir-RS path has no effect.
assertTrue(fileSys.exists(parityFiles.get("testrs")));
assertTrue(fileSys.exists(parityFiles.get("rs")));
assertFalse(fileSys.exists(parityFiles.get("xor")));
// The following is har related stuff
Path rsParity = parityFiles.get("rs");
Path xorParity = parityFiles.get("xor");
PolicyInfo infoXor = infos.get("xor");
PolicyInfo infoRs = infos.get("rs");
// Now check the purge of a parity har.
// Delete the RS parity for now.
fileSys.delete(rsParity, true);
// Recreate the XOR parity.
Path xorHar = new Path("/raid", "user/test/raidtest/raidtest" +