org.apache.hadoop.dfs
Class DistributedFileSystem

java.lang.Object
  extended by org.apache.hadoop.conf.Configured
      extended by org.apache.hadoop.fs.FileSystem
          extended by org.apache.hadoop.dfs.DistributedFileSystem
All Implemented Interfaces:
Closeable, Configurable

public class DistributedFileSystem
extends FileSystem

Implementation of the abstract FileSystem for the DFS system. This object is the way end-user code interacts with a Hadoop DistributedFileSystem.


Nested Class Summary
static class DistributedFileSystem.DiskStatus
           
 
Nested classes/interfaces inherited from class org.apache.hadoop.fs.FileSystem
FileSystem.Statistics
 
Field Summary
 
Fields inherited from class org.apache.hadoop.fs.FileSystem
LOG, statistics
 
Constructor Summary
DistributedFileSystem()
           
DistributedFileSystem(InetSocketAddress namenode, Configuration conf)
          Deprecated.  
 
Method Summary
 FSDataOutputStream append(Path f, int bufferSize, Progressable progress)
          This optional operation is not yet supported.
protected  void checkPath(Path path)
          Permit paths which explicitly specify the default port.
 void close()
          No more filesystem operations are needed.
 FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress)
          Opens an FSDataOutputStream at the indicated Path with write-progress reporting.
 boolean delete(Path f)
          Deprecated. 
 boolean delete(Path f, boolean recursive)
          requires a boolean check to delete a non empty directory recursively.
 UpgradeStatusReport distributedUpgradeProgress(FSConstants.UpgradeAction action)
           
 void finalizeUpgrade()
          Finalize previously upgraded files system state.
 ContentSummary getContentSummary(Path f)
          Return the ContentSummary of a given Path.
 DatanodeInfo[] getDataNodeStats()
          Return statistics for each datanode.
 long getDefaultBlockSize()
          Return the number of bytes that large input files should be optimally be split into to minimize i/o time.
 short getDefaultReplication()
          Get the default replication.
 DistributedFileSystem.DiskStatus getDiskStatus()
          Return the disk usage of the filesystem, including total capacity, used space, and remaining space
 BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len)
          Return an array containing hostnames, offset and size of portions of the given file.
 FileStatus getFileStatus(Path f)
          Returns the stat information about the file.
 Path getHomeDirectory()
          Return the current user's home directory in this filesystem.
 String getName()
          Deprecated.  
 long getRawCapacity()
          Return the total raw capacity of the filesystem, disregarding replication .
 long getRawUsed()
          Return the total raw used space in the filesystem, disregarding replication .
 URI getUri()
          Returns a URI whose scheme and authority identify this FileSystem.
 Path getWorkingDirectory()
          Get the current working directory for the given file system
 void initialize(URI uri, Configuration conf)
          Called after a new FileSystem instance is constructed.
 FileStatus[] listStatus(Path p)
          List the statuses of the files/directories in the given path if the path is a directory.
 void metaSave(String pathname)
           
 boolean mkdirs(Path f, FsPermission permission)
          Make the given file and all non-existent parents into directories.
 FSDataInputStream open(Path f, int bufferSize)
          Opens an FSDataInputStream at the indicated Path.
 void refreshNodes()
           
 boolean rename(Path src, Path dst)
          Rename files/dirs
 boolean reportChecksumFailure(Path f, FSDataInputStream in, long inPos, FSDataInputStream sums, long sumsPos)
          We need to find the blocks that didn't match.
 void setOwner(Path p, String username, String groupname)
          Set owner of a path (i.e.
 void setPermission(Path p, FsPermission permission)
          Set permission of a path.
 boolean setReplication(Path src, short replication)
          Set replication for an existing file.
 boolean setSafeMode(FSConstants.SafeModeAction action)
          Enter, leave or get safe mode.
 void setVerifyChecksum(boolean verifyChecksum)
           
 void setWorkingDirectory(Path dir)
          Set the current working directory for the given file system.
 String toString()
           
 
Methods inherited from class org.apache.hadoop.fs.FileSystem
append, append, closeAll, completeLocalOutput, copyFromLocalFile, copyFromLocalFile, copyFromLocalFile, copyFromLocalFile, copyToLocalFile, copyToLocalFile, create, create, create, create, create, create, create, create, create, create, createNewFile, deleteOnExit, exists, get, get, getBlockSize, getDefaultUri, getFileBlockLocations, getLength, getLocal, getNamed, getReplication, getStatistics, getUsed, globStatus, globStatus, isDirectory, isFile, listStatus, listStatus, listStatus, makeQualified, mkdirs, mkdirs, moveFromLocalFile, moveFromLocalFile, moveToLocalFile, open, parseArgs, printStatistics, processDeleteOnExit, setDefaultUri, setDefaultUri, startLocalOutput
 
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, wait, wait, wait
 

Constructor Detail

DistributedFileSystem

public DistributedFileSystem()

DistributedFileSystem

public DistributedFileSystem(InetSocketAddress namenode,
                             Configuration conf)
                      throws IOException
Deprecated. 

Throws:
IOException
Method Detail

getName

public String getName()
Deprecated. 

Overrides:
getName in class FileSystem

getUri

public URI getUri()
Description copied from class: FileSystem
Returns a URI whose scheme and authority identify this FileSystem.

Specified by:
getUri in class FileSystem

initialize

public void initialize(URI uri,
                       Configuration conf)
                throws IOException
Description copied from class: FileSystem
Called after a new FileSystem instance is constructed.

Specified by:
initialize in class FileSystem
Parameters:
uri - a uri whose authority section names the host, port, etc. for this FileSystem
conf - the configuration
Throws:
IOException

checkPath

protected void checkPath(Path path)
Permit paths which explicitly specify the default port.

Overrides:
checkPath in class FileSystem

getWorkingDirectory

public Path getWorkingDirectory()
Description copied from class: FileSystem
Get the current working directory for the given file system

Specified by:
getWorkingDirectory in class FileSystem
Returns:
the directory pathname

getDefaultBlockSize

public long getDefaultBlockSize()
Description copied from class: FileSystem
Return the number of bytes that large input files should be optimally be split into to minimize i/o time.

Overrides:
getDefaultBlockSize in class FileSystem

getDefaultReplication

public short getDefaultReplication()
Description copied from class: FileSystem
Get the default replication.

Overrides:
getDefaultReplication in class FileSystem

setWorkingDirectory

public void setWorkingDirectory(Path dir)
Description copied from class: FileSystem
Set the current working directory for the given file system. All relative paths will be resolved relative to it.

Specified by:
setWorkingDirectory in class FileSystem

getHomeDirectory

public Path getHomeDirectory()
Return the current user's home directory in this filesystem. The default implementation returns "/user/$USER/".

Overrides:
getHomeDirectory in class FileSystem

getFileBlockLocations

public BlockLocation[] getFileBlockLocations(FileStatus file,
                                             long start,
                                             long len)
                                      throws IOException
Description copied from class: FileSystem
Return an array containing hostnames, offset and size of portions of the given file. 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'.

Overrides:
getFileBlockLocations in class FileSystem
Throws:
IOException

setVerifyChecksum

public void setVerifyChecksum(boolean verifyChecksum)

open

public FSDataInputStream open(Path f,
                              int bufferSize)
                       throws IOException
Description copied from class: FileSystem
Opens an FSDataInputStream at the indicated Path.

Specified by:
open in class FileSystem
Parameters:
f - the file name to open
bufferSize - the size of the buffer to be used.
Throws:
IOException

append

public FSDataOutputStream append(Path f,
                                 int bufferSize,
                                 Progressable progress)
                          throws IOException
This optional operation is not yet supported.

Specified by:
append in class FileSystem
Parameters:
f - the existing file to be appended.
bufferSize - the size of the buffer to be used.
progress - for reporting progress if it is not null.
Throws:
IOException

create

public FSDataOutputStream create(Path f,
                                 FsPermission permission,
                                 boolean overwrite,
                                 int bufferSize,
                                 short replication,
                                 long blockSize,
                                 Progressable progress)
                          throws IOException
Description copied from class: FileSystem
Opens an FSDataOutputStream at the indicated Path with write-progress reporting.

Specified by:
create in class FileSystem
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.
replication - required block replication for the file.
Throws:
IOException
See Also:
FileSystem.setPermission(Path, FsPermission)

setReplication

public boolean setReplication(Path src,
                              short replication)
                       throws IOException
Description copied from class: FileSystem
Set replication for an existing file.

Overrides:
setReplication in class FileSystem
Parameters:
src - file name
replication - new replication
Returns:
true if successful; false if file does not exist or is a directory
Throws:
IOException

rename

public boolean rename(Path src,
                      Path dst)
               throws IOException
Rename files/dirs

Specified by:
rename in class FileSystem
Throws:
IOException

delete

@Deprecated
public boolean delete(Path f)
               throws IOException
Deprecated. 

Get rid of Path f, whether a true file or dir.

Specified by:
delete in class FileSystem
Throws:
IOException

delete

public boolean delete(Path f,
                      boolean recursive)
               throws IOException
requires a boolean check to delete a non empty directory recursively.

Specified by:
delete in class FileSystem
Parameters:
f - the path to delete.
recursive - if path is a directory and set to true, the directory is deleted else throws an exception. In case of a file the recursive can be set to either true or false.
Returns:
true if delete is successful else false.
Throws:
IOException

getContentSummary

public ContentSummary getContentSummary(Path f)
                                 throws IOException
Return the ContentSummary of a given Path.

Overrides:
getContentSummary in class FileSystem
Throws:
IOException

listStatus

public FileStatus[] listStatus(Path p)
                        throws IOException
Description copied from class: FileSystem
List the statuses of the files/directories in the given path if the path is a directory.

Specified by:
listStatus in class FileSystem
Parameters:
p - given path
Returns:
the statuses of the files/directories in the given patch
Throws:
IOException

mkdirs

public boolean mkdirs(Path f,
                      FsPermission permission)
               throws IOException
Description copied from class: FileSystem
Make the given file and all non-existent parents into directories. Has the semantics of Unix 'mkdir -p'. Existence of the directory hierarchy is not an error.

Specified by:
mkdirs in class FileSystem
Throws:
IOException

close

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

Specified by:
close in interface Closeable
Overrides:
close in class FileSystem
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

getDiskStatus

public DistributedFileSystem.DiskStatus getDiskStatus()
                                               throws IOException
Return the disk usage of the filesystem, including total capacity, used space, and remaining space

Throws:
IOException

getRawCapacity

public long getRawCapacity()
                    throws IOException
Return the total raw capacity of the filesystem, disregarding replication .

Throws:
IOException

getRawUsed

public long getRawUsed()
                throws IOException
Return the total raw used space in the filesystem, disregarding replication .

Throws:
IOException

getDataNodeStats

public DatanodeInfo[] getDataNodeStats()
                                throws IOException
Return statistics for each datanode.

Throws:
IOException

setSafeMode

public boolean setSafeMode(FSConstants.SafeModeAction action)
                    throws IOException
Enter, leave or get safe mode.

Throws:
IOException
See Also:
ClientProtocol.setSafeMode( FSConstants.SafeModeAction)

refreshNodes

public void refreshNodes()
                  throws IOException
Throws:
IOException

finalizeUpgrade

public void finalizeUpgrade()
                     throws IOException
Finalize previously upgraded files system state.

Throws:
IOException

distributedUpgradeProgress

public UpgradeStatusReport distributedUpgradeProgress(FSConstants.UpgradeAction action)
                                               throws IOException
Throws:
IOException

metaSave

public void metaSave(String pathname)
              throws IOException
Throws:
IOException

reportChecksumFailure

public boolean reportChecksumFailure(Path f,
                                     FSDataInputStream in,
                                     long inPos,
                                     FSDataInputStream sums,
                                     long sumsPos)
We need to find the blocks that didn't match. Likely only one is corrupt but we will report both to the namenode. In the future, we can consider figuring out exactly which block is corrupt.


getFileStatus

public FileStatus getFileStatus(Path f)
                         throws IOException
Returns the stat information about the file.

Specified by:
getFileStatus in class FileSystem
Parameters:
f - The path we want information from
Returns:
a FileStatus object
Throws:
FileNotFoundException - if the file does not exist.
IOException

setPermission

public void setPermission(Path p,
                          FsPermission permission)
                   throws IOException
Set permission of a path.

Overrides:
setPermission in class FileSystem
Throws:
IOException

setOwner

public void setOwner(Path p,
                     String username,
                     String groupname)
              throws IOException
Set owner of a path (i.e. a file or a directory). The parameters username and groupname cannot both be null.

Overrides:
setOwner in class FileSystem
Parameters:
p - The path
username - If it is null, the original username remains unchanged.
groupname - If it is null, the original groupname remains unchanged.
Throws:
IOException


Copyright © 2008 The Apache Software Foundation