瀏覽代碼

HADOOP-3569 Merge -r 669638:669639 from trunk to branch 0.18.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.18@669641 13f79535-47bb-0310-9956-ffa450edef68
Owen O'Malley 17 年之前
父節點
當前提交
9b1965327a

+ 3 - 0
CHANGES.txt

@@ -645,6 +645,9 @@ Release 0.18.0 - Unreleased
     HADOOP-3320. Fix NullPointerException in NetworkTopology.getDistance().
     HADOOP-3320. Fix NullPointerException in NetworkTopology.getDistance().
     (hairong)
     (hairong)
 
 
+    HADOOP-3569. KFS input stream read() now correctly reads 1 byte
+    instead of 4. (Sriram Rao via omalley)
+
 Release 0.17.1 - Unreleased
 Release 0.17.1 - Unreleased
 
 
   INCOMPATIBLE CHANGES
   INCOMPATIBLE CHANGES

+ 4 - 4
src/core/org/apache/hadoop/fs/kfs/KFSInputStream.java

@@ -79,13 +79,13 @@ class KFSInputStream extends FSInputStream {
         if (kfsChannel == null) {
         if (kfsChannel == null) {
             throw new IOException("File closed");
             throw new IOException("File closed");
         }
         }
-        byte b[] = new byte[4];
-        int res = read(b, 0, 4);
-        if (res == 4) {
+        byte b[] = new byte[1];
+        int res = read(b, 0, 1);
+        if (res == 1) {
           if (statistics != null) {
           if (statistics != null) {
             statistics.incrementBytesRead(1);
             statistics.incrementBytesRead(1);
           }
           }
-          return (b[0] + (b[1] << 8) + (b[2] << 16) + (b[3] << 24));          
+          return ((int) (b[0] & 0xff));
         }
         }
         return -1;
         return -1;
     }
     }

+ 10 - 1
src/test/org/apache/hadoop/fs/kfs/TestKosmosFileSystem.java

@@ -134,7 +134,10 @@ public class TestKosmosFileSystem extends TestCase {
         for (int i = 0; i < data.length; i++)
         for (int i = 0; i < data.length; i++)
             data[i] = (byte) (i % 16);
             data[i] = (byte) (i % 16);
 
 
-        // write an integer
+        // write 4 bytes and read them back; read API should return a byte per call
+        s1.write(32);
+        s1.write(32);
+        s1.write(32);
         s1.write(32);
         s1.write(32);
         // write some data
         // write some data
         s1.write(data, 0, data.length);
         s1.write(data, 0, data.length);
@@ -145,6 +148,12 @@ public class TestKosmosFileSystem extends TestCase {
         FSDataInputStream s2 = kosmosFileSystem.open(file1, 4096);
         FSDataInputStream s2 = kosmosFileSystem.open(file1, 4096);
         int v;
         int v;
 
 
+        v = s2.read();
+        assertEquals(v, 32);
+        v = s2.read();
+        assertEquals(v, 32);
+        v = s2.read();
+        assertEquals(v, 32);
         v = s2.read();
         v = s2.read();
         assertEquals(v, 32);
         assertEquals(v, 32);