瀏覽代碼

HDFS-2055. Add hflush support to libhdfs. Contributed by Travis Crawford

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1136646 13f79535-47bb-0310-9956-ffa450edef68
Eli Collins 14 年之前
父節點
當前提交
9185f8b003
共有 4 個文件被更改,包括 50 次插入0 次删除
  1. 2 0
      hdfs/CHANGES.txt
  2. 32 0
      hdfs/src/c++/libhdfs/hdfs.c
  3. 10 0
      hdfs/src/c++/libhdfs/hdfs.h
  4. 6 0
      hdfs/src/c++/libhdfs/hdfs_test.c

+ 2 - 0
hdfs/CHANGES.txt

@@ -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

+ 32 - 0
hdfs/src/c++/libhdfs/hdfs.c

@@ -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

+ 10 - 0
hdfs/src/c++/libhdfs/hdfs.h

@@ -239,6 +239,16 @@ extern  "C" {
     int hdfsFlush(hdfsFS fs, hdfsFile file);
 
 
+    /**
+     * 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.

+ 6 - 0
hdfs/src/c++/libhdfs/hdfs_test.c

@@ -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);
     }