org.apache.hadoop.hdfs.server.common
Class Storage.StorageDirectory

java.lang.Object
  extended by org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory
Enclosing class:
Storage

@InterfaceAudience.Private
public class Storage.StorageDirectory
extends Object

One of the storage directories.


Constructor Summary
Storage.StorageDirectory(File dir)
           
Storage.StorageDirectory(File dir, Storage.StorageDirType dirType)
           
 
Method Summary
 Storage.StorageState analyzeStorage(HdfsConstants.StartupOption startOpt)
          Check consistency of the storage directory
 void clearDirectory()
          Clear and re-create storage directory.
 void doRecover(Storage.StorageState curState)
          Complete or recover storage state from previously failed transition.
 File getCurrentDir()
          Directory current contains latest files defining the file system meta-data.
 File getFinalizedTmp()
          finalized.tmp is a transient directory, which holds the previous file system state while it is being removed in response to the finalize request.
 File getLastCheckpointTmp()
          lastcheckpoint.tmp is a transient directory, which holds current file system state while the new state is saved into the new current during regular namespace updates.
 File getPreviousCheckpoint()
          previous.checkpoint is a directory, which holds the previous (before the last save) state of the storage directory.
 File getPreviousDir()
          Directory previous contains the previous file system state, which the system can be rolled back to.
 File getPreviousTmp()
          previous.tmp is a transient directory, which holds current file system state while the new state is saved into the new current during upgrade.
 File getPreviousVersionFile()
          File VERSION from the previous directory.
 File getRemovedTmp()
          removed.tmp is a transient directory, which holds current file system state while the previous state is moved into current during rollback.
 File getRoot()
          Get root directory of this storage
 Storage.StorageDirType getStorageDirType()
          Get storage directory type
 File getVersionFile()
          File VERSION contains the following fields: node type layout version namespaceID fs state creation time other fields specific for this node type The version file is always written last during storage directory updates.
 void lock()
          Lock storage to provide exclusive access.
 void read()
          Read version file.
 void read(File from)
           
 void unlock()
          Unlock storage.
 void write()
          Write version file.
 void write(File to)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Storage.StorageDirectory

public Storage.StorageDirectory(File dir)

Storage.StorageDirectory

public Storage.StorageDirectory(File dir,
                                Storage.StorageDirType dirType)
Method Detail

getRoot

public File getRoot()
Get root directory of this storage


getStorageDirType

public Storage.StorageDirType getStorageDirType()
Get storage directory type


read

public void read()
          throws IOException
Read version file.

Throws:
IOException - if file cannot be read or contains inconsistent data

read

public void read(File from)
          throws IOException
Throws:
IOException

write

public void write()
           throws IOException
Write version file.

Throws:
IOException

write

public void write(File to)
           throws IOException
Throws:
IOException

clearDirectory

public void clearDirectory()
                    throws IOException
Clear and re-create storage directory.

Removes contents of the current directory and creates an empty directory. This does not fully format storage directory. It cannot write the version file since it should be written last after all other storage type dependent files are written. Derived storage is responsible for setting specific storage values and writing the version file to disk.

Throws:
IOException

getCurrentDir

public File getCurrentDir()
Directory current contains latest files defining the file system meta-data.

Returns:
the directory path

getVersionFile

public File getVersionFile()
File VERSION contains the following fields:
  1. node type
  2. layout version
  3. namespaceID
  4. fs state creation time
  5. other fields specific for this node type
The version file is always written last during storage directory updates. The existence of the version file indicates that all other files have been successfully written in the storage directory, the storage is valid and does not need to be recovered.

Returns:
the version file path

getPreviousVersionFile

public File getPreviousVersionFile()
File VERSION from the previous directory.

Returns:
the previous version file path

getPreviousDir

public File getPreviousDir()
Directory previous contains the previous file system state, which the system can be rolled back to.

Returns:
the directory path

getPreviousTmp

public File getPreviousTmp()
previous.tmp is a transient directory, which holds current file system state while the new state is saved into the new current during upgrade. If the saving succeeds previous.tmp will be moved to previous, otherwise it will be renamed back to current by the recovery procedure during startup.

Returns:
the directory path

getRemovedTmp

public File getRemovedTmp()
removed.tmp is a transient directory, which holds current file system state while the previous state is moved into current during rollback. If the moving succeeds removed.tmp will be removed, otherwise it will be renamed back to current by the recovery procedure during startup.

Returns:
the directory path

getFinalizedTmp

public File getFinalizedTmp()
finalized.tmp is a transient directory, which holds the previous file system state while it is being removed in response to the finalize request. Finalize operation will remove finalized.tmp when completed, otherwise the removal will resume upon the system startup.

Returns:
the directory path

getLastCheckpointTmp

public File getLastCheckpointTmp()
lastcheckpoint.tmp is a transient directory, which holds current file system state while the new state is saved into the new current during regular namespace updates. If the saving succeeds lastcheckpoint.tmp will be moved to previous.checkpoint, otherwise it will be renamed back to current by the recovery procedure during startup.

Returns:
the directory path

getPreviousCheckpoint

public File getPreviousCheckpoint()
previous.checkpoint is a directory, which holds the previous (before the last save) state of the storage directory. The directory is created as a reference only, it does not play role in state recovery procedures, and is recycled automatically, but it may be useful for manual recovery of a stale state of the system.

Returns:
the directory path

analyzeStorage

public Storage.StorageState analyzeStorage(HdfsConstants.StartupOption startOpt)
                                    throws IOException
Check consistency of the storage directory

Parameters:
startOpt - a startup option.
Returns:
state Storage.StorageState of the storage directory
Throws:
InconsistentFSStateException - if directory state is not consistent and cannot be recovered.
IOException

doRecover

public void doRecover(Storage.StorageState curState)
               throws IOException
Complete or recover storage state from previously failed transition.

Parameters:
curState - specifies what/how the state should be recovered
Throws:
IOException

lock

public void lock()
          throws IOException
Lock storage to provide exclusive access.

Locking is not supported by all file systems. E.g., NFS does not consistently support exclusive locks.

If locking is supported we guarantee exculsive access to the storage directory. Otherwise, no guarantee is given.

Throws:
IOException - if locking fails

unlock

public void unlock()
            throws IOException
Unlock storage.

Throws:
IOException


Copyright © 2009 The Apache Software Foundation