欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

通过phoenix在hbase上创建二级索引,Secondary Indexing

程序员文章站 2022-04-26 11:12:51
环境描述: 操作系统版本: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)