HBase:通过 Java API 截断 table 启用 table 截断

HBase: truncate table via Java API enable the table truncated

我在使用 Java API 截断 HBase table 时遇到意外行为。具体来说,我是在做以下操作:

  1. 禁用 table
  2. 截断 table
  3. 启用table

这些操作对应的代码如下:

 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();
 }

现在,截断操作后的语句 admin.enableTable(TABLE_NAME) 抛出 org.apache.hadoop.hbase.TableNotDisabledException。这是正确的吗?通过 Java API 截断 table 会自动重新启用它吗?

我检查了 API,但没有找到任何关于此行为的参考。

我正在使用 HBase,版本 1.0.0-cdh5.5.0。

Hbase truncate需要执行3个操作:

  1. 禁用 table 如果它已经存在(因为它在需要首先禁用的第二次操作中下降 table)
  2. 如果已经存在,则丢弃 table
  3. 重新创建提到的 table(任何创建都会自动启用 table)

hbase-shell truncate 命令的行为相同。 shell和javaapi的唯一区别是shell自动执行所有,而在javaapi、table需要首先明确禁用以实现第二个删除操作,最后一个操作再次创建它,因此默认启用新 table。

希望这能解释...