]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Hadoop: Adds the getStatus method introduced by Hadoop .21;
authorGreg Farnum <gregf@hq.newdream.net>
Wed, 12 Aug 2009 23:54:47 +0000 (16:54 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Mon, 17 Aug 2009 19:21:13 +0000 (12:21 -0700)
currently commented out since it doesn't compile in .20, but it's tested.

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

index 005edf666a5e523aa1dcd248380ba8fecc62e7db..5ca5ab77b954006a455df25b5973e8c04f7da64b 100644 (file)
@@ -506,6 +506,92 @@ JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1k
   return true;
 }
 
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_stat
+ * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/Stat;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1stat
+(JNIEnv * env, jobject obj, jstring j_path, jobject j_stat) {
+  //setup variables
+  struct stat st;
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  if (c_path == NULL) return false;
+
+  jclass cls = env->GetObjectClass(j_stat);
+  if (cls == NULL) return false;
+  jfieldID c_size_id = env->GetFieldID(cls, "size", "J");
+  if (c_size_id == NULL) return false;
+  jfieldID c_dir_id = env->GetFieldID(cls, "is_dir", "Z");
+  if (c_dir_id == NULL) return false;
+  jfieldID c_block_id = env->GetFieldID(cls, "block_size", "J");
+  if (c_block_id == NULL) return false;
+  jfieldID c_mod_id = env->GetFieldID(cls, "mod_time", "J");
+  if (c_mod_id == NULL) return false;
+  jfieldID c_access_id = env->GetFieldID(cls, "access_time", "J");
+  if (c_access_id == NULL) return false;
+  jfieldID c_mode_id = env->GetFieldID(cls, "mode", "I");
+  if (c_mode_id == NULL) return false;
+  jfieldID c_user_id = env->GetFieldID(cls, "user_id", "I");
+  if (c_user_id == NULL) return false;
+  jfieldID c_group_id = env->GetFieldID(cls, "group_id", "I");
+  if (c_group_id == NULL) return false;
+
+  //do actual lstat
+  int r = ceph_lstat(c_path, &st);
+  env->ReleaseStringUTFChars(j_path, c_path);
+
+  if (r < 0) return false; //fail out; file DNE or Ceph broke
+
+  //put variables from struct stat into Java
+  env->SetLongField(j_stat, c_size_id, (long)st.st_size);
+  env->SetBooleanField(j_stat, c_dir_id, (0 != S_ISDIR(st.st_mode)));
+  env->SetLongField(j_stat, c_block_id, (long)st.st_blksize);
+  env->SetLongField(j_stat, c_mod_id, (long long)st.st_mtime);
+  env->SetLongField(j_stat, c_access_id, (long long)st.st_atime);
+  env->SetIntField(j_stat, c_mode_id, (int)st.st_mode);
+  env->SetIntField(j_stat, c_user_id, (int)st.st_uid);
+  env->SetIntField(j_stat, c_group_id, (int)st.st_gid);
+
+  //return happy
+  return true;
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_statfs
+ * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/CephStat;)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1statfs
+(JNIEnv * env, jobject obj, jstring j_path, jobject j_cephstat)
+{
+  //setup variables
+  struct statvfs stbuf;
+  const char *c_path = env->GetStringUTFChars(j_path, 0);
+  if (c_path == NULL) return -ENOMEM;
+  jclass cls = env->GetObjectClass(j_cephstat);
+  if (cls == NULL) return 1; //JVM error of some kind
+  jfieldID c_capacity_id = env->GetFieldID(cls, "capacity", "J");
+  jfieldID c_used_id = env->GetFieldID(cls, "used", "J");
+  jfieldID c_remaining_id = env->GetFieldID(cls, "remaining", "J");
+
+  //do the statfs
+  int r = ceph_statfs(c_path, &stbuf);
+  env->ReleaseStringUTFChars(j_path, c_path);
+
+
+  if (r!=0) return r; //something broke
+
+  //place info into Java
+  env->SetLongField(j_cephstat, c_capacity_id,
+                   (long)stbuf.f_blocks*stbuf.f_bsize);
+  env->SetLongField(j_cephstat, c_used_id,
+                   (long)(stbuf.f_blocks-stbuf.f_bavail)*stbuf.f_bsize);
+  env->SetLongField(j_cephstat, c_remaining_id,
+                   (long)stbuf.f_bavail*stbuf.f_bsize);
+  return r;
+}
+
 /*
  * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
  * Method:    ceph_replication
@@ -554,7 +640,7 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1setTi
   attr.st_mtime = mtime;
   attr.st_atime = atime;
   //may need to fill in uid and gid here later on...
-  ceph_setattr(c_path, &attr, mask);
+  return ceph_setattr(c_path, &attr, mask);
 }
 
 /*
@@ -701,54 +787,3 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1wri
 
   return result;
 }
-
-/*
- * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
- * Method:    ceph_stat
- * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/Stat;)Z
- */
-JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1stat
-(JNIEnv * env, jobject obj, jstring j_path, jobject j_stat) {
-  //setup variables
-  struct stat st;
-  const char* c_path = env->GetStringUTFChars(j_path, 0);
-  if (c_path == NULL) return false;
-
-  jclass cls = env->GetObjectClass(j_stat);
-  if (cls == NULL) return false;
-  jfieldID c_size_id = env->GetFieldID(cls, "size", "J");
-  if (c_size_id == NULL) return false;
-  jfieldID c_dir_id = env->GetFieldID(cls, "is_dir", "Z");
-  if (c_dir_id == NULL) return false;
-  jfieldID c_block_id = env->GetFieldID(cls, "block_size", "J");
-  if (c_block_id == NULL) return false;
-  jfieldID c_mod_id = env->GetFieldID(cls, "mod_time", "J");
-  if (c_mod_id == NULL) return false;
-  jfieldID c_access_id = env->GetFieldID(cls, "access_time", "J");
-  if (c_access_id == NULL) return false;
-  jfieldID c_mode_id = env->GetFieldID(cls, "mode", "I");
-  if (c_mode_id == NULL) return false;
-  jfieldID c_user_id = env->GetFieldID(cls, "user_id", "I");
-  if (c_user_id == NULL) return false;
-  jfieldID c_group_id = env->GetFieldID(cls, "group_id", "I");
-  if (c_group_id == NULL) return false;
-
-  //do actual lstat
-  int r = ceph_lstat(c_path, &st);
-  env->ReleaseStringUTFChars(j_path, c_path);
-
-  if (r < 0) return false; //fail out; file DNE or Ceph broke
-
-  //put variables from struct stat into Java
-  env->SetLongField(j_stat, c_size_id, (long)st.st_size);
-  env->SetBooleanField(j_stat, c_dir_id, (0 != S_ISDIR(st.st_mode)));
-  env->SetLongField(j_stat, c_block_id, (long)st.st_blksize);
-  env->SetLongField(j_stat, c_mod_id, (long long)st.st_mtime);
-  env->SetLongField(j_stat, c_access_id, (long long)st.st_atime);
-  env->SetIntField(j_stat, c_mode_id, (int)st.st_mode);
-  env->SetIntField(j_stat, c_user_id, (int)st.st_uid);
-  env->SetIntField(j_stat, c_group_id, (int)st.st_gid);
-
-  //return happy
-  return true;
-}
index 03bc5c9ced082f55c56068907d80a1fb2842b4da..955a4ec5a592d632231999c93536c7e2f2de8180 100644 (file)
@@ -174,6 +174,22 @@ JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1s
 JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1kill_1client
   (JNIEnv *, jobject);
 
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_stat
+ * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/Stat;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1stat
+  (JNIEnv *, jobject, jstring, jobject);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_statfs
+ * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/CephStat;)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1statfs
+(JNIEnv * env, jobject obj, jstring j_path, jobject j_cephstat);
+
 /*
  * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
  * Method:    ceph_replication
@@ -262,14 +278,6 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1clo
 JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1write
   (JNIEnv *, jobject, jint, jbyteArray, jint, jint);
 
-/*
- * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
- * Method:    ceph_stat
- * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/Stat;)Z
- */
-JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1stat
-  (JNIEnv *, jobject, jstring, jobject);
-
 #ifdef __cplusplus
 }
 #endif
