]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Hadoop: Refactor open to open optimistically and then check for errors
authorGreg Farnum <gregf@hq.newdream.net>
Tue, 8 Sep 2009 18:25:37 +0000 (11:25 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Tue, 8 Sep 2009 19:41:45 +0000 (12:41 -0700)
on the return code and cached data.
Also fix a bad return in CephFSInterface from the last commit.

src/client/hadoop/CephFSInterface.cc
src/client/hadoop/ceph/CephFileSystem.java

index 975d0c3e3fad12709b24f119fa949c3e86db5fcb..786d1cb905f72a37d2d0e6294f63aa21467a10a5 100644 (file)
@@ -315,7 +315,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_cep
   DIR *dirp;
   int r;
   r = ceph_opendir(c_path, &dirp);
-  if (r<0) return r;
+  if (r<0) return NULL;
   int buflen = 100; //good default?
   char *buf = new char[buflen];
   string *ent;
index c45ae8dead564e01e386d59b5ef75b9c492f467f..a60fa5ff5052144d89ce0d5c019e261702d466a1 100644 (file)
@@ -50,6 +50,7 @@ import org.apache.hadoop.fs.FileStatus;
 public class CephFileSystem extends FileSystem {
 
   private static final int EEXIST = 17;
+  private static final int ENOENT = 2;
 
   private URI uri;
 
@@ -523,16 +524,20 @@ public class CephFileSystem extends FileSystem {
     debug("open:enter with path " + path);
     Path abs_path = makeAbsolute(path);
     
-    if (!exists(abs_path))
-      throw new IOException("open:  absolute path \""  + abs_path.toString()
-                           + "\" does not exist");
-    if(!isFile(abs_path))
-      throw new IOException("open:  absolute path \""  + abs_path.toString()
-                           + "\" is not a file");
-
     int fh = ceph_open_for_read(abs_path.toString());
-    if (fh < 0) {
-      throw new IOException("open: Failed to open file " + abs_path.toString());
+    if (fh < 0) { //uh-oh, something's bad!
+      if (fh == -ENOENT) //well that was a stupid open
+       throw new IOException("open:  absolute path \""  + abs_path.toString()
+                             + "\" does not exist");
+      else //hrm...the file exists but we can't open it :(
+       throw new IOException("open: Failed to open file " + abs_path.toString());
+    }
+
+    if(isDirectory(abs_path)) { //yes, it is possible to open Ceph directories
+      //but that doesn't mean you should in Hadoop!
+      ceph_close(fh);
+      throw new IOException("open:  absolute path \""  + abs_path.toString()
+                           + "\" is a directory!");
     }
     Stat lstat = new Stat();
     ceph_stat(abs_path.toString(), lstat);