環境描述: 操作系統版本:CentOS release 6.5 (Final) 內核版本:2.6.32-431.el6.x86_64 phoenix版本:phoenix-4.10.0 hbase版本:hbase-1.2.6 hbase節點分佈:1個HMaster,2個RegionServer 文檔目 ...
環境描述:
- 操作系統版本:CentOS release 6.5 (Final)
- 內核版本:2.6.32-431.el6.x86_64
- phoenix版本:phoenix-4.10.0
- hbase版本:hbase-1.2.6
- hbase節點分佈:1個HMaster,2個RegionServer
文檔目的:
通過在phoenix客戶端連接hbase資料庫,在phoenix中創建二級索引。
配置過程:
1.登錄到RegionSever節點,修改hbase-site.xml配置文件,加入如下配置
<property>
<name>phoenix.query.maxServerCacheBytes</name>
<value>2097152000</value>
</property>
<property>
<name>hbase.regionserver.wal.codec</name>
<value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value>
</property>
<property>
<name>hbase.region.server.rpc.scheduler.factory.class</name>
<value>org.apache.hadoop.hbase.ipc.PhoenixRpcSchedulerFactory</value>
<description>Factory to create the Phoenix RPC Scheduler that uses separate queues for index and metadata updates</description>
</property>
<property>
<name>hbase.rpc.controllerfactory.class</name>
<value>org.apache.hadoop.hbase.ipc.controller.ServerRpcControllerFactory</value>
<description>Factory to create the Phoenix RPC Scheduler that uses separate queues for index and metadata updates</description>
</property>
備註:要在所有的RegionServer節點進行添加,HMaster節點的hbase-site.xml配置文件不需要進行修改。
2.修改之後,重新啟動hbase服務
進入hbase-1.2.6目錄:
bin/stop-hbase.sh
bin/start-hbase.sh
3.通過jps檢查各個hbase節點進程無異常
4.通過phoenix連接hbase,然後創建二級索引
創建表測試表:
CREATE TABLE IF NOT EXISTS WEB_STAT (
HOST CHAR(2) NOT NULL,
DOMAIN VARCHAR NOT NULL,
FEATURE VARCHAR NOT NULL,
DATE DATE NOT NULL,
USAGE.CORE BIGINT,
USAGE.DB BIGINT,
STATS.ACTIVE_VISITOR INTEGER
CONSTRAINT PK PRIMARY KEY (HOST, DOMAIN, FEATURE, DATE)
);
創建二級索引:
CREATE INDEX IDX_01 ON WEB_STAT(HOST);
刪除二級索引:
DROP INDEX IDX_01 ON WEB_STAT
備註:如果以上創建索引沒有報錯,說明以上的基本配置是沒有問題的。
如果不配置以上參數,會報下麵的錯誤:
0: jdbc:phoenix:redhat6> create index my_index on example (M.C0);
Error: ERROR 1029 (42Y88): Mutable secondary indexes must have the hbase.regionserver.wal.codec property set to org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec in the hbase-sites.xml of every region server. tableName=MY_INDEX (state=42Y88,code=1029)
java.sql.SQLException: ERROR 1029 (42Y88): Mutable secondary indexes must have the hbase.regionserver.wal.codec property set to org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec in the hbase-sites.xml of every region server. tableName=MY_INDEX
at org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:488)
at org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:150)
at org.apache.phoenix.schema.MetaDataClient.createIndex(MetaDataClient.java:1456)
at org.apache.phoenix.compile.CreateIndexCompiler$1.execute(CreateIndexCompiler.java:85)
at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:394)
at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:377)
at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
at org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:375)
at org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:364)
at org.apache.phoenix.jdbc.PhoenixStatement.execute(PhoenixStatement.java:1738)
at sqlline.Commands.execute(Commands.java:822)
at sqlline.Commands.sql(Commands.java:732)
at sqlline.SqlLine.dispatch(SqlLine.java:813)
at sqlline.SqlLine.begin(SqlLine.java:686)
at sqlline.SqlLine.start(SqlLine.java:398)
at sqlline.SqlLine.main(SqlLine.java:291)