From 2aa385463305beaae8770c8deb22faed6943ef00 Mon Sep 17 00:00:00 2001 From: Vinayakumar B Date: Thu, 20 Sep 2018 09:31:35 +0530 Subject: [PATCH] HADOOP-15736. Trash : Negative Value For Deletion Interval Leads To Abnormal Behaviour. Contributed by Ayush Saxena. (cherry picked from commit 7ad27e97f05b13b33fdcef9cb63ace9c1728bfb5) --- .../java/org/apache/hadoop/fs/TrashPolicyDefault.java | 8 +++++++- .../src/test/java/org/apache/hadoop/fs/TestTrash.java | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java index 6e101a26e24..39d5e73f0ba 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java @@ -101,6 +101,12 @@ public class TrashPolicyDefault extends TrashPolicy { this.emptierInterval = (long)(conf.getFloat( FS_TRASH_CHECKPOINT_INTERVAL_KEY, FS_TRASH_CHECKPOINT_INTERVAL_DEFAULT) * MSECS_PER_MINUTE); + if (deletionInterval < 0) { + LOG.warn("Invalid value {} for deletion interval," + + " deletion interaval can not be negative." + + "Changing to default value 0", deletionInterval); + this.deletionInterval = 0; + } } private Path makeTrashRelativePath(Path basePath, Path rmFilePath) { @@ -109,7 +115,7 @@ public class TrashPolicyDefault extends TrashPolicy { @Override public boolean isEnabled() { - return deletionInterval != 0; + return deletionInterval > 0; } @SuppressWarnings("deprecation") diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java index 568821be280..04f56fb0754 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java @@ -132,6 +132,9 @@ public class TestTrash { conf.setLong(FS_TRASH_INTERVAL_KEY, 0); // disabled assertFalse(new Trash(conf).isEnabled()); + conf.setLong(FS_TRASH_INTERVAL_KEY, -1); // disabled + assertFalse(new Trash(conf).isEnabled()); + conf.setLong(FS_TRASH_INTERVAL_KEY, 10); // 10 minute assertTrue(new Trash(conf).isEnabled()); @@ -526,6 +529,9 @@ public class TestTrash { conf.setLong(FS_TRASH_INTERVAL_KEY, 0); // disabled assertFalse(new Trash(conf).isEnabled()); + conf.setLong(FS_TRASH_INTERVAL_KEY, -1); // disabled + assertFalse(new Trash(conf).isEnabled()); + conf.setLong(FS_TRASH_INTERVAL_KEY, 10); // 10 minute assertTrue(new Trash(conf).isEnabled());