Browse Source

Merge -r 595130:595131 from trunk to 0.15 branch. Fixes: HADOOP-2172.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/branches/branch-0.15@595135 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 17 years ago
parent
commit
5602fef71c
2 changed files with 25 additions and 4 deletions
  1. 5 0
      CHANGES.txt
  2. 20 4
      src/java/org/apache/hadoop/fs/RawLocalFileSystem.java

+ 5 - 0
CHANGES.txt

@@ -20,6 +20,11 @@ Release 0.15.1 -
     FSCopyFilesMapper.close which led to a NPE since the reporter isn't valid
     FSCopyFilesMapper.close which led to a NPE since the reporter isn't valid
     in the close method. (Chris Douglas via acmurthy) 
     in the close method. (Chris Douglas via acmurthy) 
 
 
+    HADOOP-2172.  Restore performance of random access to local files
+    by caching positions of local input streams, avoiding a system
+    call. (cutting)
+
+
 Release 0.15.0 - 2007-11-2
 Release 0.15.0 - 2007-11-2
 
 
   INCOMPATIBLE CHANGES
   INCOMPATIBLE CHANGES

+ 20 - 4
src/java/org/apache/hadoop/fs/RawLocalFileSystem.java

@@ -68,6 +68,7 @@ public class RawLocalFileSystem extends FileSystem {
    *******************************************************/
    *******************************************************/
   class LocalFSFileInputStream extends FSInputStream {
   class LocalFSFileInputStream extends FSInputStream {
     FileInputStream fis;
     FileInputStream fis;
+    private long position;
 
 
     public LocalFSFileInputStream(Path f) throws IOException {
     public LocalFSFileInputStream(Path f) throws IOException {
       this.fis = new FileInputStream(pathToFile(f));
       this.fis = new FileInputStream(pathToFile(f));
@@ -75,10 +76,11 @@ public class RawLocalFileSystem extends FileSystem {
     
     
     public void seek(long pos) throws IOException {
     public void seek(long pos) throws IOException {
       fis.getChannel().position(pos);
       fis.getChannel().position(pos);
+      this.position = pos;
     }
     }
     
     
     public long getPos() throws IOException {
     public long getPos() throws IOException {
-      return fis.getChannel().position();
+      return this.position;
     }
     }
     
     
     public boolean seekToNewSource(long targetPos) throws IOException {
     public boolean seekToNewSource(long targetPos) throws IOException {
@@ -94,7 +96,11 @@ public class RawLocalFileSystem extends FileSystem {
     
     
     public int read() throws IOException {
     public int read() throws IOException {
       try {
       try {
-        return fis.read();
+        int value = fis.read();
+        if (value >= 0) {
+          this.position++;
+        }
+        return value;
       } catch (IOException e) {                 // unexpected exception
       } catch (IOException e) {                 // unexpected exception
         throw new FSError(e);                   // assume native fs error
         throw new FSError(e);                   // assume native fs error
       }
       }
@@ -102,7 +108,11 @@ public class RawLocalFileSystem extends FileSystem {
     
     
     public int read(byte[] b, int off, int len) throws IOException {
     public int read(byte[] b, int off, int len) throws IOException {
       try {
       try {
-        return fis.read(b, off, len);
+        int value = fis.read(b, off, len);
+        if (value > 0) {
+          this.position += value;
+        }
+        return value;
       } catch (IOException e) {                 // unexpected exception
       } catch (IOException e) {                 // unexpected exception
         throw new FSError(e);                   // assume native fs error
         throw new FSError(e);                   // assume native fs error
       }
       }
@@ -118,7 +128,13 @@ public class RawLocalFileSystem extends FileSystem {
       }
       }
     }
     }
     
     
-    public long skip(long n) throws IOException { return fis.skip(n); }
+    public long skip(long n) throws IOException {
+      long value = fis.skip(n);
+      if (value > 0) {
+        this.position += value;
+      }
+      return value;
+    }
   }
   }
   
   
   public FSDataInputStream open(Path f, int bufferSize) throws IOException {
   public FSDataInputStream open(Path f, int bufferSize) throws IOException {