org.apache.hadoop.hbase.util
Class FSTableDescriptors

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

@InterfaceAudience.Private
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 in the TABLEINFO_DIR subdir of 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 in the TABLEINFO_DIR subdir of the table directory in the filesystem. It has a TABLEINFO_FILE_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.


Constructor Summary
FSTableDescriptors(org.apache.hadoop.conf.Configuration conf)
          Construct a FSTableDescriptors instance using the hbase root dir of the given conf and the filesystem where that root dir lives.
FSTableDescriptors(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir)
           
FSTableDescriptors(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir, boolean fsreadonly, boolean usecache)
           
 
Method Summary
 void add(HTableDescriptor htd)
          Adds (or updates) the table descriptor to the FileSystem and updates the local cache with it.
 boolean createTableDescriptor(HTableDescriptor htd)
          Create new HTableDescriptor in HDFS.
 boolean createTableDescriptor(HTableDescriptor htd, boolean forceCreation)
          Create new HTableDescriptor in HDFS.
 boolean createTableDescriptorForTableDirectory(org.apache.hadoop.fs.Path tableDir, HTableDescriptor htd, boolean forceCreation)
          Create a new HTableDescriptor in HDFS in the specified table directory.
 void deleteTableDescriptorIfExists(TableName tableName)
          Deletes all the table descriptor files from the file system.
 HTableDescriptor get(TableName tablename)
          Get the current table descriptor for the given table, or null if none exists.
 Map<String,HTableDescriptor> getAll()
          Returns a map from table name to table descriptor for all tables.
 Map<String,HTableDescriptor> getByNamespace(String name)
          Get Map of all NamespaceDescriptors for a given namespace.
static HTableDescriptor getTableDescriptorFromFs(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir)
          Returns the latest table descriptor for the table located at the given directory directly from the file system if it exists.
static HTableDescriptor getTableDescriptorFromFs(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir, boolean rewritePb)
          Returns the latest table descriptor for the table located at the given directory directly from the file system if it exists.
static HTableDescriptor getTableDescriptorFromFs(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path hbaseRootDir, TableName tableName)
          Returns the latest table descriptor for the given table directly from the file system if it exists, bypassing the local cache.
static HTableDescriptor getTableDescriptorFromFs(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path hbaseRootDir, TableName tableName, boolean rewritePb)
          Returns the latest table descriptor for the table located at the given directory directly from the file system if it exists.
static org.apache.hadoop.fs.FileStatus getTableInfoPath(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir)
          Find the most current table info file for the table located in the given table directory.
 boolean isTableInfoExists(TableName tableName)
          Checks if a current table info file exists for the given table
 boolean isUsecache()
           
 HTableDescriptor remove(TableName tablename)
          Removes the table descriptor from the local cache and returns it.
 void setCacheOff()
          Disables the tabledescriptor cache
 void setCacheOn()
          Enables the tabledescriptor cache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FSTableDescriptors

public FSTableDescriptors(org.apache.hadoop.conf.Configuration conf)
                   throws IOException
Construct a FSTableDescriptors instance using the hbase root dir of the given conf and the filesystem where that root dir lives. This instance can do write operations (is not read only).

Throws:
IOException

FSTableDescriptors

public FSTableDescriptors(org.apache.hadoop.conf.Configuration conf,
                          org.apache.hadoop.fs.FileSystem fs,
                          org.apache.hadoop.fs.Path rootdir)
                   throws IOException
Throws:
IOException

FSTableDescriptors

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

setCacheOn

public void setCacheOn()
                throws IOException
Description copied from interface: TableDescriptors
Enables the tabledescriptor cache

Specified by:
setCacheOn in interface TableDescriptors
Throws:
IOException

setCacheOff

public void setCacheOff()
                 throws IOException
Description copied from interface: TableDescriptors
Disables the tabledescriptor cache

Specified by:
setCacheOff in interface TableDescriptors
Throws:
IOException

isUsecache

public boolean isUsecache()

get

public HTableDescriptor get(TableName tablename)
                     throws IOException
Get the current table descriptor for the given table, or null if none exists. Uses a local cache of the descriptor but still checks the filesystem on each call to see if a newer file has been created since the cached one was read.

Specified by:
get in interface TableDescriptors
Returns:
HTableDescriptor for tablename
Throws:
IOException

getAll

public Map<String,HTableDescriptor> getAll()
                                    throws IOException
Returns a map from table name to table descriptor for all tables.

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

getByNamespace

public Map<String,HTableDescriptor> getByNamespace(String name)
                                            throws IOException
