hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1373241 - in /hadoop/common/branches/branch-1: ./ src/core/org/apache/hadoop/fs/ src/test/org/apache/hadoop/fs/
Date Wed, 15 Aug 2012 07:25:09 GMT
Author: tucu
Date: Wed Aug 15 07:25:09 2012
New Revision: 1373241

URL: http://svn.apache.org/viewvc?rev=1373241&view=rev
Log:
HADOOP-7754. Expose file descriptors from Hadoop-wrapped local FileSystems (todd and ahmed
via tucu)

Added:
    hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/HasFileDescriptor.java
Modified:
    hadoop/common/branches/branch-1/CHANGES.txt
    hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/BufferedFSInputStream.java
    hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/FSDataInputStream.java
    hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java
    hadoop/common/branches/branch-1/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java

Modified: hadoop/common/branches/branch-1/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/CHANGES.txt?rev=1373241&r1=1373240&r2=1373241&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/CHANGES.txt (original)
+++ hadoop/common/branches/branch-1/CHANGES.txt Wed Aug 15 07:25:09 2012
@@ -30,6 +30,9 @@ Release 1.2.0 - unreleased
     MAPREDUCE-4488. Port MAPREDUCE-463 (The job setup and cleanup tasks
     should be optional) to branch-1. (tomwhite)
 
+    HADOOP-7754. Expose file descriptors from Hadoop-wrapped local 
+    FileSystems (todd and ahmed via tucu)
+
   IMPROVEMENTS
 
     HDFS-3515. Port HDFS-1457 to branch-1. (eli)

Modified: hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/BufferedFSInputStream.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/BufferedFSInputStream.java?rev=1373241&r1=1373240&r2=1373241&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/BufferedFSInputStream.java
(original)
+++ hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/BufferedFSInputStream.java
Wed Aug 15 07:25:09 2012
@@ -18,6 +18,8 @@
 package org.apache.hadoop.fs;
 
 import java.io.BufferedInputStream;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
 import java.io.IOException;
 
 
@@ -27,7 +29,7 @@ import java.io.IOException;
 
 
 public class BufferedFSInputStream extends BufferedInputStream
-implements Seekable, PositionedReadable {
+implements Seekable, PositionedReadable, HasFileDescriptor {
   /**
    * Creates a <code>BufferedFSInputStream</code>
    * with the specified buffer size,
@@ -93,4 +95,13 @@ implements Seekable, PositionedReadable 
   public void readFully(long position, byte[] buffer) throws IOException {
     ((FSInputStream)in).readFully(position, buffer);
   }
+
+  @Override
+  public FileDescriptor getFileDescriptor() throws IOException {
+    if (in instanceof HasFileDescriptor) {
+      return ((HasFileDescriptor) in).getFileDescriptor();
+    } else {
+      return null;
+    }
+  }
 }

Modified: hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/FSDataInputStream.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/FSDataInputStream.java?rev=1373241&r1=1373240&r2=1373241&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/FSDataInputStream.java (original)
+++ hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/FSDataInputStream.java Wed
Aug 15 07:25:09 2012
@@ -22,7 +22,7 @@ import java.io.*;
 /** Utility that wraps a {@link FSInputStream} in a {@link DataInputStream}
  * and buffers input through a {@link BufferedInputStream}. */
 public class FSDataInputStream extends DataInputStream
-    implements Seekable, PositionedReadable, Closeable {
+    implements Seekable, PositionedReadable, Closeable, HasFileDescriptor {
 
   public FSDataInputStream(InputStream in)
     throws IOException {
@@ -59,4 +59,15 @@ public class FSDataInputStream extends D
   public boolean seekToNewSource(long targetPos) throws IOException {
     return ((Seekable)in).seekToNewSource(targetPos); 
   }
+
+  @Override
+  public FileDescriptor getFileDescriptor() throws IOException {
+    if (in instanceof HasFileDescriptor) {
+      return ((HasFileDescriptor) in).getFileDescriptor();
+    } else if (in instanceof FileInputStream) {
+      return ((FileInputStream) in).getFD();
+    } else {
+      return null;
+    }
+  }
 }

Added: hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/HasFileDescriptor.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/HasFileDescriptor.java?rev=1373241&view=auto
==============================================================================
--- hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/HasFileDescriptor.java (added)
+++ hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/HasFileDescriptor.java Wed
Aug 15 07:25:09 2012
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * Having a FileDescriptor
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Evolving
+public interface HasFileDescriptor {
+
+  /**
+   * @return the FileDescriptor
+   * @throws IOException
+   */
+  public FileDescriptor getFileDescriptor() throws IOException;
+
+}

Modified: hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java?rev=1373241&r1=1373240&r2=1373241&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java
(original)
+++ hadoop/common/branches/branch-1/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java
Wed Aug 15 07:25:09 2012
@@ -99,7 +99,7 @@ public class RawLocalFileSystem extends 
   /*******************************************************
    * For open()'s FSInputStream
    *******************************************************/
-  class LocalFSFileInputStream extends FSInputStream {
+  class LocalFSFileInputStream extends FSInputStream implements HasFileDescriptor {
     FileInputStream fis;
     private long position;
 
@@ -168,6 +168,11 @@ public class RawLocalFileSystem extends 
       }
       return value;
     }
+
+    @Override
+    public FileDescriptor getFileDescriptor() throws IOException {
+      return fis.getFD();
+    }
   }
   
   public FSDataInputStream open(Path f, int bufferSize) throws IOException {

Modified: hadoop/common/branches/branch-1/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java?rev=1373241&r1=1373240&r2=1373241&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java
(original)
+++ hadoop/common/branches/branch-1/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java
Wed Aug 15 07:25:09 2012
@@ -160,4 +160,14 @@ public class TestLocalFileSystem extends
     FileSystem fs = FileSystem.getLocal(conf);
     assertNull(fs.getCanonicalServiceName());
   }
+
+  public void testHasFileDescriptor() throws IOException {
+    Configuration conf = new Configuration();
+    LocalFileSystem fs = FileSystem.getLocal(conf);
+    Path path = new Path(TEST_ROOT_DIR, "test-file");
+    writeFile(fs, path);
+    BufferedFSInputStream bis = new BufferedFSInputStream(
+        new RawLocalFileSystem().new LocalFSFileInputStream(path), 1024);
+    assertNotNull(bis.getFileDescriptor());
+  }
 }



Mime
View raw message