Configure the Default Database for HBase Clients

For Hbase version 1.1 and above, a default database configuration determines whether clients connect to HBase tables or MapR-DB tables. You can change the default setting for all Hbase clients or you can set the database for a particular job. This setting is ignored for HBase 0.98.12 client connections.

Set the Default Database using configure.sh

About this task

configure.sh automatically sets the default database for the cluster but also provides a parameter that you can use to set the default database. If you do not pass the -defaultdb parameter when you run configure.sh, it automatically sets the default database using the following criteria:
Criteria Default Database
HBaseMaster or HBaseRegionServer is installed HBase
MapR DB client is installed and HBaseMaster or HBaseRegionServer are not installed MapR-DB

Procedure

Run configure.sh with the -defaultdb parameter to explicitly set the default database to either maprdb or hbase.
For example:
configure.sh -R -defaultdb maprdb
For more information, see configure.sh

Set the Default Database using hbase-site.xml

About this task

You can configure the mapr.hbase.default.db property in the hbase-site.xml to override the default database that is set for the cluster.

Procedure

  1. In the hbase-site.xml, edit the default value of mapr.hbase.default.db and set it to either hbase or maprdb.
    For example:
    <property>
        <name>mapr.hbase.default.db</name>
        <value>hbase</value>
      </property>
  2. Copy the property to the hbase-site.xml on each node that runs Hbase including HBase client nodes.

Set the Database Type in the Job Configuration

Procedure

To set the database type in the job configuration you can add the following code:
  • To connect to MapR-DB tables:
    
    Configuration conf = HBaseConfiguration.create();
    conf.set("mapr.hbase.default.db", "maprdb"); 
    Connection connection = ConnectionFactory.createConnection(conf);
    Table table = connection.getTable(<TABLE_NAME>);
  • To connect to HBase tables:
    
    Configuration conf = HBaseConfiguration.create();
    conf.set("mapr.hbase.default.db","hbase");
    Connection connection = ConnectionFactory.createConnection(conf);
    Table table = connection.getTable(<TABLE_NAME>);