|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.hadoop.fs.LocalDirAllocator
public class LocalDirAllocator
An implementation of a round-robin scheme for disk allocation for creating files. The way it works is that it is kept track what disk was last allocated for a file write. For the current request, the next disk from the set of disks would be allocated if the free space on the disk is sufficient enough to accommodate the file that is being considered for creation. If the space requirements cannot be met, the next disk in order would be tried and so on till a disk is found with sufficient capacity. Once a disk with sufficient space is identified, a check is done to make sure that the disk is writable. Also, there is an API provided that doesn't take the space requirements into consideration but just checks whether the disk under consideration is writable (this should be used for cases where the file size is not known apriori). An API is provided to read a path that was created earlier. That API works by doing a scan of all the disks for the input pathname. This implementation also provides the functionality of having multiple allocators per JVM (one for each unique functionality or context, like mapred, dfs-client, etc.). It ensures that there is only one instance of an allocator per context per JVM. Note: 1. The contexts referred above are actually the configuration items defined in the Configuration class like "mapred.local.dir" (for which we want to control the dir allocations). The context-strings are exactly those configuration items. 2. This implementation does not take into consideration cases where a disk becomes read-only or goes out of space while a file is being written to (disks are shared between multiple processes, and so the latter situation is probable). 3. In the class implementation, "Disk" is referred to as "Dir", which actually points to the configured directory on the Disk which will be the parent for all file write/read allocations.
Field Summary | |
---|---|
static int |
SIZE_UNKNOWN
Used when size of file to be allocated is unknown. |
Constructor Summary | |
---|---|
LocalDirAllocator(String contextCfgItemName)
Create an allocator object |
Method Summary | |
---|---|
File |
createTmpFileForWrite(String pathStr,
long size,
Configuration conf)
Creates a temporary file in the local FS. |
Iterable<Path> |
getAllLocalPathsToRead(String pathStr,
Configuration conf)
Get all of the paths that currently exist in the working directories. |
Path |
getLocalPathForWrite(String pathStr,
Configuration conf)
Get a path from the local FS. |
Path |
getLocalPathForWrite(String pathStr,
long size,
Configuration conf)
Get a path from the local FS. |
Path |
getLocalPathForWrite(String pathStr,
long size,
Configuration conf,
boolean checkWrite)
Get a path from the local FS. |
Path |
getLocalPathToRead(String pathStr,
Configuration conf)
Get a path from the local FS for reading. |
boolean |
ifExists(String pathStr,
Configuration conf)
We search through all the configured dirs for the file's existence and return true when we find |
static boolean |
isContextValid(String contextCfgItemName)
Method to check whether a context is valid |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SIZE_UNKNOWN
Constructor Detail |
---|
public LocalDirAllocator(String contextCfgItemName)
contextCfgItemName
- Method Detail |
---|
public Path getLocalPathForWrite(String pathStr, Configuration conf) throws IOException
pathStr
- the requested path (this will be created on the first
available disk)conf
- the Configuration object
IOException
public Path getLocalPathForWrite(String pathStr, long size, Configuration conf) throws IOException
pathStr
- the requested path (this will be created on the first
available disk)size
- the size of the file that is going to be writtenconf
- the Configuration object
IOException
public Path getLocalPathForWrite(String pathStr, long size, Configuration conf, boolean checkWrite) throws IOException
pathStr
- the requested path (this will be created on the first
available disk)size
- the size of the file that is going to be writtenconf
- the Configuration objectcheckWrite
- ensure that the path is writable
IOException
public Path getLocalPathToRead(String pathStr, Configuration conf) throws IOException
pathStr
- the requested file (this will be searched)conf
- the Configuration object
IOException
public Iterable<Path> getAllLocalPathsToRead(String pathStr, Configuration conf) throws IOException
pathStr
- the path underneath the rootsconf
- the configuration to look up the roots in
IOException
public File createTmpFileForWrite(String pathStr, long size, Configuration conf) throws IOException
pathStr
- prefix for the temporary filesize
- the size of the file that is going to be writtenconf
- the Configuration object
IOException
public static boolean isContextValid(String contextCfgItemName)
contextCfgItemName
-
public boolean ifExists(String pathStr, Configuration conf)
pathStr
- the requested file (this will be searched)conf
- the Configuration object
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |