org.apache.hadoop.fs
Class FileSystem

java.lang.Object
  extended byorg.apache.hadoop.conf.Configured
      extended byorg.apache.hadoop.fs.FileSystem
All Implemented Interfaces:
Configurable
Direct Known Subclasses:
DistributedFileSystem, LocalFileSystem

public abstract class FileSystem
extends Configured

An abstract base class for a fairly generic filesystem. It may be implemented as a distributed filesystem, or as a "local" one that reflects the locally-connected disk. The local version exists for small Hadopp instances and for testing.

All user code that may potentially use the Hadoop Distributed File System should be written to use a FileSystem object. The Hadoop DFS is a multi-machine system that appears as a single disk. It's useful because of its fault tolerance and potentially very large capacity.

The local implementation is LocalFileSystem and distributed implementation is DistributedFileSystem.

Author:
Mike Cafarella

Field Summary
static Logger LOG
           
 
Constructor Summary
protected FileSystem(Configuration conf)
           
 
Method Summary
abstract  void close()
          No more filesystem operations are needed.
abstract  void completeLocalInput(File localFile)
          Called when we're all done writing to the target.
abstract  void completeLocalOutput(File fsOutputFile, File tmpLocalFile)
          Called when we're all done writing to the target.
abstract  void copyFromLocalFile(File src, File dst)
          The src file is on the local disk.
abstract  void copyToLocalFile(File src, File dst)
          The src file is under FS2, and the dst is on the local disk.
 FSDataOutputStream create(File f)
          Opens an FSDataOutputStream at the indicated File.
 FSDataOutputStream create(File f, boolean overwrite, int bufferSize)
          Opens an FSDataOutputStream at the indicated File.
 boolean createNewFile(File f)
          Creates the given File as a brand-new zero-length file.
abstract  FSOutputStream createRaw(File f, boolean overwrite)
          Opens an OutputStream at the indicated File.
 boolean delete(File f)
          Deletes File
abstract  boolean deleteRaw(File f)
          Deletes File
abstract  boolean exists(File f)
          Check if exists
static FileSystem get(Configuration conf)
          Returns the configured filesystem implementation.
abstract  long getBlockSize()
          Return the number of bytes that large input files should be optimally be split into to minimize i/o time.
static File getChecksumFile(File file)
          Return the name of the checksum file associated with a file.
abstract  String[][] getFileCacheHints(File f, long start, long len)
          Return a 2D array of size 1x1 or greater, containing hostnames where portions of the given file can be found.
abstract  long getLength(File f)
          The number of bytes in a file.
abstract  String getName()
          Returns a name for this filesystem, suitable to pass to getNamed(String,Configuration).
static FileSystem getNamed(String name, Configuration conf)
          Returns a named filesystem.
abstract  File getWorkingDirectory()
          Get the current working directory for the given file system
abstract  boolean isAbsolute(File f)
          True iff the named path is absolute.
static boolean isChecksumFile(File file)
          Return true iff file is a checksum file name.
abstract  boolean isDirectory(File f)
          True iff the named path is a directory.
 boolean isFile(File f)
          True iff the named path is a regular file.
 File[] listFiles(File f)
          List files in a directory.
 File[] listFiles(File f, FileFilter filter)
          Filter files in a directory.
abstract  File[] listFilesRaw(File f)
          List files in a directory.
abstract  void lock(File f, boolean shared)
          Obtain a lock on the given File
abstract  void mkdirs(File f)
          Make the given file and all non-existent parents into directories.
abstract  void moveFromLocalFile(File src, File dst)
          The src file is on the local disk.
 FSDataInputStream open(File f)
          Opens an FSDataInputStream at the indicated File.
 FSDataInputStream open(File f, int bufferSize)
          Opens an FSDataInputStream at the indicated File.
abstract  FSInputStream openRaw(File f)
          Opens an InputStream for the indicated File, whether local or via DFS.
static FileSystem parseArgs(String[] argv, int i, Configuration conf)
          Deprecated. use fs.default.name config option instead
abstract  void release(File f)
          Release the lock
 boolean rename(File src, File dst)
          Renames File src to File dst.
abstract  boolean renameRaw(File src, File dst)
          Renames File src to File dst.
