You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by af...@apache.org on 2015/12/10 18:58:05 UTC

reef git commit: [REEF-1045] Add exception handling in LocalScratchSpace

Repository: reef
Updated Branches:
  refs/heads/master fe6194cac -> 57a44fe0d


[REEF-1045] Add exception handling in LocalScratchSpace

This PR implements two TODOs in `LocalScratchSpace.java`
by adding exception handling logic.

JIRA:
  [REEF-1045](https://issues.apache.org/jira/browse/REEF-1045)

Pull request:
  This closes #710


Project: http://git-wip-us.apache.org/repos/asf/reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/57a44fe0
Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/57a44fe0
Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/57a44fe0

Branch: refs/heads/master
Commit: 57a44fe0d62373b001faf546cc8d83ef2548b527
Parents: fe6194c
Author: Dongjoon Hyun <do...@apache.org>
Authored: Mon Dec 7 20:56:54 2015 +0900
Committer: Andrew Chung <af...@gmail.com>
Committed: Thu Dec 10 09:57:27 2015 -0800

----------------------------------------------------------------------
 .../io/storage/local/LocalScratchSpace.java     | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/reef/blob/57a44fe0/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalScratchSpace.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalScratchSpace.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalScratchSpace.java
index 5ad2e32..084fe8c 100644
--- a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalScratchSpace.java
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalScratchSpace.java
@@ -24,9 +24,12 @@ import java.io.File;
 import java.io.IOException;
 import java.util.Set;
 import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.logging.Logger;
 
 public class LocalScratchSpace implements ScratchSpace {
 
+  private static final Logger LOG = Logger.getLogger(LocalScratchSpace.class.getName());
+
   private final String jobName;
   private final String evaluatorName;
   private final Set<File> tempFiles = new ConcurrentSkipListSet<>();
@@ -68,18 +71,25 @@ public class LocalScratchSpace implements ScratchSpace {
   public long usedSpace() {
     long ret = 0;
     for (final File f : tempFiles) {
-      // TODO: Error handling...
-      ret += f.length();
+      try {
+        ret += f.length();
+      } catch (final SecurityException e) {
+        LOG.info("Fail to get file info:" + f.getAbsolutePath());
+      }
     }
     return ret;
   }
 
   @Override
   public void delete() {
-    // TODO: Error handling. Files.delete() would give us an exception. We
-    // should pass a set of Exceptions into a ReefRuntimeException.
     for (final File f : tempFiles) {
-      f.delete();
+      try {
+        if (!f.delete()) {
+          f.deleteOnExit();
+        }
+      } catch (final SecurityException e) {
+        throw new RuntimeException("Fail to delete file:" + f.getAbsolutePath(), e);
+      }
     }
     tempFiles.clear();
   }