You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by el...@apache.org on 2011/06/16 22:14:54 UTC

svn commit: r1136646 - in /hadoop/common/trunk/hdfs: CHANGES.txt src/c++/libhdfs/hdfs.c src/c++/libhdfs/hdfs.h src/c++/libhdfs/hdfs_test.c

Author: eli
Date: Thu Jun 16 20:14:54 2011
New Revision: 1136646

URL: http://svn.apache.org/viewvc?rev=1136646&view=rev
Log:
HDFS-2055. Add hflush support to libhdfs. Contributed by Travis Crawford

Modified:
    hadoop/common/trunk/hdfs/CHANGES.txt
    hadoop/common/trunk/hdfs/src/c++/libhdfs/hdfs.c
    hadoop/common/trunk/hdfs/src/c++/libhdfs/hdfs.h
    hadoop/common/trunk/hdfs/src/c++/libhdfs/hdfs_test.c

Modified: hadoop/common/trunk/hdfs/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hdfs/CHANGES.txt?rev=1136646&r1=1136645&r2=1136646&view=diff
==============================================================================
--- hadoop/common/trunk/hdfs/CHANGES.txt (original)
+++ hadoop/common/trunk/hdfs/CHANGES.txt Thu Jun 16 20:14:54 2011
@@ -290,6 +290,8 @@ Trunk (unreleased changes)
     HDFS-2058. Change Data Transfer wire protocol to use protocol buffers.
     (todd)
 
+    HDFS-2055. Add hflush support to libhdfs. (Travis Crawford via eli)
+
   IMPROVEMENTS
 
     HDFS-1875. MiniDFSCluster hard-codes dfs.datanode.address to localhost

Modified: hadoop/common/trunk/hdfs/src/c++/libhdfs/hdfs.c
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hdfs/src/c%2B%2B/libhdfs/hdfs.c?rev=1136646&r1=1136645&r2=1136646&view=diff
==============================================================================
--- hadoop/common/trunk/hdfs/src/c++/libhdfs/hdfs.c (original)
+++ hadoop/common/trunk/hdfs/src/c++/libhdfs/hdfs.c Thu Jun 16 20:14:54 2011
@@ -1006,6 +1006,38 @@ int hdfsFlush(hdfsFS fs, hdfsFile f) 
 
 
 
+int hdfsHFlush(hdfsFS fs, hdfsFile f)
+{
+    //Get the JNIEnv* corresponding to current thread
+    JNIEnv* env = getJNIEnv();
+    if (env == NULL) {
+      errno = EINTERNAL;
+      return -1;
+    }
+
+    //Parameters
+    jobject jOutputStream = (jobject)(f ? f->file : 0);
+
+    //Caught exception
+    jthrowable jExc = NULL;
+
+    //Sanity check
+    if (!f || f->type != OUTPUT) {
+        errno = EBADF;
+        return -1;
+    }
+
+    if (invokeMethod(env, NULL, &jExc, INSTANCE, jOutputStream,
+                     HADOOP_OSTRM, "hflush", "()V") != 0) {
+        errno = errnoFromException(jExc, env, HADOOP_OSTRM "::hflush");
+        return -1;
+    }
+
+    return 0;
+}
+
+
+
 int hdfsAvailable(hdfsFS fs, hdfsFile f)
 {
     // JAVA EQUIVALENT

Modified: hadoop/common/trunk/hdfs/src/c++/libhdfs/hdfs.h
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hdfs/src/c%2B%2B/libhdfs/hdfs.h?rev=1136646&r1=1136645&r2=1136646&view=diff
==============================================================================
--- hadoop/common/trunk/hdfs/src/c++/libhdfs/hdfs.h (original)
+++ hadoop/common/trunk/hdfs/src/c++/libhdfs/hdfs.h Thu Jun 16 20:14:54 2011
@@ -240,6 +240,16 @@ extern  "C" {
 
 
     /**
+     * hdfsHFlush - Flush out the data in client's user buffer. After the
+     * return of this call, new readers will see the data.
+     * @param fs configured filesystem handle
+     * @param file file handle
+     * @return 0 on success, -1 on error and sets errno
+     */
+    int hdfsHFlush(hdfsFS fs, hdfsFile file);
+
+
+    /**
      * hdfsAvailable - Number of bytes that can be read from this
      * input stream without blocking.
      * @param fs The configured filesystem handle.

Modified: hadoop/common/trunk/hdfs/src/c++/libhdfs/hdfs_test.c
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hdfs/src/c%2B%2B/libhdfs/hdfs_test.c?rev=1136646&r1=1136645&r2=1136646&view=diff
==============================================================================
--- hadoop/common/trunk/hdfs/src/c++/libhdfs/hdfs_test.c (original)
+++ hadoop/common/trunk/hdfs/src/c++/libhdfs/hdfs_test.c Thu Jun 16 20:14:54 2011
@@ -95,6 +95,12 @@ int main(int argc, char **argv) {
         }
         fprintf(stderr, "Flushed %s successfully!\n", writePath); 
 
+        if (hdfsHFlush(fs, writeFile)) {
+            fprintf(stderr, "Failed to 'hflush' %s\n", writePath);
+            exit(-1);
+        }
+        fprintf(stderr, "HFlushed %s successfully!\n", writePath);
+
         hdfsCloseFile(fs, writeFile);
     }