abstract  void reportChecksumFailure(File f, FSInputStream in, long start, long length, int crc)
          Report a checksum error to the file system.
abstract  void setWorkingDirectory(File new_dir)
          Set the current working directory for the given file system.
abstract  File startLocalInput(File fsInputFile, File tmpLocalFile)
          Returns a local File that the user can read from.
abstract  File startLocalOutput(File fsOutputFile, File tmpLocalFile)
          Returns a local File that the user can write output to.
 
Methods inherited from class org.apache.hadoop.conf.Configured
getConf, setConf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

public static final Logger LOG
Constructor Detail

FileSystem

protected FileSystem(Configuration conf)
Method Detail

parseArgs

public static FileSystem parseArgs(String[] argv,
                                   int i,
                                   Configuration conf)
                            throws IOException
Deprecated. use fs.default.name config option instead

Parse the cmd-line args, starting at i. Remove consumed args from array. We expect param in the form: '-local | -dfs '

Throws:
IOException

get

public static FileSystem get(Configuration conf)
                      throws IOException
Returns the configured filesystem implementation.

Throws:
IOException

getName

public abstract String getName()
Returns a name for this filesystem, suitable to pass to getNamed(String,Configuration).


getNamed

public static FileSystem getNamed(String name,
                                  Configuration conf)
                           throws IOException
Returns a named filesystem. Names are either the string "local" or a host:port pair, naming an DFS name server.

Throws:
IOException

getChecksumFile

public static File getChecksumFile(File file)
Return the name of the checksum file associated with a file.


isChecksumFile

public static boolean isChecksumFile(File file)
Return true iff file is a checksum file name.


getFileCacheHints

public abstract String[][] getFileCacheHints(File f,
                                             long start,
                                             long len)
                                      throws IOException
Return a 2D array of size 1x1 or greater, containing hostnames where portions of the given file can be found. For a nonexistent file or regions, null will be returned. This call is most helpful with DFS, where it returns hostnames of machines that contain the given file. The FileSystem will simply return an elt containing 'localhost'.

Throws:
IOException

open

public FSDataInputStream open(File f,
                              int bufferSize)
                       throws IOException
Opens an FSDataInputStream at the indicated File.

Parameters:
f - the file name to open
bufferSize - the size of the buffer to be used.
Throws:
IOException

open

public FSDataInputStream open(File f)
                       throws IOException
Opens an FSDataInputStream at the indicated File.

Parameters:
f - the file to open
Throws:
IOException

openRaw

public abstract FSInputStream openRaw(File f)
                               throws IOException
Opens an InputStream for the indicated File, whether local or via DFS.

Throws:
IOException

create

public FSDataOutputStream create(File f)
                          throws IOException
Opens an FSDataOutputStream at the indicated File. Files are overwritten by default.

Throws:
IOException

create

public FSDataOutputStream create(File f,
                                 boolean overwrite,
                                 int bufferSize)
                          throws IOException
Opens an FSDataOutputStream at the indicated File.

Parameters:
f - the file name to open
overwrite - if a file with this name already exists, then if true, the file will be overwritten, and if false an error will be thrown.
bufferSize - the size of the buffer to be used.
Throws:
IOException

createRaw

public abstract FSOutputStream createRaw(File f,
                                         boolean overwrite)
                                  throws IOException
Opens an OutputStream at the indicated File.

Parameters:
f - the file name to open
overwrite - if a file with this name already exists, then if true, the file will be overwritten, and if false an error will be thrown.
Throws:
IOException

createNewFile

public boolean createNewFile(File f)
                      throws IOException
Creates the given File as a brand-new zero-length file. If create fails, or if it already existed, return false.

Throws:
IOException

rename

public boolean rename(File src,
                      File dst)
               throws IOException
Renames File src to File dst. Can take place on local fs or remote DFS.

Throws:
IOException

renameRaw

public abstract boolean renameRaw(File src,
                                  File dst)
                           throws IOException
Renames File src to File dst. Can take place on local fs or remote DFS.

Throws:
IOException

delete

public boolean delete(File f)
               throws IOException
Deletes File

Throws:
IOException

deleteRaw

public abstract boolean deleteRaw(File f)
                           throws IOException
Deletes File

Throws:
IOException

