toddlipcon commented on a change in pull request #597: HDFS-3246: pRead
equivalent for direct read path
URL: https://github.com/apache/hadoop/pull/597#discussion_r273629967
##########
File path:
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c
##########
@@ -1571,6 +1651,51 @@ tSize hdfsPread(hdfsFS fs, hdfsFile f, tOffset position,
return jVal.i;
}
+tSize preadDirect(hdfsFS fs, hdfsFile f, tOffset position, void* buffer,
+ tSize length)
+{
+ // JAVA EQUIVALENT:
+ // ByteBuffer buf = ByteBuffer.allocateDirect(length) // wraps C buffer
+ // fis.read(position, buf);
+
+ jvalue jVal;
+ jthrowable jthr;
+ jobject bb;
+
+ //Get the JNIEnv* corresponding to current thread
+ JNIEnv* env = getJNIEnv();
+ if (env == NULL) {
+ errno = EINTERNAL;
+ return -1;
+ }
+
+ //Error checking... make sure that this file is 'readable'
+ if (f->type != HDFS_STREAM_INPUT) {
+ fprintf(stderr, "Cannot read from a non-InputStream object!\n");
+ errno = EINVAL;
+ return -1;
+ }
+
+ //Read the requisite bytes
+ bb = (*env)->NewDirectByteBuffer(env, buffer, length);
+ if (bb == NULL) {
+ errno = printPendingExceptionAndFree(env, PRINT_EXC_ALL,
+ "readDirect: NewDirectByteBuffer");
+ return -1;
+ }
+
+ jthr = invokeMethod(env, &jVal, INSTANCE, f->file,
+ JC_FS_DATA_INPUT_STREAM, "read", "(JLjava/nio/ByteBuffer;)I",
+ position, bb);
+ destroyLocalReference(env, bb);
+ if (jthr) {
+ errno = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
+ "preadDirect: FSDataInputStream#read");
+ return -1;
+ }
+ return (jVal.i < 0) ? 0 : jVal.i;
Review comment:
it seems the javadoc says that the method can return 0 for a transient
zero-length result, and -1 for EOF. But here we're converting -1 to 0, so the
caller can't distinguish between a must-retry '0 length read' and a 'shouldn't
retry' EOF, right?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]