diff options
author | Greg Farnum <gregf@hq.newdream.net> | 2009-08-12 16:54:47 -0700 |
---|---|---|
committer | Greg Farnum <gregf@hq.newdream.net> | 2009-08-17 12:21:13 -0700 |
commit | dbfdcc14734ea6069beb51a84b3a324393658cdd (patch) | |
tree | 760cb10ee2b463812359b925824187eb6bd91fc3 | |
parent | cfd3d87a31ae855f3156ad8461ba12bc9ea163d3 (diff) | |
download | ceph-dbfdcc14734ea6069beb51a84b3a324393658cdd.tar.gz |
Hadoop: Adds the getStatus method introduced by Hadoop .21;
currently commented out since it doesn't compile in .20, but it's tested.
-rw-r--r-- | src/client/hadoop/CephFSInterface.cc | 139 | ||||
-rw-r--r-- | src/client/hadoop/CephFSInterface.h | 24 | ||||
-rw-r--r-- | src/client/hadoop/ceph/CephFileSystem.java | 31 | ||||
-rw-r--r-- | src/client/hadoop/org_apache_hadoop_fs_ceph_CephFileSystem.h | 8 |
4 files changed, 140 insertions, 62 deletions
diff --git a/src/client/hadoop/CephFSInterface.cc b/src/client/hadoop/CephFSInterface.cc index 005edf666a5..5ca5ab77b95 100644 --- a/src/client/hadoop/CephFSInterface.cc +++ b/src/client/hadoop/CephFSInterface.cc @@ -508,6 +508,92 @@ JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1k /* * 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 * Signature: (Ljava/lang/String;)I */ @@ -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; -} diff --git a/src/client/hadoop/CephFSInterface.h b/src/client/hadoop/CephFSInterface.h index 03bc5c9ced0..955a4ec5a59 100644 --- a/src/client/hadoop/CephFSInterface.h +++ b/src/client/hadoop/CephFSInterface.h @@ -176,6 +176,22 @@ JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1k /* * 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 * Signature: (Ljava/lang/String;)I */ @@ -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 diff --git a/src/client/hadoop/ceph/CephFileSystem.java b/src/client/hadoop/ceph/CephFileSystem.java index e8be05317ca..2e27bf6c4ad 100644 --- a/src/client/hadoop/ceph/CephFileSystem.java +++ b/src/client/hadoop/ceph/CephFileSystem.java @@ -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() {} + } } diff --git a/src/client/hadoop/org_apache_hadoop_fs_ceph_CephFileSystem.h b/src/client/hadoop/org_apache_hadoop_fs_ceph_CephFileSystem.h index 99beb5d6ae6..c8b75ef0a23 100644 --- a/src/client/hadoop/org_apache_hadoop_fs_ceph_CephFileSystem.h +++ b/src/client/hadoop/org_apache_hadoop_fs_ceph_CephFileSystem.h @@ -179,6 +179,14 @@ JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1s /* * 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 * Signature: (Ljava/lang/String;)I */ |