Description copied from interface: TableDescriptors
Get Map of all NamespaceDescriptors for a given namespace.

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

add

public void add(HTableDescriptor htd)
         throws IOException
Adds (or updates) the table descriptor to the FileSystem and updates the local cache with it.

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

remove

public HTableDescriptor remove(TableName tablename)
                        throws IOException
Removes the table descriptor from the local cache and returns it. If not in read only mode, it also deletes the entire table directory(!) from the FileSystem.

Specified by:
remove in interface TableDescriptors
Returns:
Instance of table descriptor or null if none found.
Throws:
IOException

isTableInfoExists

public boolean isTableInfoExists(TableName tableName)
                          throws IOException
Checks if a current table info file exists for the given table

Parameters:
tableName - name of table
Returns:
true if exists
Throws:
IOException

getTableInfoPath

public static org.apache.hadoop.fs.FileStatus getTableInfoPath(org.apache.hadoop.fs.FileSystem fs,
                                                               org.apache.hadoop.fs.Path tableDir)
                                                        throws IOException
Find the most current table info file for the table located in the given table directory. Looks within the TABLEINFO_DIR subdirectory of the given directory for any table info files and takes the 'current' one - meaning the one with the highest sequence number if present or no sequence number at all if none exist (for backward compatibility from before there were sequence numbers).

Returns:
The file status of the current table info file or null if it does not exist
Throws:
IOException

getTableDescriptorFromFs

public static HTableDescriptor getTableDescriptorFromFs(org.apache.hadoop.fs.FileSystem fs,
                                                        org.apache.hadoop.fs.Path hbaseRootDir,
                                                        TableName tableName)
                                                 throws IOException
Returns the latest table descriptor for the given table directly from the file system if it exists, bypassing the local cache. Returns null if it's not found.

Throws:
IOException

getTableDescriptorFromFs

public static HTableDescriptor getTableDescriptorFromFs(org.apache.hadoop.fs.FileSystem fs,
                                                        org.apache.hadoop.fs.Path hbaseRootDir,
                                                        TableName tableName,
                                                        boolean rewritePb)
                                                 throws IOException
Returns the latest table descriptor for the table located at the given directory directly from the file system if it exists.

Throws:
TableInfoMissingException - if there is no descriptor
IOException

getTableDescriptorFromFs

public static HTableDescriptor getTableDescriptorFromFs(org.apache.hadoop.fs.FileSystem fs,
                                                        org.apache.hadoop.fs.Path tableDir)
                                                 throws IOException
Returns the latest table descriptor for the table located at the given directory directly from the file system if it exists.

Throws:
TableInfoMissingException - if there is no descriptor
IOException

getTableDescriptorFromFs

public static HTableDescriptor getTableDescriptorFromFs(org.apache.hadoop.fs.FileSystem fs,
                                                        org.apache.hadoop.fs.Path tableDir,
                                                        boolean rewritePb)
                                                 throws IOException
Returns the latest table descriptor for the table located at the given directory directly from the file system if it exists.

Throws:
TableInfoMissingException - if there is no descriptor
IOException

deleteTableDescriptorIfExists

public void deleteTableDescriptorIfExists(TableName tableName)
                                   throws IOException
Deletes all the table descriptor files from the file system. Used in unit tests only.

Throws:
org.apache.commons.lang.NotImplementedException - if in read only mode
IOException

createTableDescriptor

public boolean createTableDescriptor(HTableDescriptor htd)
                              throws IOException
Create new HTableDescriptor in HDFS. Happens when we are creating table. Used by tests.

Returns:
True if we successfully created file.
Throws:
IOException

createTableDescriptor

public boolean createTableDescriptor(HTableDescriptor htd,
                                     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

Returns:
True if we successfully created file.
Throws:
IOException

createTableDescriptorForTableDirectory

public boolean createTableDescriptorForTableDirectory(org.apache.hadoop.fs.Path tableDir,
                                                      HTableDescriptor htd,
                                                      boolean forceCreation)
                                               throws IOException
Create a new HTableDescriptor in HDFS in the specified table directory. Happens when we create a new table or snapshot a table.

Parameters:
tableDir - table directory under which we should write the file
htd - description of the table to write
forceCreation - if true,then even if previous table descriptor is present it will be overwritten
Returns:
true if the we successfully created the file, false if the file already exists and we weren't forcing the descriptor creation.
Throws:
IOException - if a filesystem error occurs


Copyright © 2015 The Apache Software Foundation. All rights reserved.