Browse Source

HADOOP-646. Fix DFS namenode to handle edits files larger than 2GB. Contributed by Milind.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@473522 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 years ago
parent
commit
e7dcde5bbd
2 changed files with 19 additions and 3 deletions
  1. 3 0
      CHANGES.txt
  2. 16 3
      src/java/org/apache/hadoop/dfs/FSEditLog.java

+ 3 - 0
CHANGES.txt

@@ -50,6 +50,9 @@ Trunk (unreleased changes)
 15. HADOOP-708.  Fix test-libhdfs to return the correct status, so
     that failures will break the build.  (Nigel Daley via cutting)
 
+16. HADOOP-646.  Fix namenode to handle edits files larger than 2GB.
+    (Milind Bhandarkar via cutting)
+
 
 Release 0.8.0 - 2006-11-03
 

+ 16 - 3
src/java/org/apache/hadoop/dfs/FSEditLog.java

@@ -20,6 +20,7 @@ package org.apache.hadoop.dfs;
 import java.io.BufferedInputStream;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
+import java.io.EOFException;
 import java.io.File;
 import java.io.FileDescriptor;
 import java.io.FileInputStream;
@@ -157,8 +158,15 @@ class FSEditLog {
               new FileInputStream(edits)));
       // Read log file version. Could be missing. 
       in.mark( 4 );
-      if( in.available() > 0 ) {
+      // If edits log is greater than 2G, available method will return negative
+      // numbers, so we avoid having to call available
+      boolean available = true;
+      try {
         logVersion = in.readByte();
+      } catch (EOFException e) {
+        available = false;
+      }
+      if (available) {
         in.reset();
         if( logVersion >= 0 )
           logVersion = 0;
@@ -174,8 +182,13 @@ class FSEditLog {
       
       short replication = (short)conf.getInt("dfs.replication", 3);
       try {
-        while (in.available() > 0) {
-          byte opcode = in.readByte();
+        while (true) {
+          byte opcode = -1;
+          try {
+            opcode = in.readByte();
+          } catch (EOFException e) {
+            break; // no more transactions
+          }
           numEdits++;
           switch (opcode) {
           case OP_ADD: {