HDFS-15093. RENAME.TO_TRASH is ignored When RENAME.OVERWRITE is specified. Contributed by Ayush Saxena.

This commit is contained in:
Ayush Saxena 2020-05-23 18:38:32 +05:30
parent f99fcb26ab
commit e0ae232f66
3 changed files with 25 additions and 2 deletions

View File

@ -609,7 +609,8 @@ public void rename2(String src, String dst, Rename... options)
for (Rename option : options) {
if (option == Rename.OVERWRITE) {
overwrite = true;
} else if (option == Rename.TO_TRASH) {
}
if (option == Rename.TO_TRASH) {
toTrash = true;
}
}

View File

@ -688,7 +688,8 @@ public Rename2ResponseProto rename2(RpcController controller,
ArrayList<Rename> optionList = new ArrayList<Rename>();
if(req.getOverwriteDest()) {
optionList.add(Rename.OVERWRITE);
} else if(req.hasMoveToTrash() && req.getMoveToTrash()) {
}
if (req.hasMoveToTrash() && req.getMoveToTrash()) {
optionList.add(Rename.TO_TRASH);
}

View File

@ -30,7 +30,9 @@
import org.apache.hadoop.fs.Options.Rename;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Test;
public class TestDFSRename {
@ -175,4 +177,23 @@ public void testRenameWithOverwrite() throws Exception {
}
}
}
@Test
public void testRename2Options() throws Exception {
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(
new HdfsConfiguration()).build()) {
cluster.waitActive();
final DistributedFileSystem dfs = cluster.getFileSystem();
Path path = new Path("/test");
dfs.mkdirs(path);
GenericTestUtils.LogCapturer auditLog =
GenericTestUtils.LogCapturer.captureLogs(FSNamesystem.auditLog);
dfs.rename(path, new Path("/dir1"),
new Rename[] {Rename.OVERWRITE, Rename.TO_TRASH});
String auditOut = auditLog.getOutput();
assertTrue("Rename should have both OVERWRITE and TO_TRASH "
+ "flags at namenode but had only " + auditOut,
auditOut.contains("options=[OVERWRITE, TO_TRASH]"));
}
}
}