You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/08/11 13:18:55 UTC

ignite git commit: IGNITE-3668 IGFS: Local secondary: Review all "throw new IOException" places. This closes #944.

Repository: ignite
Updated Branches:
  refs/heads/ignite-1926 866ef6bad -> d15f65c98


IGNITE-3668 IGFS: Local secondary: Review all "throw new IOException" places. This closes #944.


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

Branch: refs/heads/ignite-1926
Commit: d15f65c9870970c650bbb4a1e0c38c565b1ec8cd
Parents: 866ef6b
Author: tledkov-gridgain <tl...@gridgain.com>
Authored: Thu Aug 11 16:18:45 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Thu Aug 11 16:18:45 2016 +0300

----------------------------------------------------------------------
 .../hadoop/fs/LocalIgfsSecondaryFileSystem.java | 75 ++++++++++----------
 1 file changed, 36 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d15f65c9/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/LocalIgfsSecondaryFileSystem.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/LocalIgfsSecondaryFileSystem.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/LocalIgfsSecondaryFileSystem.java
index afd8d03..c26ab25 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/LocalIgfsSecondaryFileSystem.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/LocalIgfsSecondaryFileSystem.java
@@ -31,6 +31,7 @@ import org.apache.ignite.igfs.IgfsFile;
 import org.apache.ignite.igfs.IgfsParentNotDirectoryException;
 import org.apache.ignite.igfs.IgfsPath;
 import org.apache.ignite.igfs.IgfsPathAlreadyExistsException;
+import org.apache.ignite.igfs.IgfsPathIsNotDirectoryException;
 import org.apache.ignite.igfs.IgfsPathNotFoundException;
 import org.apache.ignite.igfs.IgfsUserContext;
 import org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystem;
