2

I am experiencing an unexpected behaviour using the Java API to truncate an HBase table. In detail, I am doing the following operations:

  1. Disable the table
  2. Truncate the table
  3. Enable the table

The code corresponding to these operations is the following:

 Configuration conf = HBaseConfiguration.create();
 // ...
 // Setting properly the configuration information
 // ...
 try (HBaseAdmin admin = new HBaseAdmin(conf)) {
     if (admin.isTableEnabled(TABLE_NAME)) {
         admin.disableTable(TABLE_NAME);
     }
     admin.truncateTable(TableName.valueOf(TABLE_NAME), false);
     // Enabling the table after having truncated
     admin.enableTable(TABLE_NAME);
 } catch (MasterNotRunningException e) {
     e.printStackTrace();
 } catch (ZooKeeperConnectionException e) {
     e.printStackTrace();
 } catch (IOException e) {
     e.printStackTrace();
 }

Now, the statement admin.enableTable(TABLE_NAME) after the truncate operation throws an org.apache.hadoop.hbase.TableNotDisabledException. Is it correct? Truncating a table via Java API re-enables it automagically?

I have checked the API and I did not find any reference to this behaviuor.

I am using HBase, version 1.0.0-cdh5.5.0.

riccardo.cardin
  • 7,971
  • 5
  • 57
  • 106

1 Answers1

2

Hbase truncate needs to perform 3 operations:

  1. Disables table if it already presents(as it drops table in second operation which needs to be disabled first)
  2. Drops table if it already presents
  3. Recreates the mentioned table(any create will automatically enables the table)

Same behavior is with hbase-shell truncate command. The only difference between shell and java api is that shell automatically performs all, but in java api, table needs to be disabled first explicitly to achieve second drop operation and last operation creates it again, so new table is enabled by default.

Hope this explains...

Anupam Jain
  • 476
  • 2
  • 6