diff --git a/hadoop-0.20.2-cdh3u0/src/c++/libhdfs/hdfs.c b/hadoop-0.20.2-cdh3u0/src/c++/libhdfs/hdfs.c index 53f94bb..5731a1e 100644 --- a/hadoop-0.20.2-cdh3u0/src/c++/libhdfs/hdfs.c +++ b/hadoop-0.20.2-cdh3u0/src/c++/libhdfs/hdfs.c @@ -1006,6 +1006,38 @@ int hdfsFlush(hdfsFS fs, hdfsFile f) +int hdfsSync(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, "sync", "()V") != 0) { + errno = errnoFromException(jExc, env, HADOOP_OSTRM "::sync"); + return -1; + } + + return 0; +} + + + int hdfsAvailable(hdfsFS fs, hdfsFile f) { // JAVA EQUIVALENT diff --git a/hadoop-0.20.2-cdh3u0/src/c++/libhdfs/hdfs.h b/hadoop-0.20.2-cdh3u0/src/c++/libhdfs/hdfs.h index 6a01084..b27a744 100644 --- a/hadoop-0.20.2-cdh3u0/src/c++/libhdfs/hdfs.h +++ b/hadoop-0.20.2-cdh3u0/src/c++/libhdfs/hdfs.h @@ -240,6 +240,15 @@ extern "C" { /** + * hdfsSync - Synchronize all buffer with the underlying devices. + * @param fs The configured filesystem handle. + * @param file The file handle. + * @return Returns 0 on success, -1 on error. + */ + int hdfsSync(hdfsFS fs, hdfsFile file); + + + /** * hdfsAvailable - Number of bytes that can be read from this * input stream without blocking. * @param fs The configured filesystem handle.