Преглед на файлове

HDFS-470. libhdfs should handle 0-length reads from FSInputStream correctly. Contributed by Colin Patrick McCabe

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1361447 13f79535-47bb-0310-9956-ffa450edef68
Eli Collins преди 13 години
родител
ревизия
bb00c0ce20

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -324,6 +324,9 @@ Release 2.0.1-alpha - UNRELEASED
     HDFS-3639. JspHelper#getUGI should always verify the token if
     security is enabled. (eli)
 
+    HDFS-470. libhdfs should handle 0-length reads from FSInputStream
+    correctly. (Colin Patrick McCabe via eli)
+
   BREAKDOWN OF HDFS-3042 SUBTASKS
 
     HDFS-2185. HDFS portion of ZK-based FailoverController (todd)

+ 6 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/native/hdfs.c

@@ -878,11 +878,15 @@ static int handleReadResult(int success, jvalue jVal, jthrowable jExc,
     noReadBytes = -1;
   } else {
     noReadBytes = jVal.i;
-    if (noReadBytes < 0) {
+    if (noReadBytes == 0) {
+      // 0 from Java means try again, which is EINTR here
+      errno = EINTR;
+      noReadBytes = -1;
+    } else if (noReadBytes < 0) {
       // -1 from Java is EOF, which is 0 here
+      errno = 0;
       noReadBytes = 0;
     }
-    errno = 0;
   }
 
   return noReadBytes;

+ 7 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/native/hdfs.h

@@ -311,8 +311,13 @@ extern  "C" {
      * @param file The file handle.
      * @param buffer The buffer to copy read bytes into.
      * @param length The length of the buffer.
-     * @return Returns the number of bytes actually read, possibly less
-     * than than length;-1 on error.
+     * @return      On success, a positive number indicating how many bytes
+     *              were read.
+     *              On end-of-file, 0.
+     *              On error, -1.  Errno will be set to the error code.
+     *              Just like the POSIX read function, hdfsRead will return -1
+     *              and set errno to EINTR if data is temporarily unavailable,
+     *              but we are not yet at the end of the file.
      */
     tSize hdfsRead(hdfsFS fs, hdfsFile file, void* buffer, tSize length);