@@ -195,20 +196,21 @@ public class LocalIgfsSecondaryFileSystem implements IgfsSecondaryFileSystem, Li
 
     /** {@inheritDoc} */
     @Override public void rename(IgfsPath src, IgfsPath dest) {
-        try {
-            File srcFile = fileForPath(src);
-            File destFile = fileForPath(dest);
+        File srcFile = fileForPath(src);
+        File destFile = fileForPath(dest);
 
-            if (!srcFile.exists())
-                throw new IOException("File not found: " + srcFile);
+        if (!srcFile.exists())
+            throw new IgfsPathNotFoundException("Failed to perform rename because source path not found: " + src);
 
-            if (srcFile.isDirectory() && destFile.isFile())
-                throw new IOException("Failed rename directory to existing file: [src=" + src + ", dest=" + dest + ']');
+        if (srcFile.isDirectory() && destFile.isFile())
+            throw new IgfsPathIsNotDirectoryException("Failed to perform rename because destination path is " +
+                "directory and source path is file [src=" + src + ", dest=" + dest + ']');
 
+        try {
             if (destFile.isDirectory())
                 Files.move(srcFile.toPath(), destFile.toPath().resolve(srcFile.getName()));
             else if(!srcFile.renameTo(destFile))
-                throw new IgfsException("Failed to rename (secondary file system returned false) " +
+                throw new IgfsException("Failed to perform rename (underlying file system returned false) " +
                     "[src=" + src + ", dest=" + dest + ']');
         }
         catch (IOException e) {
@@ -219,28 +221,22 @@ public class LocalIgfsSecondaryFileSystem implements IgfsSecondaryFileSystem, Li
     /** {@inheritDoc} */
     @SuppressWarnings("ConstantConditions")
     @Override public boolean delete(IgfsPath path, boolean recursive) {
-        try {
-            File f = fileForPath(path);
+        File f = fileForPath(path);
 
-            // TODO: IGNITE-3642.
-            if (!recursive || !f.isDirectory())
-                return f.delete();
-            else
-                return deleteDirectory(f);
-        }
-        catch (IOException e) {
-            throw handleSecondaryFsError(e, "Failed to delete file [path=" + path + ", recursive=" + recursive + "]");
-        }
+        // TODO: IGNITE-3642.
+        if (!recursive || !f.isDirectory())
+            return f.delete();
+        else
+            return deleteDirectory(f);
     }
 
     /**
      * Delete directory recursively.
      *
      * @param dir Directory.
-     * @throws IOException If fails.
      * @return {@code true} if successful.
      */
-    private boolean deleteDirectory(File dir) throws IOException {
+    private boolean deleteDirectory(File dir) {
         File[] entries = dir.listFiles();
 
         if (entries != null) {
@@ -249,7 +245,7 @@ public class LocalIgfsSecondaryFileSystem implements IgfsSecondaryFileSystem, Li
                     deleteDirectory(entry);
                 else if (entry.isFile()) {
                     if (!entry.delete())
-                        throw new IOException("Cannot remove file: " + entry);
+                        return false;
                 }
                 else
                     // TODO: IGNITE-3642.
@@ -258,7 +254,7 @@ public class LocalIgfsSecondaryFileSystem implements IgfsSecondaryFileSystem, Li
         }
 
         if (!dir.delete())
-            throw new IOException("Cannot remove directory: " + dir);
+            return false;
 
         return true;
     }
@@ -266,7 +262,7 @@ public class LocalIgfsSecondaryFileSystem implements IgfsSecondaryFileSystem, Li
     /** {@inheritDoc} */
     @Override public void mkdirs(IgfsPath path) {
         if (!mkdirs0(fileForPath(path)))
-            throw new IgniteException("Failed to make directories [path=" + path + "]");
+            throw new IgniteException("Failed to make directories (underlying file system returned false): " + path);
     }
 
     /** {@inheritDoc} */
@@ -396,11 +392,11 @@ public class LocalIgfsSecondaryFileSystem implements IgfsSecondaryFileSystem, Li
                 if (create)
                     return create0(path, false, bufSize);
                 else
-                    throw new IOException("File not found: " + path);
+                    throw new IgfsPathNotFoundException("Failed to append to file because it doesn't exist: " + path);
             }
         }
         catch (IOException e) {
-            throw handleSecondaryFsError(e, "Failed to append file [path=" + path + ']');
+            throw handleSecondaryFsError(e, "Failed to append to file because it doesn't exist: " + path);
         }
     }
 
@@ -449,7 +445,7 @@ public class LocalIgfsSecondaryFileSystem implements IgfsSecondaryFileSystem, Li
                     String val = props.get(name);
 
                     if (val ==  null)
-                        throw new IllegalArgumentException("File property not found [path=" + path + ", name=" + name + ']');
+                        throw new IllegalArgumentException("Property not found [path=" + path + ", name=" + name + ']');
 
                     return val;
                 }
@@ -617,22 +613,23 @@ public class LocalIgfsSecondaryFileSystem implements IgfsSecondaryFileSystem, Li
      * @return Output stream.
      */
     private OutputStream create0(IgfsPath path, boolean overwrite, int bufSize) {
-        try {
-            File file = fileForPath(path);
+        File file = fileForPath(path);
 
-            boolean exists = file.exists();
+        boolean exists = file.exists();
 
-            if (exists) {
-                if (!overwrite)
-                    throw new IOException("File already exists.");
-            }
-            else {
-                File parent = file.getParentFile();
+        if (exists) {
+            if (!overwrite)
+                throw new IgfsPathAlreadyExistsException("Failed to create a file because it already exists: " + path);
+        }
+        else {
+            File parent = file.getParentFile();
 
-                if (!mkdirs0(parent))
-                    throw new IOException("Failed to create parent directory: " + parent);
-            }
+            if (!mkdirs0(parent))
+                throw new IgfsException("Failed to create parent directory for file (underlying file system " +
+                    "returned false): " + path);
+        }
 
+        try {
             return new BufferedOutputStream(new FileOutputStream(file), bufSize);
         }
         catch (IOException e) {