]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Hadoop: Added setTimes to CephFileSystem and CephFSInterface.
authorGreg Farnum <gregf@hq.newdream.net>
Fri, 7 Aug 2009 22:54:33 +0000 (15:54 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Fri, 7 Aug 2009 23:28:29 +0000 (16:28 -0700)
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 293972ce9dba29985b17a5ab8f9e7cdbc678581b..13ac0163e87a70a595ae4c4fa9bdd1db25168306 100644 (file)
@@ -535,6 +535,28 @@ JNIEXPORT jstring JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1ho
   return env->NewStringUTF(address.c_str());
 }
 
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_setTimes
+ * Signature: (Ljava/lang/String;JJ)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1setTimes
+(JNIEnv * env, jobject obj, jstring j_path, jlong mtime, jlong atime) {
+  const char *c_path = env->GetStringUTFChars(j_path, 0);
+  if(c_path == NULL) return -ENOMEM;
+
+  //build the mask for ceph_setattr
+  int mask = 0;
+  if (mtime!=-1) mask = CEPH_SETATTR_MTIME;
+  if (atime!=-1) mask |= CEPH_SETTATTR_ATIME;
+  //build a struct stat and fill it in!
+  struct stat attr;
+  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);
+}
+
 /*
  * Class:     org_apache_hadoop_fs_ceph_CephInputStream
  * Method:    ceph_read
index abcff972be881349be71b6de96feea0a87e2aa91..03bc5c9ced082f55c56068907d80a1fb2842b4da 100644 (file)
@@ -190,6 +190,14 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1repli
 JNIEXPORT jstring JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1hosts
   (JNIEnv *, jobject, jint, jlong);
 
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_setTimes
+ * Signature: (Ljava/lang/String;JJ)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1setTimes
+  (JNIEnv *, jobject, jstring, jlong, jlong);
+
 /*
  * Class:     org_apache_hadoop_fs_ceph_CephInputStream
  * Method:    ceph_read
index 2f3ba63ad521e976c6b529d4cf09c7f97f6f6439..c32b125c9f7c1c99cd10b46c92b89467920b2d61 100644 (file)
@@ -72,6 +72,7 @@ public class CephFileSystem extends FileSystem {
   private native boolean ceph_stat(String path, Stat 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);
 
   public CephFileSystem() {
     debug("CephFileSystem:enter");
@@ -335,6 +336,26 @@ public class CephFileSystem extends FileSystem {
     ceph_setPermission(abs_path.toString(), permission.toShort());
   }
 
+  /**
+   * Set access/modification times of a file.
+   * @param p The path
+   * @param mtime Set modification time in number of millis since Jan 1, 1970.
+   * @param atime Set access time in number of millis since Jan 1, 1970.
+   */
+@Override
+  public void setTimes(Path p, long mtime, long atime) throws IOException {
+  if (!initialized) throw new IOException ("You have to initialize the"
+                      +"CephFileSystem before calling other methods.");
+  Path abs_path = makeAbsolute(p);
+  //libhadoopcephfs respects the -1 "don't set" meanings, but we
+  //need to convert these times in millis to times in seconds here
+  if (mtime != -1) mtime /= 1000;
+  if (atime != -1) atime /= 1000;
+  int r = ceph_setTimes(abs_path.toString(), mtime, atime);
+  if (r<0) throw new IOException ("Failed to set times on path "
+                                 + abs_path.toString() + " Error code: " + r);
+}
+
   /**
    * In order to run this with Hadoop .20, I had to revert back to using
    * a boolean instead of the CreateFlag.
index 2be8bcdc76d6796669ca7ca1b4e2c913804bbda1..99beb5d6ae6e86552d5ac4b335753ec57dc8e62d 100644 (file)
@@ -17,22 +17,6 @@ extern "C" {
 JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1initializeClient
   (JNIEnv *, jobject, jstring, jstring);
 
-/*
- * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
- * Method:    ceph_copyFromLocalFile
- * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
- */
-JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1copyFromLocalFile
-  (JNIEnv *, jobject, jstring, jstring);
-
-/*
- * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
- * Method:    ceph_copyToLocalFile
- * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
- */
-JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1copyToLocalFile
-  (JNIEnv *, jobject, jstring, jstring);
-
 /*
  * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
  * Method:    ceph_getcwd
@@ -209,6 +193,14 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1repli
 JNIEXPORT jstring JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1hosts
   (JNIEnv *, jobject, jint, jlong);
 
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_setTimes
+ * Signature: (Ljava/lang/String;JJ)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1setTimes
+  (JNIEnv *, jobject, jstring, jlong, jlong);
+
 #ifdef __cplusplus
 }
 #endif