org.apache.hadoop.hbase.util
Class FSTableDescriptors

java.lang.Object
  extended by org.apache.hadoop.hbase.util.FSTableDescriptors
All Implemented Interfaces:
TableDescriptors

public class FSTableDescriptors
extends Object
implements TableDescriptors

Implementation of TableDescriptors that reads descriptors from the passed filesystem. It expects descriptors to be in a file under the table's directory in FS. Can be read-only -- i.e. does not modify the filesystem or can be read and write.

Also has utility for keeping up the table descriptors tableinfo file. The table schema file is kept under the table directory in the filesystem. It has a TABLEINFO_NAME prefix and then a suffix that is the edit sequenceid: e.g. .tableinfo.0000000003. This sequenceid is always increasing. It starts at zero. The table schema file with the highest sequenceid has the most recent schema edit. Usually there is one file only, the most recent but there may be short periods where there are more than one file. Old files are eventually cleaned. Presumption is that there will not be lots of concurrent clients making table schema edits. If so, the below needs a bit of a reworking and perhaps some supporting api in hdfs.


Field Summary
static String TABLEINFO_NAME
          The file name used to store HTD in HDFS
 
Constructor Summary
FSTableDescriptors(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir)
           
FSTableDescriptors(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir, boolean fsreadOnly)
           
 
Method Summary
 void add(HTableDescriptor htd)
          Add or update descriptor
static boolean createTableDescriptor(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir, HTableDescriptor htableDescriptor)
          Create new HTableDescriptor in HDFS.
static boolean createTableDescriptor(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir, HTableDescriptor htableDescriptor, boolean forceCreation)
          Create new HTableDescriptor in HDFS.
static boolean createTableDescriptor(HTableDescriptor htableDescriptor, org.apache.hadoop.conf.Configuration conf)
          Create new HTableDescriptor in HDFS.
static void deleteTableDescriptorIfExists(String tableName, org.apache.hadoop.conf.Configuration conf)
          Deletes a table's directory from the file system if exists.
 HTableDescriptor get(byte[] tablename)
           
 HTableDescriptor get(String tablename)
           
 Map<String,HTableDescriptor> getAll()
          Get Map of all HTableDescriptors.
static HTableDescriptor getTableDescriptor(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir)
           
static HTableDescriptor getTableDescriptor(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path hbaseRootDir, byte[] tableName)
          Get HTD from HDFS.
static boolean isTableInfoExists(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir, String tableName)
          Checks if .tableinfo exists for given table
 HTableDescriptor remove(String tablename)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TABLEINFO_NAME

public static final String TABLEINFO_NAME
The file name used to store HTD in HDFS

See Also:
Constant Field Values
Constructor Detail

FSTableDescriptors

public FSTableDescriptors(org.apache.hadoop.fs.FileSystem fs,
                          org.apache.hadoop.fs.Path rootdir)

FSTableDescriptors

public FSTableDescriptors(org.apache.hadoop.fs.FileSystem fs,
                          org.apache.hadoop.fs.Path rootdir,
                          boolean fsreadOnly)
Parameters:
fs -
rootdir -
fsreadOnly - True if we are read-only when it comes to filesystem operations; i.e. on remove, we do not do delete in fs.
Method Detail

get

public HTableDescriptor get(byte[] tablename)
                     throws FileNotFoundException,
                            IOException
Specified by:
get in interface TableDescriptors
Returns:
HTableDescriptor for tablename
Throws:
FileNotFoundException
TableExistsException
IOException

get

public HTableDescriptor get(String tablename)
                     throws FileNotFoundException,
                            IOException
Specified by:
get in interface TableDescriptors
Returns:
HTableDescriptor for tablename
Throws:
FileNotFoundException
TableExistsException
IOException

getAll

public Map<String,HTableDescriptor> getAll()
                                    throws IOException
Description copied from interface: TableDescriptors
Get Map of all HTableDescriptors. Populates the descriptor cache as a side effect.

Specified by:
getAll in interface TableDescriptors
Returns:
Map of all descriptors.
Throws:
IOException

add

public void add(HTableDescriptor htd)
         throws IOException
Description copied from interface: TableDescriptors
Add or update descriptor

Specified by:
add in interface TableDescriptors
Parameters:
htd - Descriptor to set into TableDescriptors
Throws:
IOException

remove

public HTableDescriptor remove(String tablename)
                        throws IOException
Specified by:
remove in interface TableDescriptors
Returns:
Instance of table descriptor or null if none found.
Throws:
IOException

isTableInfoExists

public static boolean isTableInfoExists(org.apache.hadoop.fs.FileSystem fs,
                                        org.apache.hadoop.fs.Path rootdir,
                                        String tableName)
                                 throws IOException
Checks if .tableinfo exists for given table

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

getTableDescriptor

public static HTableDescriptor getTableDescriptor(org.apache.hadoop.fs.FileSystem fs,
                                                  org.apache.hadoop.fs.Path hbaseRootDir,
                                                  byte[] tableName)
                                           throws IOException
Get HTD from HDFS.

Parameters:
fs -
hbaseRootDir -
tableName -
Returns:
Descriptor or null if none found.
Throws:
IOException

getTableDescriptor

public static HTableDescriptor getTableDescriptor(org.apache.hadoop.fs.FileSystem fs,
                                                  org.apache.hadoop.fs.Path tableDir)
                                           throws IOException,
                                                  NullPointerException
Throws:
IOException
NullPointerException

deleteTableDescriptorIfExists

public static void deleteTableDescriptorIfExists(String tableName,
                                                 org.apache.hadoop.conf.Configuration conf)
                                          throws IOException
Deletes a table's directory from the file system if exists. Used in unit tests.

Throws:
IOException

createTableDescriptor

public static boolean createTableDescriptor(HTableDescriptor htableDescriptor,
                                            org.apache.hadoop.conf.Configuration conf)
                                     throws IOException
Create new HTableDescriptor in HDFS. Happens when we are creating table.

Parameters:
htableDescriptor -
conf -
Throws:
IOException

createTableDescriptor

public static boolean createTableDescriptor(org.apache.hadoop.fs.FileSystem fs,
                                            org.apache.hadoop.fs.Path rootdir,
                                            HTableDescriptor htableDescriptor)
                                     throws IOException
Create new HTableDescriptor in HDFS. Happens when we are creating table. Used by tests.

Parameters:
fs -
htableDescriptor -
rootdir -
Throws:
IOException

createTableDescriptor

public static boolean createTableDescriptor(org.apache.hadoop.fs.FileSystem fs,
                                            org.apache.hadoop.fs.Path rootdir,
                                            HTableDescriptor htableDescriptor,
                                            boolean forceCreation)
                                     throws IOException
Create new HTableDescriptor in HDFS. Happens when we are creating table. If forceCreation is true then even if previous table descriptor is present it will be overwritten

Parameters:
fs -
htableDescriptor -
rootdir -
forceCreation -
Returns:
True if we successfully created file.
Throws:
IOException


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.