You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by el...@apache.org on 2012/09/05 21:42:10 UTC
svn commit: r1381319 - in
/hadoop/common/trunk/hadoop-common-project/hadoop-common: CHANGES.txt
src/main/java/org/apache/hadoop/fs/Trash.java
src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java
src/test/java/org/apache/hadoop/fs/TestTrash.java
Author: eli
Date: Wed Sep 5 19:42:09 2012
New Revision: 1381319
URL: http://svn.apache.org/viewvc?rev=1381319&view=rev
Log:
HADOOP-8770. NN should not RPC to self to find trash defaults. Contributed by Eli Collins
Modified:
hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Trash.java
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1381319&r1=1381318&r2=1381319&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Wed Sep 5 19:42:09 2012
@@ -465,6 +465,8 @@ Branch-2 ( Unreleased changes )
HADOOP-8764. CMake: HADOOP-8737 broke ARM build. (Trevor Robinson via eli)
+ HADOOP-8770. NN should not RPC to self to find trash defaults. (eli)
+
BREAKDOWN OF HDFS-3042 SUBTASKS
HADOOP-8220. ZKFailoverController doesn't handle failure to become active
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Trash.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Trash.java?rev=1381319&r1=1381318&r2=1381319&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Trash.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Trash.java Wed Sep 5 19:42:09 2012
@@ -68,8 +68,26 @@ public class Trash extends Configured {
public static boolean moveToAppropriateTrash(FileSystem fs, Path p,
Configuration conf) throws IOException {
Path fullyResolvedPath = fs.resolvePath(p);
- Trash trash = new Trash(FileSystem.get(fullyResolvedPath.toUri(), conf), conf);
- boolean success = trash.moveToTrash(fullyResolvedPath);
+ FileSystem fullyResolvedFs =
+ FileSystem.get(fullyResolvedPath.toUri(), conf);
+ // If the trash interval is configured server side then clobber this
+ // configuration so that we always respect the server configuration.
+ try {
+ long trashInterval = fullyResolvedFs.getServerDefaults(
+ fullyResolvedPath).getTrashInterval();
+ if (0 != trashInterval) {
+ Configuration confCopy = new Configuration(conf);
+ confCopy.setLong(CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY,
+ trashInterval);
+ conf = confCopy;
+ }
+ } catch (Exception e) {
+ // If we can not determine that trash is enabled server side then
+ // bail rather than potentially deleting a file when trash is enabled.
+ throw new IOException("Failed to get server trash configuration", e);
+ }
+ Trash trash = new Trash(fullyResolvedFs, conf);
+ boolean success = trash.moveToTrash(fullyResolvedPath);
if (success) {
System.out.println("Moved: '" + p + "' to trash at: " +
trash.getCurrentTrashDir() );
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java?rev=1381319&r1=1381318&r2=1381319&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java Wed Sep 5 19:42:09 2012
@@ -79,24 +79,9 @@ public class TrashPolicyDefault extends
this.trash = new Path(home, TRASH);
this.homesParent = home.getParent();
this.current = new Path(trash, CURRENT);
- long trashInterval = 0;
- try {
- trashInterval = fs.getServerDefaults(home).getTrashInterval();
- } catch (IOException ioe) {
- LOG.warn("Unable to get server defaults", ioe);
- }
- // If the trash interval is not configured or is disabled on the
- // server side then check the config which may be client side.
- if (0 == trashInterval) {
- this.deletionInterval = (long)(conf.getFloat(
- FS_TRASH_INTERVAL_KEY, FS_TRASH_INTERVAL_DEFAULT)
- * MSECS_PER_MINUTE);
- } else {
- this.deletionInterval = trashInterval * MSECS_PER_MINUTE;
- }
- // For the checkpoint interval use the given config instead of
- // checking the server as it's OK if a client starts an emptier
- // with a different interval than the server.
+ this.deletionInterval = (long)(conf.getFloat(
+ FS_TRASH_INTERVAL_KEY, FS_TRASH_INTERVAL_DEFAULT)
+ * MSECS_PER_MINUTE);
this.emptierInterval = (long)(conf.getFloat(
FS_TRASH_CHECKPOINT_INTERVAL_KEY, FS_TRASH_CHECKPOINT_INTERVAL_DEFAULT)
* MSECS_PER_MINUTE);
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java?rev=1381319&r1=1381318&r2=1381319&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java Wed Sep 5 19:42:09 2012
@@ -99,7 +99,6 @@ public class TestTrash extends TestCase
}
/**
- *
* Test trash for the shell's delete command for the default file system
* specified in the paramter conf
* @param conf
@@ -429,8 +428,10 @@ public class TestTrash extends TestCase
String output = byteStream.toString();
System.setOut(stdout);
System.setErr(stderr);
- assertTrue("skipTrash wasn't suggested as remedy to failed rm command",
- output.indexOf(("Consider using -skipTrash option")) != -1 );
+ assertTrue("skipTrash wasn't suggested as remedy to failed rm command" +
+ " or we deleted / even though we could not get server defaults",
+ output.indexOf("Consider using -skipTrash option") != -1 ||
+ output.indexOf("Failed to determine server trash configuration") != -1);
}
}