
- HBase 教程
- HBase - 首頁
- HBase - 概述
- HBase - 架構
- HBase - 安裝
- HBase - Shell
- HBase - 常用命令
- HBase - 管理員 API
- HBase - 建立表
- HBase - 列出表
- HBase - 停用表
- HBase - 啟用表
- HBase - 描述和修改
- HBase - 表是否存在
- HBase - 刪除表
- HBase - 關閉
- HBase - 客戶端 API
- HBase - 建立資料
- HBase - 更新資料
- HBase - 讀取資料
- HBase - 刪除資料
- HBase - 掃描
- HBase - 計數和截斷
- HBase - 安全性
- HBase 資源
- HBase - 常見問題解答
- HBase - 快速指南
- HBase - 有用資源
HBase - 停用表
使用 HBase Shell 停用表
要刪除表或更改其設定,您需要首先使用 disable 命令停用表。您可以使用 enable 命令重新啟用它。
以下是停用表的語法
disable ‘emp’
示例
以下是一個顯示如何停用表的示例。
hbase(main):025:0> disable 'emp' 0 row(s) in 1.2760 seconds
驗證
停用表後,您仍然可以透過 **list** 和 **exists** 命令感知其存在。您無法掃描它。它會給出以下錯誤。
hbase(main):028:0> scan 'emp' ROW COLUMN + CELL ERROR: emp is disabled.
is_disabled
此命令用於查詢表是否已停用。其語法如下。
hbase> is_disabled 'table name'
以下示例驗證名為 emp 的表是否已停用。如果已停用,則返回 true,否則返回 false。
hbase(main):031:0> is_disabled 'emp' true 0 row(s) in 0.0440 seconds
disable_all
此命令用於停用與給定正則表示式匹配的所有表。**disable_all** 命令的語法如下。
hbase> disable_all 'r.*'
假設 HBase 中有 5 個表,分別為 raja、rajani、rajendra、rajesh 和 raju。以下程式碼將停用所有以 **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
使用 Java API 停用表
要驗證表是否已停用,請使用 **isTableDisabled()** 方法,要停用表,請使用 **disableTable()** 方法。這些方法屬於 **HBaseAdmin** 類。請按照以下步驟停用表。
步驟 1
如下所示例項化 **HBaseAdmin** 類。
// Creating configuration object Configuration conf = HBaseConfiguration.create(); // Creating HBaseAdmin object HBaseAdmin admin = new HBaseAdmin(conf);
步驟 2
如下所示,使用 **isTableDisabled()** 方法驗證表是否已停用。
Boolean b = admin.isTableDisabled("emp");
步驟 3
如果表未停用,請如下所示停用它。
if(!b){ admin.disableTable("emp"); System.out.println("Table disabled"); }
以下是驗證表是否已停用;如果未停用,如何停用的完整程式。
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; 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("Table disabled"); } } }
如下所示編譯並執行上述程式。
$javac DisableTable.java $java DsiableTable
輸出應如下所示
false Table disabled
廣告