org.hbase.async
Class MapRTableMappingRules

java.lang.Object
  extended by org.hbase.async.MapRTableMappingRules

public class MapRTableMappingRules
extends Object

The TableMappingRule class encapsulate the rules for deciding if a table name map to HBase table or a MapR table.

Apache HBase has its own flat namespace (no slashes in a table name). This namespace must be supported by MapR, because:

  1. A customer may run Apache HBase on a MapR cluster
  2. A customer may have applications with hard-coded table names which they want to migrate to Goose

A single client JAR supports both Goose and Apache HBase.

The following rules determine, based on the table name/path, whether it's a Goose table or an Apache HBase table:

PatternTable type
a/b/c (anything with a slash)    Goose
maprfs://...Goose
hbase://mytable1Apache HBase
mytable1 (no slash)   (See notes below)

Notes: If a mapping for this table name exists in the client configuration, this is a Goose table. Otherwise, it is a stock HBase table.

HBase table namespace mappings

As explained in FS-NS-003, there needs to be a way to determine whether a flat table name (no slashes and doesn't start with hbase://) should be treated as a stock HBase table or a Goose table. This is accomplished with a client-side configuration called hbase.table.namespace.mappings.

Example 1:

<name>hbase.table.namespace.mappings</name>
<value>*:/tables</value>

Any flat table name foo is treated as a Goose table at /tables/foo.

Example 2:

<name>hbase.table.namespace.mappings</name>
<value>mytable1:/user/aaa,mytable2:/user/bbb</value>

Example 3:

<name>hbase.table.namespace.mappings</name>
<value>mytable1:/user/aaa,mapr-*:/user/bbb,*:/tables</value>

Mappings are evaluated in order. The flat table name mytable1 is treated as a Goose table at /user/aaa/mytable1. Any flat table with name starting with "mapr-" is treated as a Goose table at /user/bbb/mapr-*. Any other flat table name foo is treated as a Goose table at /tables/foo.

Example 4 (same as not specifying this parameter at all):

<name>hbase.table.namespace.mappings</name>
<value></value>

All flat table names are treated as stock HBase tables.


Nested Class Summary
static class MapRTableMappingRules.ClusterType
          Describe the type of cluster based on the running services.
 
Field Summary
static String HBASE_AVAILABLE
           
static String HBASE_ENGINE
           
static String HBASE_PREFIX
           
static org.apache.hadoop.fs.Path HBASE_PREFIX_PATH
           
static String HBASE_TABLE_NAMESPACE_MAPPINGS
           
static String MAPR_ENGINE
           
static String MAPRFS_PREFIX
           
static byte[] META_TABLE_NAME
          The META table's name.
static byte[] ROOT_TABLE_NAME
          The root table's name.
static String UTF8_ENCODING
          When we encode strings, we always specify UTF8 encoding
 
Constructor Summary
MapRTableMappingRules(org.apache.hadoop.conf.Configuration conf)
          Creates a table mapping rule object based on the value of 'hbase.table.namespace.mappings' parameter in the conf.
 
Method Summary
 MapRTableMappingRules.ClusterType getClusterType()
           
protected  org.apache.hadoop.fs.FileSystem getFS()
          Lazy initialization of FileSystem object using the Configuration provided in the constructor.
static org.apache.hadoop.fs.Path getMapRTablePath(org.apache.hadoop.conf.Configuration conf, String tableName)
           
 org.apache.hadoop.fs.Path getMapRTablePath(String tableName)
          Returns translated path according to the configured mapping.
 boolean isMapRDefault()
           
static boolean isMapRTable(org.apache.hadoop.conf.Configuration conf, String tableName)
           
 boolean isMapRTable(String tableName)
          Tests if tableName should be treated as MapR table
static boolean isMetaTable(String tableName)
          Checks of the tableName being passed represents either -ROOT- or .META.
protected  org.apache.hadoop.fs.Path makePath(String parent, String table)
          Constructs absolute table path from the parent and the table name.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAPR_ENGINE

public static final String MAPR_ENGINE
See Also:
Constant Field Values

HBASE_ENGINE

public static final String HBASE_ENGINE
See Also:
Constant Field Values

HBASE_TABLE_NAMESPACE_MAPPINGS

public static final String HBASE_TABLE_NAMESPACE_MAPPINGS
See Also:
Constant Field Values

HBASE_AVAILABLE

public static final String HBASE_AVAILABLE
See Also:
Constant Field Values

MAPRFS_PREFIX

public static final String MAPRFS_PREFIX
See Also:
Constant Field Values

HBASE_PREFIX

public static final String HBASE_PREFIX
See Also:
Constant Field Values

HBASE_PREFIX_PATH

public static final org.apache.hadoop.fs.Path HBASE_PREFIX_PATH

ROOT_TABLE_NAME

public static final byte[] ROOT_TABLE_NAME
The root table's name.


META_TABLE_NAME

public static final byte[] META_TABLE_NAME
The META table's name.


UTF8_ENCODING

public static final String UTF8_ENCODING
When we encode strings, we always specify UTF8 encoding

See Also:
Constant Field Values
Constructor Detail

MapRTableMappingRules

public MapRTableMappingRules(org.apache.hadoop.conf.Configuration conf)
Creates a table mapping rule object based on the value of 'hbase.table.namespace.mappings' parameter in the conf.

The class maintains a global HashMap of mapping rules string and its compiled form. If the current mapping rule is not found in the map, it is compiled and put in the hash-map.

Parameters:
conf -
Method Detail

isMapRDefault

public boolean isMapRDefault()

getClusterType

public MapRTableMappingRules.ClusterType getClusterType()

isMapRTable

public boolean isMapRTable(String tableName)
Tests if tableName should be treated as MapR table

Parameters:
tableName -
Returns:
true if the table is determined to be a MapR table.
Throws:
IOException
IllegalArgumentException - If the passed tableName is null

isMapRTable

public static boolean isMapRTable(org.apache.hadoop.conf.Configuration conf,
                                  String tableName)

toString

public String toString()
Overrides:
toString in class Object

isMetaTable

public static boolean isMetaTable(String tableName)
Checks of the tableName being passed represents either -ROOT- or .META.

Returns:
true if a tablesName is either -ROOT- or .META.

getMapRTablePath

public org.apache.hadoop.fs.Path getMapRTablePath(String tableName)
                                           throws IllegalArgumentException
Returns translated path according to the configured mapping. See MapRTableMappingRules

Parameters:
tableName - Absolute or relative table name
Returns:
Translated absolute path if the table is a MapR table, null otherwise
Throws:
IllegalArgumentException

getMapRTablePath

public static org.apache.hadoop.fs.Path getMapRTablePath(org.apache.hadoop.conf.Configuration conf,
                                                         String tableName)

makePath

protected org.apache.hadoop.fs.Path makePath(String parent,
                                             String table)
Constructs absolute table path from the parent and the table name.
  1. If the parent does not end with '/', table name is ignored else table name is appended to parent.
  2. If parent does not start with '/', user's home directory is prefixed to the resultant path.

Parameters:
parent -
table -
Returns:
the absolute path
Throws:
IOException

getFS

protected org.apache.hadoop.fs.FileSystem getFS()
                                         throws IOException
Lazy initialization of FileSystem object using the Configuration provided in the constructor. This code will not get executed if there is no rule with relative path.

Returns:
the FileSystem object
Throws:
IOException


Copyright © 2010-2014, The Async HBase Authors