浏览代码

HADOOP-4713. Fix librecordio to handle records larger than 64k. Contributed by Christian Kunz.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.19@722324 13f79535-47bb-0310-9956-ffa450edef68
Christopher Douglas 16 年之前
父节点
当前提交
a01243b5f0
共有 2 个文件被更改,包括 16 次插入4 次删除
  1. 3 0
      CHANGES.txt
  2. 13 4
      src/c++/librecordio/binarchive.cc

+ 3 - 0
CHANGES.txt

@@ -1037,6 +1037,9 @@ Release 0.18.3 - Unreleased
     HADOOP-4257. The DFS client should pick only one datanode as the candidate
     HADOOP-4257. The DFS client should pick only one datanode as the candidate
     to initiate lease recovery.  (Tsz Wo (Nicholas), SZE via dhruba)
     to initiate lease recovery.  (Tsz Wo (Nicholas), SZE via dhruba)
 
 
+    HADOOP-4713. Fix librecordio to handle records larger than 64k. (Christian
+    Kunz via cdouglas)
+
 Release 0.18.2 - 2008-11-03
 Release 0.18.2 - 2008-11-03
 
 
   BUG FIXES
   BUG FIXES

+ 13 - 4
src/c++/librecordio/binarchive.cc

@@ -161,10 +161,19 @@ static void deserializeString(std::string& t, InStream& stream)
   int32_t len = 0;
   int32_t len = 0;
   ::deserializeInt(len, stream);
   ::deserializeInt(len, stream);
   if (len > 0) {
   if (len > 0) {
-    char buf[len];
-    stream.read((void*) buf, len);
-    std::string s(buf, len);
-    t = s;
+    // resize the string to the right length
+    t.resize(len);
+    // read into the string in 64k chunks
+    const int bufSize = 65536;
+    int offset = 0;
+    char buf[bufSize];
+    while (len > 0) {
+      int chunkLength = len > bufSize ? bufSize : len;
+      stream.read((void *)buf, chunkLength);
+      t.replace(offset, chunkLength, buf, chunkLength);
+      offset += chunkLength;
+      len -= chunkLength;
+    }
   }
   }
 }
 }