English 中文(简体)
HBase - Disabling a Table
  • 时间:2024-12-22

HBase - Disabpng a Table


Previous Page Next Page  

Disabpng 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.

Given below is the syntax to disable a table:

disable ‘emp’

Example

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

hbase(main):025:0> disable  emp 
0 row(s) in 1.2760 seconds

Verification

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

hbase(main):028:0> 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(main):031:0> is_disabled  emp 
true
0 row(s) in 0.0440 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  r.* 

Suppose there are 5 tables in HBase, namely raja, rajani, rajendra, rajesh, and raju. The following code will disable all the tables starting with raj.

hbase(main):002:07> disable_all  raj.* 
raja
rajani
rajendra
rajesh
raju
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. Follow the steps given below to disable a table.

Step 1

Instantiate HBaseAdmin class as shown below.

// Creating configuration object
Configuration conf = HBaseConfiguration.create();

// Creating HBaseAdmin object
HBaseAdmin admin = new HBaseAdmin(conf);

Step 2

Verify whether the table is disabled using isTableDisabled() method as shown below.

Boolean b = admin.isTableDisabled("emp");

Step 3

If the table is not disabled, disable it as shown below.

if(!b){
   admin.disableTable("emp");
   System.out.println("Table disabled");
}

Given below is the complete program to verify whether the table is disabled; if not, how to disable it.

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.cpent.HBaseAdmin;

pubpc class DisableTable{

   pubpc 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);

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

Compile and execute the above program as shown below.

$javac DisableTable.java
$java DsiableTable

The following should be the output:

false
Table disabled
Advertisements