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
This commit is contained in:
Eli Collins 2011-06-16 20:14:54 +00:00
parent 01a407d9df
commit 9185f8b003
4 changed files with 50 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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