exists

public abstract boolean exists(File f)
                        throws IOException
Check if exists

Throws:
IOException

isDirectory

public abstract boolean isDirectory(File f)
                             throws IOException
True iff the named path is a directory.

Throws:
IOException

isFile

public boolean isFile(File f)
               throws IOException
True iff the named path is a regular file.

Throws:
IOException

isAbsolute

public abstract boolean isAbsolute(File f)
True iff the named path is absolute.


getLength

public abstract long getLength(File f)
                        throws IOException
The number of bytes in a file.

Throws:
IOException

listFiles

public File[] listFiles(File f)
                 throws IOException
List files in a directory.

Throws:
IOException

listFilesRaw

public abstract File[] listFilesRaw(File f)
                             throws IOException
List files in a directory.

Throws:
IOException

listFiles

public File[] listFiles(File f,
                        FileFilter filter)
                 throws IOException
Filter files in a directory.

Throws:
IOException

setWorkingDirectory

public abstract void setWorkingDirectory(File new_dir)
Set the current working directory for the given file system. All relative paths will be resolved relative to it.

Parameters:
new_dir -

getWorkingDirectory

public abstract File getWorkingDirectory()
Get the current working directory for the given file system

Returns:
the directory pathname

mkdirs

public abstract void mkdirs(File f)
                     throws IOException
Make the given file and all non-existent parents into directories.

Throws:
IOException

lock

public abstract void lock(File f,
                          boolean shared)
                   throws IOException
Obtain a lock on the given File

Throws:
IOException

release

public abstract void release(File f)
                      throws IOException
Release the lock

Throws:
IOException

copyFromLocalFile

public abstract void copyFromLocalFile(File src,
                                       File dst)
                                throws IOException
The src file is on the local disk. Add it to FS at the given dst name and the source is kept intact afterwards

Throws:
IOException

moveFromLocalFile

public abstract void moveFromLocalFile(File src,
                                       File dst)
                                throws IOException
The src file is on the local disk. Add it to FS at the given dst name, removing the source afterwards.

Throws:
IOException

copyToLocalFile

public abstract void copyToLocalFile(File src,
                                     File dst)
                              throws IOException
The src file is under FS2, and the dst is on the local disk. Copy it from FS control to the local dst name.

Throws:
IOException

startLocalOutput

public abstract File startLocalOutput(File fsOutputFile,
                                      File tmpLocalFile)
                               throws IOException
Returns a local File that the user can write output to. The caller provides both the eventual FS target name and the local working file. If the FS is local, we write directly into the target. If the FS is remote, we write into the tmp local area.

Throws:
IOException

completeLocalOutput

public abstract void completeLocalOutput(File fsOutputFile,
                                         File tmpLocalFile)
                                  throws IOException
Called when we're all done writing to the target. A local FS will do nothing, because we've written to exactly the right place. A remote FS will copy the contents of tmpLocalFile to the correct target at fsOutputFile.

Throws:
IOException

startLocalInput

public abstract File startLocalInput(File fsInputFile,
                                     File tmpLocalFile)
                              throws IOException
Returns a local File that the user can read from. The caller provides both the eventual FS target name and the local working file. If the FS is local, we read directly from the source. If the FS is remote, we write data into the tmp local area.

Throws:
IOException

completeLocalInput

public abstract void completeLocalInput(File localFile)
                                 throws IOException
Called when we're all done writing to the target. A local FS will do nothing, because we've written to exactly the right place. A remote FS will copy the contents of tmpLocalFile to the correct target at fsOutputFile.

Throws:
IOException

close

public abstract void close()
                    throws IOException
No more filesystem operations are needed. Will release any held locks.

Throws:
IOException

reportChecksumFailure

public abstract void reportChecksumFailure(File f,
                                           FSInputStream in,
                                           long start,
                                           long length,
                                           int crc)
Report a checksum error to the file system.

Parameters:
f - the file name containing the error
in - the stream open on the file
start - the position of the beginning of the bad data in the file
length - the length of the bad data in the file
crc - the expected CRC32 of the data

getBlockSize

public abstract long getBlockSize()
Return the number of bytes that large input files should be optimally be split into to minimize i/o time.



Copyright © 2006 The Apache Software Foundation