Disabling a Table

Disabling a Table using HBase Shell

To delete a table or change its settings, you need to first disable the table using the disable command. You can re-enable it using the enable command.

Syntax

disable ‘emp’

Example

Given below is an example that shows how to disable a table.

hbase> disable 'emp'
0 row(s) in 1.2760 seconds
Verification

After disabling the table, you can still sense its existence through list and exists commands. You cannot scan it. It will give you the following error.

hbase> scan 'emp'
ROW         COLUMN + CELL
ERROR: emp is disabled.
is_disabled

This command is used to find whether a table is disabled. Its syntax is as follows.

hbase> is_disabled 'table name'

The following example verifies whether the table named emp is disabled. If it is disabled, it will return true and if not, it will return false.

hbase> is_disabled 'emp'
true
0 row(s) in 0.0348 seconds
disable_all

This command is used to disable all the tables matching the given regex. The syntax for disable_all command is given below.

hbase> disable_all 'a.*'

Suppose there are 5 tables in HBase, namely ashok, ajay, anjali, akila, and anand. The following code will disable all the tables starting with a.

hbase> disable_all 'a.*'
ashok
ajay
anjali
akila
anand
Disable the above 5 tables (y/n)?
y
5 tables successfully disabled
Disable a Table Using Java API

To verify whether a table is disabled, isTableDisabled() method is used and to disable a table, disableTable() method is used. These methods belong to the HBaseAdmin class.

package com.ashok.hbase;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.HBaseAdmin;

/**
 * 
 * @author ashok.mariyala
 *
 */
public class DisableTable{
   public static void main(String args[]) throws MasterNotRunningException, IOException{

      // Instantiating configuration class
      Configuration conf = HBaseConfiguration.create();

      // Instantiating HBaseAdmin class
      HBaseAdmin admin = new HBaseAdmin(conf);

      // Verifying weather the table is disabled
      Boolean bool = admin.isTableDisabled("emp");
      System.out.println(bool);

      // Disabling the table using HBaseAdmin object
      if(!bool){
         admin.disableTable("emp");
         System.out.println("Successfully Table disabled");
      }
   }
}


Disabling a Table
Scroll to top