Kaynağa Gözat

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.18@722325 13f79535-47bb-0310-9956-ffa450edef68
Christopher Douglas 16 yıl önce
ebeveyn
işleme
cc7290d35a
2 değiştirilmiş dosya ile 16 ekleme ve 4 silme
  1. 3 0
      CHANGES.txt
  2. 13 4
      src/c++/librecordio/binarchive.cc

+ 3 - 0
CHANGES.txt

@@ -52,6 +52,9 @@ Release 0.18.3 - Unreleased
     HADOOP-4257. The DFS client should pick only one datanode as the candidate
     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
 
   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;
   ::deserializeInt(len, stream);
   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;
+    }
   }
 }