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

java.lang.Object
  extended by org.apache.hadoop.hdfs.server.common.StorageInfo
      extended by org.apache.hadoop.hdfs.server.common.Storage
All Implemented Interfaces:
org.apache.hadoop.io.Writable
Direct Known Subclasses:
DataStorage, FSImage

@InterfaceAudience.Private
public abstract class Storage
extends StorageInfo

Storage information file.

Local storage information is stored in a separate file VERSION. It contains type of the node, the storage layout version, the namespace id, and the fs state creation time.

Local storage can reside in multiple directories. Each directory should contain the same VERSION file as the others. During startup Hadoop servers (name-node and data-nodes) read their local storage information from them.

The servers hold a lock for each storage directory while they run so that other nodes were not able to startup sharing the same storage. The locks are released when the servers stop (normally or abnormally).


Nested Class Summary
 class Storage.StorageDirectory
          One of the storage directories.
static interface Storage.StorageDirType
          An interface to denote storage directory type Implementations can define a type for storage directory by implementing this interface.
static class Storage.StorageState
           
 
Field Summary
protected static int LAST_PRE_UPGRADE_LAYOUT_VERSION
           
protected static String LAST_UPGRADABLE_HADOOP_VERSION
           
static int LAST_UPGRADABLE_LAYOUT_VERSION
           
static org.apache.commons.logging.Log LOG
           
static int PRE_GENERATIONSTAMP_LAYOUT_VERSION
           
static int PRE_RBW_LAYOUT_VERSION
           
static String STORAGE_DIR_CURRENT
           
protected static String STORAGE_FILE_VERSION
           
protected  List<Storage.StorageDirectory> storageDirs
           
 
Fields inherited from class org.apache.hadoop.hdfs.server.common.StorageInfo
cTime, layoutVersion, namespaceID
 
Constructor Summary
protected Storage(HdfsConstants.NodeType type)
          Create empty storage info of the specified type
protected Storage(HdfsConstants.NodeType type, int nsID, long cT)
           
protected Storage(HdfsConstants.NodeType type, StorageInfo storageInfo)
           
 
Method Summary
protected  void addStorageDir(Storage.StorageDirectory sd)
           
protected static void checkVersionUpgradable(int oldVersion)
          Checks if the upgrade from the given old version is supported.
protected abstract  void corruptPreUpgradeStorage(File rootDir)
           
protected static void deleteDir(File dir)
           
 Iterator<Storage.StorageDirectory> dirIterator()
          Return default iterator This iterator returns all entries in storageDirs
 Iterator<Storage.StorageDirectory> dirIterator(Storage.StorageDirType dirType)
          Return iterator based on Storage Directory Type This iterator selects entries in storageDirs of type dirType and returns them via the Iterator
static String getBuildVersion()
           
protected  void getFields(Properties props, Storage.StorageDirectory sd)
          Get common storage fields.
 int getNumStorageDirs()
           
static String getRegistrationID(StorageInfo storage)
           
 Storage.StorageDirectory getStorageDir(int idx)
           
abstract  boolean isConversionNeeded(Storage.StorageDirectory sd)
           
 boolean isLockSupported(int idx)
          Check whether underlying file system supports file locking.
 String listStorageDirectories()
          generate storage list (debug line)
static void rename(File from, File to)
           
protected  void setFields(Properties props, Storage.StorageDirectory sd)
          Set common storage fields.
 void unlockAll()
          Unlock all storage directories.
 void writeAll()
          Write all data storage files.
protected  void writeCorruptedData(RandomAccessFile file)
           
 
Methods inherited from class org.apache.hadoop.hdfs.server.common.StorageInfo
getCTime, getLayoutVersion, getNamespaceID, readFields, setStorageInfo, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.commons.logging.Log LOG

LAST_PRE_UPGRADE_LAYOUT_VERSION

protected static final int LAST_PRE_UPGRADE_LAYOUT_VERSION
See Also:
Constant Field Values

