]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Hadoop: Some changes in order to reduce the number of messages sent on non-existent...
authorGreg Farnum <gregf@hq.newdream.net>
Tue, 8 Sep 2009 06:48:05 +0000 (23:48 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Tue, 8 Sep 2009 19:23:38 +0000 (12:23 -0700)
src/client/hadoop/CephFSInterface.cc
src/client/hadoop/ceph/CephFileSystem.java

index 4e208b6b9d2401627f3abdb4af11041d3c8bb93a..975d0c3e3fad12709b24f119fa949c3e86db5fcb 100644 (file)
@@ -313,8 +313,9 @@ JNIEXPORT jobjectArray JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_cep
   const char *c_path = env->GetStringUTFChars(j_path, 0);
   if (c_path == NULL) return NULL;
   DIR *dirp;
-  ceph_opendir(c_path, &dirp);
   int r;
+  r = ceph_opendir(c_path, &dirp);
+  if (r<0) return r;
   int buflen = 100; //good default?
   char *buf = new char[buflen];
   string *ent;
index 9b285e77675253953f130da81f0159495712ae46..c45ae8dead564e01e386d59b5ef75b9c492f467f 100644 (file)
@@ -241,32 +241,10 @@ public class CephFileSystem extends FileSystem {
     if (!initialized) return;
     debug("setWorkingDirecty:enter with new working dir " + dir);
     Path abs_path = makeAbsolute(dir);
-
-    // error conditions if path's not a directory
-    boolean isDir = false;
-    boolean path_exists = false;
-    try {
-      isDir = isDirectory(abs_path);
-      if (!isDir) path_exists = exists(abs_path);
-    }
-
-    catch (IOException e) {
-      debug("Warning: isDirectory threw an exception");
-    }
-
-    if (!isDir) {
-      if (path_exists)
-       debug("Warning: SetWorkingDirectory(" + dir.toString() + 
-                          "): path is not a directory");
-      else
-       debug("Warning: SetWorkingDirectory(" + dir.toString() + 
-                          "): path does not exist");
-    }
-    else {
-      debug("calling ceph_setcwd from Java");
-      ceph_setcwd(abs_path.toString());
-      debug("returned from ceph_setcwd to Java" );
-    }
+    debug("calling ceph_setcwd from Java");
+    if (!ceph_setcwd(abs_path.toString()))
+      debug("Warning:ceph_setcwd failed for some reason on path " + abs_path);
+    debug("returned from ceph_setcwd to Java" );
     debug("setWorkingDirectory:exit");
   }
 
@@ -419,8 +397,8 @@ public class CephFileSystem extends FileSystem {
                       +"CephFileSystem before calling other methods.");
     debug("listStatus:enter with path " + path);
     Path abs_path = makeAbsolute(path);
-    if (isDirectory(abs_path)) {
-      Path[] paths = listPaths(abs_path);
+    Path[] paths = listPaths(abs_path);
+    if (paths != null) {
       FileStatus[] statuses = new FileStatus[paths.length];
       for (int i = 0; i < paths.length; ++i) {
        statuses[i] = getFileStatus(paths[i]);
@@ -428,7 +406,9 @@ public class CephFileSystem extends FileSystem {
       debug("listStatus:exit");
       return statuses;
     }
-    return null; //it's a file, or DNE
+    if (!isFile(path)) throw new FileNotFoundException(); //if we get here, listPaths returned null
+    //which means that the input wasn't a directory, so throw an Exception if it's not a file
+    return null; //or return null if it's a file
   }
 
   @Override
@@ -489,27 +469,30 @@ public class CephFileSystem extends FileSystem {
     // throw an exception if !CreateFlag.OVERWRITE.
 
     // Step 1: existence test
-    if(isDirectory(abs_path))
-      throw new IOException("create: Cannot overwrite existing directory \""
-                           + path.toString() + "\" with a file");      
-    if (progress!=null) progress.progress();
-    //    if (!flag.contains(CreateFlag.OVERWRITE)) {
-    if (!overwrite) {
-      if (exists(abs_path)) {
+    boolean exists = exists(abs_path);
+    if (exists) {
+      if(isDirectory(abs_path))
+       throw new IOException("create: Cannot overwrite existing directory \""
+                             + path.toString() + "\" with a file");
+      if (!overwrite)
+      //if (!flag.contains(CreateFlag.OVERWRITE)) {
        throw new IOException("createRaw: Cannot open existing file \"" 
                              + abs_path.toString() 
                              + "\" for writing without overwrite flag");
-      }
     }
 
+    if (progress!=null) progress.progress();
+
     // Step 2: create any nonexistent directories in the path
-    Path parent =  abs_path.getParent();
-    if (parent != null) { // if parent is root, we're done
-      int r = ceph_mkdirs(parent.toString(), permission.toShort());
-      if (!(r==0 || r==-EEXIST))
-       throw new IOException ("Error creating parent directory; code: " + r);
+    if (!exists) {
+      Path parent = abs_path.getParent();
+      if (parent != null) { // if parent is root, we're done
+       int r = ceph_mkdirs(parent.toString(), permission.toShort());
+       if (!(r==0 || r==-EEXIST))
+         throw new IOException ("Error creating parent directory; code: " + r);
+      }
+      if (progress!=null) progress.progress();
     }
-    if (progress!=null) progress.progress();
     // Step 3: open the file
     debug("calling ceph_open_for_overwrite from Java");
     int fh = ceph_open_for_overwrite(abs_path.toString(), (int)permission.toShort());
@@ -540,15 +523,13 @@ public class CephFileSystem extends FileSystem {
     debug("open:enter with path " + path);
     Path abs_path = makeAbsolute(path);
     
-    if(!isFile(abs_path)) {
-      if (!exists(abs_path))
-       throw new IOException("open:  absolute path \""  + abs_path.toString()
-                             + "\" does not exist");
-      else
-       throw new IOException("open:  absolute path \""  + abs_path.toString()
-                             + "\" is not a file");
-    }
-    
+    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());
@@ -563,7 +544,7 @@ public class CephFileSystem extends FileSystem {
     FSInputStream cephIStream = new CephInputStream(getConf(), fh, size);
     debug("open:exit");
     return new FSDataInputStream(cephIStream);
-  }
+    }
 
   /**
    * Rename a file or directory.
@@ -682,7 +663,9 @@ public class CephFileSystem extends FileSystem {
     // sanity check
     if (abs_path.toString().equals(root))
       throw new IOException("Error: deleting the root directory is a Bad Idea.");
-    
+
+    if (!exists(abs_path)) return false;
+
     // if the path is a file, try to delete it.
     if (isFile(abs_path)) {
       boolean result = ceph_unlink(abs_path.toString());
@@ -694,9 +677,7 @@ public class CephFileSystem extends FileSystem {
       return result;
     }
 
-    if (!isDirectory(abs_path)) return false;
-    
-    /* If the path is a directory, recursively try to delete its contents,
+    /* The path is a directory, so recursively try to delete its contents,
        and then delete the directory. */
     if (!recursive) {
       throw new IOException("Directories must be deleted recursively!");
@@ -753,16 +734,12 @@ public class CephFileSystem extends FileSystem {
                       +"CephFileSystem before calling other methods.");
     debug("getBlockSize:enter with path " + path);
     Path abs_path = makeAbsolute(path);
-    if (!exists(abs_path)) {
-      throw new IOException("org.apache.hadoop.fs.ceph.CephFileSystem.getBlockSize: File or directory " + path.toString() + " does not exist.");
-    }
     long result = ceph_getblocksize(abs_path.toString());
-    
-    if (result < 4096) {
-      debug("org.apache.hadoop.fs.ceph.CephFileSystem.getBlockSize: " + 
-                        "path exists; strange block size of " + result + " defaulting to 4096");
-      return 4096;
-    }
+  
+    if (result < 0)
+      throw new IOException("org.apache.hadoop.fs.ceph.CephFileSystem.getBlockSize: File or directory "
+                           + path.toString() + " does not exist.");
+
     debug("getBlockSize:exit with result " + result);
     return result;
   }
@@ -804,12 +781,11 @@ public class CephFileSystem extends FileSystem {
     Path abs_path = makeAbsolute(path);
 
     // If it's a directory, get the listing. Otherwise, complain and give up.
-    if (isDirectory(abs_path)) {
-      debug("calling ceph_getdir from Java with path " + abs_path);
-      dirlist = ceph_getdir(abs_path.toString());
-      debug("returning from ceph_getdir to Java");
-    }
-    else {
+    debug("calling ceph_getdir from Java with path " + abs_path);
+    dirlist = ceph_getdir(abs_path.toString());
+    debug("returning from ceph_getdir to Java");
+
+    if (dirlist == null) {
       throw new IOException("listPaths: path " + path.toString() + " is not a directory.");
     }