HADOOP-15736. Trash : Negative Value For Deletion Interval Leads To Abnormal Behaviour. Contributed by Ayush Saxena.

(cherry picked from commit 7ad27e97f05b13b33fdcef9cb63ace9c1728bfb5)
This commit is contained in:
Vinayakumar B 2018-09-20 09:31:35 +05:30
parent 3fb6787295
commit 2aa3854633
2 changed files with 13 additions and 1 deletions

View File

@ -101,6 +101,12 @@ public void initialize(Configuration conf, FileSystem fs) {
this.emptierInterval = (long)(conf.getFloat( this.emptierInterval = (long)(conf.getFloat(
FS_TRASH_CHECKPOINT_INTERVAL_KEY, FS_TRASH_CHECKPOINT_INTERVAL_DEFAULT) FS_TRASH_CHECKPOINT_INTERVAL_KEY, FS_TRASH_CHECKPOINT_INTERVAL_DEFAULT)
* MSECS_PER_MINUTE); * 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) { private Path makeTrashRelativePath(Path basePath, Path rmFilePath) {
@ -109,7 +115,7 @@ private Path makeTrashRelativePath(Path basePath, Path rmFilePath) {
@Override @Override
public boolean isEnabled() { public boolean isEnabled() {
return deletionInterval != 0; return deletionInterval > 0;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

View File

@ -132,6 +132,9 @@ public static void trashShell(final Configuration conf, final Path base,
conf.setLong(FS_TRASH_INTERVAL_KEY, 0); // disabled conf.setLong(FS_TRASH_INTERVAL_KEY, 0); // disabled
assertFalse(new Trash(conf).isEnabled()); 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 conf.setLong(FS_TRASH_INTERVAL_KEY, 10); // 10 minute
assertTrue(new Trash(conf).isEnabled()); assertTrue(new Trash(conf).isEnabled());
@ -526,6 +529,9 @@ public void testExistingFileTrash() throws IOException {
conf.setLong(FS_TRASH_INTERVAL_KEY, 0); // disabled conf.setLong(FS_TRASH_INTERVAL_KEY, 0); // disabled
assertFalse(new Trash(conf).isEnabled()); 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 conf.setLong(FS_TRASH_INTERVAL_KEY, 10); // 10 minute
assertTrue(new Trash(conf).isEnabled()); assertTrue(new Trash(conf).isEnabled());