LAST_UPGRADABLE_LAYOUT_VERSION

public static final int LAST_UPGRADABLE_LAYOUT_VERSION
See Also:
Constant Field Values

LAST_UPGRADABLE_HADOOP_VERSION

protected static final String LAST_UPGRADABLE_HADOOP_VERSION
See Also:
Constant Field Values

PRE_GENERATIONSTAMP_LAYOUT_VERSION

public static final int PRE_GENERATIONSTAMP_LAYOUT_VERSION
See Also:
Constant Field Values

PRE_RBW_LAYOUT_VERSION

public static final int PRE_RBW_LAYOUT_VERSION
See Also:
Constant Field Values

STORAGE_FILE_VERSION

protected static final String STORAGE_FILE_VERSION
See Also:
Constant Field Values

STORAGE_DIR_CURRENT

public static final String STORAGE_DIR_CURRENT
See Also:
Constant Field Values

storageDirs

protected List<Storage.StorageDirectory> storageDirs
Constructor Detail

Storage

protected Storage(HdfsConstants.NodeType type)
Create empty storage info of the specified type


Storage

protected Storage(HdfsConstants.NodeType type,
                  int nsID,
                  long cT)

Storage

protected Storage(HdfsConstants.NodeType type,
                  StorageInfo storageInfo)
Method Detail

dirIterator

public Iterator<Storage.StorageDirectory> dirIterator()
Return default iterator This iterator returns all entries in storageDirs


dirIterator

public Iterator<Storage.StorageDirectory> dirIterator(Storage.StorageDirType dirType)
Return iterator based on Storage Directory Type This iterator selects entries in storageDirs of type dirType and returns them via the Iterator


listStorageDirectories

public String listStorageDirectories()
generate storage list (debug line)


getNumStorageDirs

public int getNumStorageDirs()

getStorageDir

public Storage.StorageDirectory getStorageDir(int idx)

addStorageDir

protected void addStorageDir(Storage.StorageDirectory sd)

isConversionNeeded

public abstract boolean isConversionNeeded(Storage.StorageDirectory sd)
                                    throws IOException
Throws:
IOException

checkVersionUpgradable

protected static void checkVersionUpgradable(int oldVersion)
                                      throws IOException
Checks if the upgrade from the given old version is supported. If no upgrade is supported, it throws IncorrectVersionException.

Parameters:
oldVersion -
Throws:
IOException

getFields

protected void getFields(Properties props,
                         Storage.StorageDirectory sd)
                  throws IOException
Get common storage fields. Should be overloaded if additional fields need to be get.

Parameters:
props -
Throws:
IOException

setFields

protected void setFields(Properties props,
                         Storage.StorageDirectory sd)
                  throws IOException
Set common storage fields. Should be overloaded if additional fields need to be set.

Parameters:
props -
Throws:
IOException

rename

public static void rename(File from,
                          File to)
                   throws IOException
Throws:
IOException

deleteDir

protected static void deleteDir(File dir)
                         throws IOException
Throws:
IOException

writeAll

public void writeAll()
              throws IOException
Write all data storage files.

Throws:
IOException

unlockAll

public void unlockAll()
               throws IOException
Unlock all storage directories.

Throws:
IOException

isLockSupported

public boolean isLockSupported(int idx)
                        throws IOException
Check whether underlying file system supports file locking.

Returns:
true if exclusive locks are supported or false otherwise.
Throws:
IOException
See Also:
Storage.StorageDirectory.lock()

getBuildVersion

public static String getBuildVersion()

getRegistrationID

public static String getRegistrationID(StorageInfo storage)

corruptPreUpgradeStorage

protected abstract void corruptPreUpgradeStorage(File rootDir)
                                          throws IOException
Throws:
IOException

writeCorruptedData

protected void writeCorruptedData(RandomAccessFile file)
                           throws IOException
Throws:
IOException


Copyright © 2009 The Apache Software Foundation