index e8be05317cad54ad59db111b25bd7ace990320b7..2e27bf6c4ad909cb6cb1432930bbf602b71dc2a6 100644 (file)
@@ -23,7 +23,8 @@ import org.apache.hadoop.fs.permission.FsPermission;
 import org.apache.hadoop.fs.permission.FsAction;
 import org.apache.hadoop.util.Progressable;
 import org.apache.hadoop.fs.FileStatus;
-//import org.apache.hadoop.fs.CreateFlag;
+import org.apache.hadoop.fs.FsStatus;
+import org.apache.hadoop.fs.CreateFlag;
 
 /**
  * <p>
@@ -70,6 +71,7 @@ public class CephFileSystem extends FileSystem {
   private native boolean ceph_setPermission(String path, int mode);
   private native boolean ceph_kill_client();
   private native boolean ceph_stat(String path, Stat fill);
+  private native int ceph_statfs(String Path, CephStat fill);
   private native int ceph_replication(String path);
   private native String ceph_hosts(int fh, long offset);
   private native int ceph_setTimes(String path, long mtime, long atime);
@@ -390,7 +392,7 @@ public class CephFileSystem extends FileSystem {
       throw new IOException("create: Cannot overwrite existing directory \""
                            + abs_path.toString() + "\" with a file");      
     if (progress!=null) progress.progress();
-    //if (!flag.contains(CreateFlag.OVERWRITE)) {
+    //    if (!flag.contains(CreateFlag.OVERWRITE)) {
     if (!overwrite) {
       if (exists(abs_path)) {
        throw new IOException("createRaw: Cannot open existing file \"" 
@@ -499,6 +501,23 @@ public class CephFileSystem extends FileSystem {
     return locations;
   }
   
+  /*  public FsStatus getStatus (Path path) throws IOException {
+    if (!initialized) throw new IOException("You have to initialize the"
+                     + " CephFileSystem before calling other methods.");
+    debug("getStatus:enter");
+    Path abs_path = makeAbsolute(path);
+
+    //currently(Ceph .12) Ceph actually ignores the path
+    //but we still pass it in; if Ceph stops ignoring we may need more
+    //error-checking code.
+    CephStat ceph_stat = new CephStat();
+    int result = ceph_statfs(abs_path.toString(), ceph_stat);
+    if (result!=0) throw new IOException("Somehow failed to statfs the Ceph filesystem. Error code: " + result);
+    debug("getStatus:exit");
+    return new FsStatus(ceph_stat.capacity,
+                       ceph_stat.used, ceph_stat.remaining);
+                       }*/
+
   /* Added in for .20, not required in trunk */
   public boolean delete(Path path) throws IOException { return delete(path, true); };
 
@@ -692,4 +711,12 @@ public class CephFileSystem extends FileSystem {
 
     public Stat(){}
   }
+
+  private class CephStat {
+    public long capacity;
+    public long used;
+    public long remaining;
+
+    public CephStat() {}
+  }
 }
index 99beb5d6ae6e86552d5ac4b335753ec57dc8e62d..c8b75ef0a2342c863f1bd478515e5989131d2a4b 100644 (file)
@@ -177,6 +177,14 @@ JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1k
 JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1stat
   (JNIEnv *, jobject, jstring, jobject);
 
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_statfs
+ * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/CephStat;)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1statfs
+  (JNIEnv *, jobject, jstring, jobject);
+
 /*
  * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
  * Method:    ceph_replication