svn merge -c 1239727 FIXES HADOOP-8001

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1239730 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Joseph Evans 2012-02-02 17:19:26 +00:00
parent 818dfb0c5b
commit 7c0614e301
3 changed files with 66 additions and 7 deletions

View File

@ -95,6 +95,8 @@ Release 0.23.1 - Unreleased
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES
HADOOP-8001 ChecksumFileSystem's rename doesn't correctly handle checksum
files. (Daryn Sharp via bobby)
HADOOP-8006 TestFSInputChecker is failing in trunk. HADOOP-8006 TestFSInputChecker is failing in trunk.
(Daryn Sharp via bobby) (Daryn Sharp via bobby)

View File

@ -474,18 +474,21 @@ public boolean rename(Path src, Path dst) throws IOException {
if (fs.isDirectory(src)) { if (fs.isDirectory(src)) {
return fs.rename(src, dst); return fs.rename(src, dst);
} else { } else {
if (fs.isDirectory(dst)) {
dst = new Path(dst, src.getName());
}
boolean value = fs.rename(src, dst); boolean value = fs.rename(src, dst);
if (!value) if (!value)
return false; return false;
Path checkFile = getChecksumFile(src); Path srcCheckFile = getChecksumFile(src);
if (fs.exists(checkFile)) { //try to rename checksum Path dstCheckFile = getChecksumFile(dst);
if (fs.isDirectory(dst)) { if (fs.exists(srcCheckFile)) { //try to rename checksum
value = fs.rename(checkFile, dst); value = fs.rename(srcCheckFile, dstCheckFile);
} else { } else if (fs.exists(dstCheckFile)) {
value = fs.rename(checkFile, getChecksumFile(dst)); // no src checksum, so remove dst checksum
} value = fs.delete(dstCheckFile, true);
} }
return value; return value;

View File

@ -203,4 +203,58 @@ public void testCorruptedChecksum() throws Exception {
String str = readFile(localFs, testPath, 1024); String str = readFile(localFs, testPath, 1024);
assertEquals("testing stale checksum", str); assertEquals("testing stale checksum", str);
} }
@Test
public void testRenameFileToFile() throws Exception {
Path srcPath = new Path(TEST_ROOT_DIR, "testRenameSrc");
Path dstPath = new Path(TEST_ROOT_DIR, "testRenameDst");
verifyRename(srcPath, dstPath, false);
}
@Test
public void testRenameFileIntoDir() throws Exception {
Path srcPath = new Path(TEST_ROOT_DIR, "testRenameSrc");
Path dstPath = new Path(TEST_ROOT_DIR, "testRenameDir");
localFs.mkdirs(dstPath);
verifyRename(srcPath, dstPath, true);
}
@Test
public void testRenameFileIntoDirFile() throws Exception {
Path srcPath = new Path(TEST_ROOT_DIR, "testRenameSrc");
Path dstPath = new Path(TEST_ROOT_DIR, "testRenameDir/testRenameDst");
assertTrue(localFs.mkdirs(dstPath));
verifyRename(srcPath, dstPath, false);
}
void verifyRename(Path srcPath, Path dstPath, boolean dstIsDir)
throws Exception {
localFs.delete(srcPath,true);
localFs.delete(dstPath,true);
Path realDstPath = dstPath;
if (dstIsDir) {
localFs.mkdirs(dstPath);
realDstPath = new Path(dstPath, srcPath.getName());
}
// ensure file + checksum are moved
writeFile(localFs, srcPath, 1);
assertTrue(localFs.exists(localFs.getChecksumFile(srcPath)));
assertTrue(localFs.rename(srcPath, dstPath));
assertTrue(localFs.exists(localFs.getChecksumFile(realDstPath)));
// create a file with no checksum, rename, ensure dst checksum is removed
writeFile(localFs.getRawFileSystem(), srcPath, 1);
assertFalse(localFs.exists(localFs.getChecksumFile(srcPath)));
assertTrue(localFs.rename(srcPath, dstPath));
assertFalse(localFs.exists(localFs.getChecksumFile(realDstPath)));
// create file with checksum, rename over prior dst with no checksum
writeFile(localFs, srcPath, 1);
assertTrue(localFs.exists(localFs.getChecksumFile(srcPath)));
assertTrue(localFs.rename(srcPath, dstPath));
assertTrue(localFs.exists(localFs.getChecksumFile(realDstPath)));
}
} }