org.apache.hadoop.hbase.util
Class FSUtils

java.lang.Object
  extended by org.apache.hadoop.hbase.util.FSUtils

public class FSUtils
extends Object

Utility methods for interacting with the underlying file system.


Nested Class Summary
static class FSUtils.DirFilter
          A PathFilter that returns directories.
 
Method Summary
 org.apache.hadoop.fs.Path checkdir(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir)
          Check if directory exists.
static void checkFileSystemAvailable(org.apache.hadoop.fs.FileSystem fs)
          Checks to see if the specified file system is available
static void checkVersion(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir, boolean message)
          Verifies current version of file system
static org.apache.hadoop.fs.Path create(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path p)
          Create file.
static boolean deleteDirectory(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir)
          Delete if exists.
static String getPath(org.apache.hadoop.fs.Path p)
          Return the 'path' component of a Path.
static org.apache.hadoop.fs.Path getRootDir(HBaseConfiguration c)
           
static String getVersion(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir)
          Verifies current version of file system
static boolean isMajorCompacted(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path hbaseRootDir)
          Runs through the hbase rootdir and checks all stores have only one file in them -- that is, they've been major compacted.
static boolean isMajorCompactedPre020(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path hbaseRootDir)
          Runs through the hbase rootdir and checks all stores have only one file in them -- that is, they've been major compacted.
static boolean isPre020FileLayout(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path hbaseRootDir)
          Expects to find -ROOT- directory.
static boolean rootRegionExists(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir)
          Checks if root region exists
static void setVersion(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir)
          Sets version of file system
static void setVersion(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir, String version)
          Sets version of file system
static void validateRootPath(org.apache.hadoop.fs.Path root)
          Verifies root directory path is a valid URI with a scheme
static void waitOnSafeMode(HBaseConfiguration conf, long wait)
          If DFS, check safe mode and if so, wait until we clear it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

deleteDirectory

public static boolean deleteDirectory(org.apache.hadoop.fs.FileSystem fs,
                                      org.apache.hadoop.fs.Path dir)
                               throws IOException
Delete if exists.

Parameters:
fs -
dir -
Returns:
True if deleted dir
Throws:
IOException

checkdir

public org.apache.hadoop.fs.Path checkdir(org.apache.hadoop.fs.FileSystem fs,
                                          org.apache.hadoop.fs.Path dir)
                                   throws IOException
Check if directory exists. If it does not, create it.

Parameters:
fs -
dir -
Returns:
Path
Throws:
IOException

create

public static org.apache.hadoop.fs.Path create(org.apache.hadoop.fs.FileSystem fs,
                                               org.apache.hadoop.fs.Path p)
                                        throws IOException
Create file.

Parameters:
fs -
p -
Returns:
Path
Throws:
IOException

checkFileSystemAvailable

public static void checkFileSystemAvailable(org.apache.hadoop.fs.FileSystem fs)
                                     throws IOException
Checks to see if the specified file system is available

Parameters:
fs -
Throws:
IOException

waitOnSafeMode

public static void waitOnSafeMode(HBaseConfiguration conf,
                                  long wait)
                           throws IOException
If DFS, check safe mode and if so, wait until we clear it.

Parameters:
conf -
wait - Sleep between retries
Throws:
IOException

getVersion

public static String getVersion(org.apache.hadoop.fs.FileSystem fs,
                                org.apache.hadoop.fs.Path rootdir)
                         throws IOException
Verifies current version of file system

Parameters:
fs -
rootdir -
Returns:
null if no version file exists, version string otherwise.
Throws:
IOException

checkVersion

public static void checkVersion(org.apache.hadoop.fs.FileSystem fs,
                                org.apache.hadoop.fs.Path rootdir,
                                boolean message)
                         throws IOException
Verifies current version of file system

Parameters:
fs - file system
rootdir - root directory of HBase installation
message - if true, issues a message on System.out
Throws:
IOException

setVersion

public static void setVersion(org.apache.hadoop.fs.FileSystem fs,
                              org.apache.hadoop.fs.Path rootdir)
                       throws IOException
Sets version of file system

Parameters:
fs -
rootdir -
Throws:
IOException

setVersion

public static void setVersion(org.apache.hadoop.fs.FileSystem fs,
                              org.apache.hadoop.fs.Path rootdir,
                              String version)
                       throws IOException
Sets version of file system

Parameters:
fs -
rootdir -
version -
Throws:
IOException

validateRootPath

public static void validateRootPath(org.apache.hadoop.fs.Path root)
                             throws IOException
Verifies root directory path is a valid URI with a scheme

Parameters:
root - root directory path
Throws:
IOException - if not a valid URI with a scheme

getPath

public static String getPath(org.apache.hadoop.fs.Path p)
Return the 'path' component of a Path. In Hadoop, Path is an URI. This method returns the 'path' component of a Path's URI: e.g. If a Path is hdfs://example.org:9000/hbase_trunk/TestTable/compaction.dir, this method returns /hbase_trunk/TestTable/compaction.dir. This method is useful if you want to print out a Path without qualifying Filesystem instance.

Parameters:
p - Filesystem Path whose 'path' component we are to return.
Returns:
Path portion of the Filesystem

getRootDir

public static org.apache.hadoop.fs.Path getRootDir(HBaseConfiguration c)
                                            throws IOException
Parameters:
c -
Returns:
Path to hbase root directory: i.e. hbase.rootdir as a Path.
Throws:
IOException

rootRegionExists

public static boolean rootRegionExists(org.apache.hadoop.fs.FileSystem fs,
                                       org.apache.hadoop.fs.Path rootdir)
                                throws IOException
Checks if root region exists

Parameters:
fs - file system
rootdir - root directory of HBase installation
Returns:
true if exists
Throws:
IOException

isMajorCompacted

public static boolean isMajorCompacted(org.apache.hadoop.fs.FileSystem fs,
                                       org.apache.hadoop.fs.Path hbaseRootDir)
                                throws IOException
Runs through the hbase rootdir and checks all stores have only one file in them -- that is, they've been major compacted. Looks at root and meta tables too.

Parameters:
fs -
hbaseRootDir -
Returns:
True if this hbase install is major compacted.
Throws:
IOException

isPre020FileLayout

public static boolean isPre020FileLayout(org.apache.hadoop.fs.FileSystem fs,
                                         org.apache.hadoop.fs.Path hbaseRootDir)
                                  throws IOException
Expects to find -ROOT- directory.

Parameters:
fs -
hbaseRootDir -
Returns:
True if this a pre020 layout.
Throws:
IOException

isMajorCompactedPre020

public static boolean isMajorCompactedPre020(org.apache.hadoop.fs.FileSystem fs,
                                             org.apache.hadoop.fs.Path hbaseRootDir)
                                      throws IOException
Runs through the hbase rootdir and checks all stores have only one file in them -- that is, they've been major compacted. Looks at root and meta tables too. This version differs from isMajorCompacted(FileSystem, Path) in that it expects a pre-0.20.0 hbase layout on the filesystem. Used migrating.

Parameters:
fs -
hbaseRootDir -
Returns:
True if this hbase install is major compacted.
Throws:
IOException


Copyright © 2010 The Apache Software Foundation