[MINOR] Robust hdfs file delete w/ retries (fix occasional test issues) Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/c663e31c Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/c663e31c Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/c663e31c
Branch: refs/heads/master Commit: c663e31ceefb383195d5405630af99b53260827d Parents: c7f5f08 Author: Matthias Boehm <[email protected]> Authored: Fri Mar 17 12:52:20 2017 -0700 Committer: Matthias Boehm <[email protected]> Committed: Fri Mar 17 12:52:42 2017 -0700 ---------------------------------------------------------------------- .../sysml/runtime/util/MapReduceTool.java | 36 +++++++++++--------- .../functions/io/SeqParReadTest.java | 3 +- 2 files changed, 20 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/c663e31c/src/main/java/org/apache/sysml/runtime/util/MapReduceTool.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/util/MapReduceTool.java b/src/main/java/org/apache/sysml/runtime/util/MapReduceTool.java index ff121b6..7a28de7 100644 --- a/src/main/java/org/apache/sysml/runtime/util/MapReduceTool.java +++ b/src/main/java/org/apache/sysml/runtime/util/MapReduceTool.java @@ -64,6 +64,8 @@ import org.apache.wink.json4j.OrderedJSONObject; public class MapReduceTool { + private static final int MAX_DELETE_RETRIES = 10; + private static final Log LOG = LogFactory.getLog(MapReduceTool.class.getName()); private static JobConf _rJob = null; //cached job conf for read-only operations @@ -119,18 +121,6 @@ public class MapReduceTool } return ret; } - - public static void deleteFileIfExistOnHDFS(Path outpath, JobConf job) throws IOException { - if (FileSystem.get(job).exists(outpath)) { - FileSystem.get(job).delete(outpath, true); - } - } - - public static void deleteFileIfExistOnLFS(Path outpath, JobConf job) throws IOException { - if (FileSystem.getLocal(job).exists(outpath)) { - FileSystem.getLocal(job).delete(outpath, true); - } - } public static void deleteFileWithMTDIfExistOnHDFS(String fname) throws IOException { deleteFileIfExistOnHDFS(fname); @@ -138,11 +128,23 @@ public class MapReduceTool } public static void deleteFileIfExistOnHDFS(String dir) throws IOException { - Path outpath = new Path(dir); - FileSystem fs = FileSystem.get(_rJob); - if (fs.exists(outpath)) { - //System.err.println("Deleting " + outpath + " ... "); - fs.delete(outpath, true); + deleteFileIfExists(FileSystem.get(_rJob), new Path(dir)); + } + + public static void deleteFileIfExistOnHDFS(Path outpath, JobConf job) throws IOException { + deleteFileIfExists(FileSystem.get(job), outpath); + } + + public static void deleteFileIfExistOnLFS(Path outpath, JobConf job) throws IOException { + deleteFileIfExists(FileSystem.getLocal(job), outpath); + } + + private static void deleteFileIfExists(FileSystem fs, Path outpath) throws IOException { + if( fs.exists(outpath) ) { + int retries = MAX_DELETE_RETRIES; + while( !fs.delete(outpath, true) && retries > 0 ) { + retries--; + } } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/c663e31c/src/test/java/org/apache/sysml/test/integration/functions/io/SeqParReadTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/io/SeqParReadTest.java b/src/test/java/org/apache/sysml/test/integration/functions/io/SeqParReadTest.java index f33d728..d26779c 100644 --- a/src/test/java/org/apache/sysml/test/integration/functions/io/SeqParReadTest.java +++ b/src/test/java/org/apache/sysml/test/integration/functions/io/SeqParReadTest.java @@ -270,8 +270,7 @@ public class SeqParReadTest extends AutomatedTestBase { private void writeMatrix( double[][] A, String fname, OutputInfo oi, long rows, long cols, int brows, int bcols, long nnz ) throws DMLRuntimeException, IOException { - MapReduceTool.deleteFileIfExistOnHDFS(fname); - MapReduceTool.deleteFileIfExistOnHDFS(fname+".mtd"); + MapReduceTool.deleteFileWithMTDIfExistOnHDFS(fname); MatrixCharacteristics mc = new MatrixCharacteristics(rows, cols, brows, bcols, nnz); MatrixBlock mb = DataConverter.convertToMatrixBlock(A);
