CrazyAirhead

疯狂的傻瓜,傻瓜也疯狂——傻方能执著,疯狂才专注!

0%

If you want to test the HBase Indexer with a higher throughput than the manual puts explained in the Tutorial, but don’t want to bother setting up your own schema & application, you will find the demo ingester tools useful.

如果你想测试HBase Indexer在高吞吐面而不是像教程所描述的那样手工输入,也不想设置一个自己的脚本和应用,你可以用demo提取工具。

For more information on them, please see demo/README.md in the binary distribution.

更为详细的信息,可以查看发布包中的demo/README.md

The most basic indexer configuration only requires a table name and a single field. However, there are many configuration settings that can be used in an indexer configuration file to customize behavior.

最基础索引器配置只需要一个表名和一个字段名就可以。但是,有很多配置可以用于配置可以自定义解析器的行为。

1
2
3
<indexer table="mytable">
<field name="fieldname" value="columnfamily:qualifier" type="string"/>
</indexer>

全局索引器属性(Global indexer attributes)

The following is a list of attributes that can be set on the top-level element in an indexer configuration.

以下列出的属性可以在顶层<indexer>节点中配置。

table

The table attribute specifies the name of the HBase table to be indexed by the indexer. It is the only mandatory attribute in the indexer element.

table属性用于指定HBase需要索引器索引的表名。这个indexer节点中强制要求的属性。

mapping-type

The mapping-type attribute has two possible values: row, or column. This attribute specifies whether row-based or column-based indexing is to be performed.

mapping-type属性有两种值:row和column。这个属性用于指定是基于行还是基于列的索引方式。

Row-based indexing treats all data within a single HBase row as input for a single document in Solr. This is the kind of indexing that would be used for an HBase table that contains a separate entity in each row, e.g. a table containing users.

基于行索引方式把Hbase一行当中的所有数据当成Solr的一个文档输入。这种方式用于索引一行就表示一个独立的实体的Hbase表,比如包含用户的表。

Column-based indexing treats each HBase cell as input for a single document in Solr. This approach could be used for example in a messaging platform where a single user’s messages are all stored in a single row, with each message being stored in a separate cell.

基于列索引方式把Hbase的一个列当作Solr的一个文档输入。这种处理可以用于消息平台,一个用户的所有消息存在同一行中,而每条消息存在一个单独的列上。

The default mapping-type value is row.

默认的mapping-type是row。

read-row

The read-row attribute has two possible values: dynamic, or never.

read-row属性有两种值:dyamic和never。

This attribute is only important when using row-based indexing. It specifies whether or not the indexer should re-read data from HBase in order to perform indexing.

这个属性中对基于行索引的方式才是重要的。它指定索引器为了进行索引是否需要从Hbase重新读取数据。

When set to “dynamic”, the indexer will read the necessary data from a row if a partial update to the row is performed in HBase. In dynamic mode, the row will not be re-read if all data needed to perform indexing is included in the row update.

当被设置为“dynamic”时,如果HBase是一行数据的部分数据更新时,索引器会读取这一行中需要的数据。dynamic模式下,如果是一行的全部数据的更新,索引器不会重新读取Hbase的数据。

If this attribute is set to never, a row will never be re-read by the indexer.

如果这个属性被设置为never,索引器不会重读行数据。

The default setting is “dynamic”.

默认的设置是“dynamic”。

mapper

The mapper attribute allows the user to specify a custom mapper class that will create a Solr document from a HBase Result object. The mapper class must implement the com.ngdata.hbaseindexer.parse.ResultToSolrMapper interface.

mapper属性允许用户指定一个自定义的类通过Hbase结果对象来创建Solr文档。但这个mapper类必需实现com.ngdata.hbaseindexer.parse.ResultToSolrMapper接口。

By default, the built-in com.ngdata.hbaseindexer.parse.DefaultResultToSolrMapper is used.

默认情况,使用的是内署的com.ngdata.hbaseindexer.parse.DefaultResultToSolrMapper

unique-key-formatter

The unique-key-formatter attribute specifies the name of the class used to format HBase row keys (as well as column families and column qualifiers) as text. A textual representation of these pieces of information is needed for indexing in Solr, as all data in Solr is textual, but row keys, column families, and column qualifiers are byte arrays.

unique-key-formatter指定了用于格式化Hbase rowkeys(列簇和列限定符也一样)为文本的类名。在Solr中索引需要这些信息的文本表示,因为Solr中的所有数据都是文本数据,但是行键、列族和列限定符是字节数组。

A unique-key-formatter class must implement the com.ngdata.hbaseindexer.uniquekey.UniqueKeyFormatter interface.

一个unique-key-formatter类必须实现com.ngdata.hbaseindexer.uniquekey.UniqueKeyFormatter接口。

The default value of this attribute is com.ngdata.hbaseindexer.uniquekey.StringUniqueKeyFormatter. The StringUniqueKey formatter simply treats row keys and other byte arrays as strings.

这个属性的默认值是com.ngdata.hbaseindexer.uniquekey.StringUniqueKeyFormatter。StringUniqueKeyFormatter只是简单的把rowkey或者其他字节数据当成字符串。

If your row keys, column families, or qualifiers can’t simply be used as strings, consider using the com.ngdata.hbaseindexer.uniquekey.HexUniqueKeyFormatter.

如果你的rowkey,列簇,或者限定符不能简单的用字符串表示,就你需要考虑使用com.ngdata.hbaseindexer.uniquekey.HexUniqueKeyFormatter

unique-key-field

This attribute specifies the name of the document identifier field used in Solr.

这个属性指定Solr中文档的标识字段。

The default value for this field is “id”.

默认值是“id”。

row-field

The row-field attribute specifies the name of the Solr field to be used for storing an HBase row key.

row-field属性指定了Solr中用于存储Hbase rowkey的安段名。

This field is only important when doing column-based indexing. In order for the indexer to be able to delete all documents for a single row from the index, it needs to be able to find all documents for the row in Solr. When this attribute is populated in the indexer definition, it’s value is used as the name of a field in Solr to store the encoded row key.

这个字段对于基于列索引方式才很重要。索引器为了能够从索引中删除一行的所有文档,它一个字段能在Solr中找到该行的所有文档。在索引器定义中设置这个属性时,它的值将用作Solr中字段的名称,以存储编码的行键。

By default, this attribute is empty, meaning that the row key is not stored in Solr. The consequence of this is that deleting a complete row or complete column family in HBase will not delete the indexed documents in Solr.

默认情况,这个属性为空,这意味着rowkey不会被存储在Solr里面。这样的结果就是在Hbase中删除一个完整的行或者列并不删除Solr中的已经索引的文档。

column-family-field

The column-family-field specifies the name of the Solr field to be used for storing the HBase column family name.

column-family-field指定Solr中用于存储HBase列簇名的字段名。

See the description of the row-field attribute for more information.

查看row-field属性查看更多的信息。

By default, this attribute is empty, so the column-family name is not saved in Solr.

默认情况,这个属性为空,也就是说,列簇不会被Solr存储。

table-name-field

The table-name-field specifies the name of the Solr field to be used for storing the name of the HBase table where a record is stored.

table-name-field指定Solr中用于存储Hbase表名的字段名。

By default, this attribute is empty, so the name of the HBase table is not stored unless this setting is explicitly set in the indexer config.

默认情况,这个属性是空,也就是说Hbase的表名不会被存储除非在indexer节点中明确指定。

indxer内定义的节点(Elements within the indexer definition)

There are three types of elements that can be used within an indexer configuration: , , and .

在indexer节点有三种类型的节点:,

The field element defines a single field to be indexed in Solr, as well as where its contents are to be taken from and interpreted from HBase. There are typically one or more fields listed in an indexer configuration – one for each Solr field to be stored.

field节点定义了要在Solr中索引的单个字段,以及要从Hbase获取和解析的内容。索引器配置中通常列出一个或多个字段——每个Solr字段都要存储一个字段。

The field attribute has four attributes, listed below.

field有如下的四个属性。

name

The name attribute specifies the name of a Solr field in which to store data. A field with a matching name should be defined in the Solr schema.

name属性指定了Solr的中存储数据的字段名。这个字段需要在Solr的Schema中有匹配的字段名。

The name attribute is mandatory.

name属性是必须的。

value

The value attribute specifies the data to be used from HBase for populating the field in Solr. It takes the form of a column family name and qualifier, separated by a colon.

value属性指定了Hase用于填充Solr字段的数据。它采用列族名和限定符的形式,用冒号分隔。

The qualifier portion can end in an asterisk, which is interpreted as a wildcard. In this case, all matching column-family and qualifier expressions will be used.

限定符部分可以星号结尾,该星号被解释为通配符。在这种情况下,将使用所有匹配的列族表达式和限定符表达式。

The following are examples of valid value attributes:

以下是有效值属性的示例:

  • mycolumnfamily:myqualifier
  • mycolumnfamily:my*
  • mycolumnfamily:*

source

The source attribute determines what portion of an HBase KeyValue will be used as indexing content.

Source属性确定HBASE KeyValue的哪个部分将用作索引内容。

It has two possible values: value and qualifier.、

它有两个可能的值:value和qualifier。

When value is specified (which is the case by default), then the cell value is used as input for indexing.

当指定值时(默认情况下是这种情况),则使用单元格值作为索引的输入。

When qualifier is specified, then the column qualifier is used as input for indexing.

当指定限定符时,列限定符将用作索引的输入。

type

The type attribute defines the datatype of the content in HBase.

type属性定义HBASE中内容的数据类型。

Because all data is stored in HBase as byte arrays, but all content in Solr is indexed as text, a method for converting from byte arrays to the actual datatype is needed.

因为所有数据都以字节数组的形式存储在HBASE中,但是Solr中的所有内容都被索引为文本,所以需要一个方法将字节数组转换为实际的数据类型。

The value of this field can be one of any of the datatypes supported by the HBase Bytes class: int, long, string, boolean, float, double, short, or bigdecimal.

该字段的值可以是HBASE Bytes类支持的任何数据类型之一:int、long、string、boole、Float、Double、Short或Big十进制。

If the Bytes-based representation has not been used for storing data in HBase, the name of a custom class can be specified for this attribute. The custom class must implement the com.ngdata.hbaseindexer.parse.ByteArrayValueMapper interface.

如果没有使用基于Bytes的表示形式在HBASE中存储数据,则可以为该属性指定自定义类的名称。自定义类必须实现com.ngdata.hbaseindexer.parse.ByteArrayValueMapper接口。

The element defines a key-value pair that will be supplied to custom classes that implement the com.ngdata.hbaseindexer.Configurable interface.

节点定义了一个键值对,它将提供给实现com.ngdata.hbase indexer.Configable接口的自定义类。 elements can also be nested in a element. 元素也可以嵌套在元素中。

The element has two attributes: name and value. Both are mandatory.

访节点有两个属性:name和value。两者都是必须的。

配置样例(Example configuration)

The example configuration below demonstrates all elements and attributes that can be used to configure an indexer.

下面的示例配置演示了可用于配置索引器的所有元素和属性。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<!--
Do row-based indexing on table "table1", never re-reading updated content.
Store the unique document id in Solr field called "custom-id".
Additionally store the row key in a Solr field called "custom-row", and store the
column family in a Solr field called "custom-family".

Perform conversion of byte array keys using the class "com.mycompany.MyKeyFormatter".
-->
<indexer
table="table1"
mapping-type="row"
read-row="never"
unique-key-field="custom-id"
row-field="custom-row"
column-family-field="custom-family"
table-name-field="custom-table"
unique-key-formatter="com.mycompany.MyKeyFormatter"
>

<!-- A float-based field taken from any qualifier in the column family "colfam" -->
<field name="field1" value="colfam:*" source="qualifier" type="float"/>

<param name="globalKeyA" value="globalValueA"/>
<param name="globalKeyB" value="globalValueB"/>

</indexer>

参考

morphlines
morphlines-architecture

This page explains how to start doing basic indexing in HBase. Before following this tutorial, make sure that the HBase Indexer and other required software is installed and running as explained in the installation instructions.

这篇解释如何在Hbase中开始基础索引。在开始教程之前,请确保Hbase Indexer和其他需要的软件已经安装和运行。

At this point, HBase and Solr (in cloud mode) should be running, and the HBase Indexer should be unpacked in a directory (which we’ll call $INDEXER_HOME). For this tutorial, it is assumed that the default example index schema is being used by Solr (as explained on the installation page).

此时,Hbasa和Solr(云模式)已经行行,并且Hbase Indexer已经解压到一个目录中(这是我们称为$INDEXER_HOME)。在这个教程中,我们假设用的是Solr的默认example索引(就像安装中说的那样)。

启动Hbase Indexer(Start the HBase Indexer daemon)

In a terminal, execute the following (assuming $INDEXER_HOME points to the directory where the hbase-indexer tar.gz distribution was unpacked).

在终端中,运行如下命令(假定$INDEXER_HOME指向hbase-indexer tar.gz解压的目录)。

1
2
cd $INDEXER_HOME
./bin/hbase-indexer server

创建需要索引的表(Create a table to be indexed in HBase)

In the HBase shell, create a table. For this tutorial, we’ll create a table named “indexdemo-user”, with a single column family named “info”. Note that the REPLICATION_SCOPE of the column family of the table must be set to 1.

在Hbase shell,创建一个表。在这里,我们创建一个“indexdemo-user”的表,有一个“info”的列簇。注意列簇的REPLICATION_SCOPE必须设置成1。

1
2
$ hbase shell
hbase> create 'indexdemo-user', { NAME => 'info', REPLICATION_SCOPE => '1' }

添加索引器(Add an indexer)

Now we’ll create an indexer that will index the the indexdemo-user table as its contents are updated.

现在我们创建一个索引器,在indexdemo-user表的内容被更新是他会进行索引。

In your favourite text editor, create a new xml file called indexdemo-indexer.xml, with the following content:

用你喜欢的编辑器,创建一个新的xml文件,命名为indexdemo-indexer.xml,添加如下内容:

1
2
3
4
5
6
<?xml version="1.0"?>
<indexer table="indexdemo-user">
<field name="firstname_s" value="info:firstname"/>
<field name="lastname_s" value="info:lastname"/>
<field name="age_i" value="info:age" type="int"/>
</indexer>

The above file defines three pieces of information that will be used for indexing, how to interpret them, and how they will be stored in Solr.

上面的文件定义了三个索引字段的信息,如何解析,如何在Solr中存储。

Next, create an indexer based on the created indexer xml file.

接下来,基于xml文件创建一个索引器。

1
2
./bin/hbase-indexer add-indexer -n myindexer -c indexdemo-indexer.xml \
-cp solr.zk=localhost:2181/solr -cp solr.collection=collection1

Note that the above command assumes that ZooKeeper is running on localhost on port 2181, and that there is a Solr Core called “collection1” configured. If you are doing this tutorial on an existing HBase/Solr environment, you may need to use different settings.

注意上面的命令假设,ZooKeeper运行要本机的2181端口上,并且Solr Core已经创建了一个名为“collection1”的索引。如果你在一个现有的Hbase/Solr环境运行本教程,你需要修改配置。

更新表内容(Update the table content)

In the HBase shell, try adding some data to the indexdemo-user table
在Hbase shell中,尝试给indexdemo-user添加一些数据。

1
2
hbase> put 'indexdemo-user', 'row1', 'info:firstname', 'John'
hbase> put 'indexdemo-user', 'row1', 'info:lastname', 'Smith'

After adding this data, take a look in Solr (i.e. http://localhost:8983/solr/#/collection1/query). You should see a single document in Solr that has the firstname_s field set to “John”, and the lastname_s field set to “Smith”.

添加数据之后,来看一下Solr(i.e. http://localhost:8983/solr/#/collection1/quer),你应该能看到一个文档,这个文档的firstname_s字段值为“John”,同时lastname_s字段值为“Smith”。

Note If you don’t have autoCommit enabled in Solr, you won’t be able to see the updated contents immediately in Solr. The demo environment has autoCommit enabled for a commit every second.

注意如果没有开启autoCommit,你不会马上在Solr看到更新的内容。这例子的环境autoCommit已经开启并设置为每秒自动提交1次。

Now try updating the data you’ve just added

现在尝试更新你刚才添加的数据

1
hbase> put 'indexdemo-user', 'row1', 'info:firstname', 'Jim'

And now check the content in Solr. The document’s firstname_s field now contains the string “Jim”.

然后在Solr有检查内容。看下文档的firstname_s是不是变成了“Jim”

Finally, delete the row from HBase.

最后,删除Hbase的这条记录。

1
hbase> deleteall 'indexdemo-user', 'row1'

You can now verify that the data has been deleted from Solr.

你可以验证下Solr中的数据是不是已经删除了。

This page explains how to do a basic installation of the HBase Indexer on a single machine.

这篇会讲解如何在单机中进行Hbase Indexer的基础安装。

Before you start, make sure that you have the required software installed (they can all be running on single machine).

在开始之前,请确认你已经安装了所有需要的软件(他们可以都可以在单机运行)。

获取Hbase Indexer(Get the HBase Indexer)

Check out the code and build the tar.gz distribution.

签出代码并生成tar.gz的发布包。

1
2
git clone git://github.com/NGDATA/hbase-indexer.git
mvn clean package -Pdist -DskipTests

Next, unpackage the tar.gz distribution (in the example below it is unpacked under your $HOME directory).

接下来,解压tar.gz发布包(这个例子中,他被解压到$HOME目录)。

1
2
tar zxvf hbase-indexer-dist/target/hbase-indexer-1.0-SNAPSHOT.tar.gz -C ~
cd ~/hbase-indexer-1.0-SNAPSHOT

配置Hbase Indexer(Configure HBase Indexer)

In the hbase-indexer directory, edit the file conf/hbase-indexer-site.xml and configure the ZooKeeper connection string (twice, once for hbase-indexer, and once for hbase, alternatively you can copy your hbase-site.xmlto the conf directory).

hbase-indexer目录,编辑conf/hbase-indexer-site.xml 文件并配置ZooKeeper的连接串(两次,一次用于hbase-indexer,一次用于Hbase,或者你可以拷贝你的hbase-site.xml到你的conf目录)。

1
2
3
4
5
6
7
8
<property>
<name>hbaseindexer.zookeeper.connectstring</name>
<value>zookeeperhost</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>zookeeperhost</value>
</property>

If you have not defined JAVA_HOME globally, and the bin/hbase-indexer script would complain it doesn’t find you Java, you can set the JAVA_HOME in the script conf/hbase-indexer-env.sh.

如果你没有定义全局的JAVA_HOMEbin/hbase-indexer脚本会报没有找到Java,你可以通过运行conf/hbase-indexer-env.sh来设置JAVA_HOME

配置Hbase(Configure HBase)

In order to use the HBase Indexer, replication must be enabled in HBase. There are also a number of other HBase settings that can be set to optimize the working of the HBase indexer.

为了运行Hbase Indexer,复制集必须开启。同时还有一些HBase的设置需要配置以便优代Hbase Indexer的运行。

Add the settings below to your hbase-site.xml configuration on all HBase region servers, and restart HBase.
所有的分区服务上的hbase-site.xml添加如下配置,然后重启Hbase。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<configuration>
<!-- SEP is basically replication, so enable it -->
<property>
<name>hbase.replication</name>
<value>true</value>
</property>
<!-- Source ratio of 100% makes sure that each SEP consumer is actually
used (otherwise, some can sit idle, especially with small clusters) -->
<property>
<name>replication.source.ratio</name>
<value>1.0</value>
</property>
<!-- Maximum number of hlog entries to replicate in one go. If this is
large, and a consumer takes a while to process the events, the
HBase rpc call will time out. -->
<property>
<name>replication.source.nb.capacity</name>
<value>1000</value>
</property>
<!-- A custom replication source that fixes a few things and adds
some functionality (doesn't interfere with normal replication
usage). -->
<property>
<name>replication.replicationsource.implementation</name>
<value>com.ngdata.sep.impl.SepReplicationSource</value>
</property>
</configuration>

添加Indexer jar到HBase(Add indexer jars to HBase)

The HBase Indexer includes two jar files that need to be in the classpath of HBase. Copy these from the lib directory of the unpacked hbase-indexer installation into the lib directory of HBase for each region server.

Hbase Indexer包含两个jar文件需要在Hbase的类目录下。将解压目录hbase-indexer下的lib中的这些文件拷贝到所有Hbase分区服务器的lib目录。

1
cp lib/hbase-sep-* $HBASE_HOME/lib

启动Solr(Start Solr)

Ensure that Solr is running. In general, it’s easiest to have Solr use the same ZooKeeper instance as HBase.

确保Solr已经运行。通常,很容易让Hbase和Solr共用相同的ZooKeeper。

Assuming that you’ve downloaded Solr 4.2.0 and you’re running ZooKeeper on the current machine, you can start up the base Solr in cloud mode using the example schema as follows:

假设你已经下载了Solr 4.2.0并且ZooKeeper运行在当前机器,你可能通过下列脚本在云模式运行Solr。

1
2
cd $SOLR_HOME/example
java -Dbootstrap_confdir=./solr/collection1/conf -Dcollection.configName=myconf -DzkHost=localhost:2181/solr -jar start.jar

构建(Building the binary distribution)

Use the following command to build the binary distribution (.tar.gz & rpm):

使用如下命令构建生成二进制发布包(.tar.gz & rpm):

1
mvn -DskipTests -Pdist install

测试(Testing)

These steps assume a running HBase 0.94.x installation (preferably CDH 4.2), as well as a running Solr installation. For this example, the configured Solr schema will need to have a multi-valued field called “data”, as well as a unique key field called “id”.

以下这此步骤假定已经安装了Hbase 0.94.x(最好是CDH 4.2)和Solr。在这个例子中,Solr的映射,需要配置多值字段“data”和唯一键字段“id”。

  1. Enable replication and other settings that are outlined in the hbase-sep demo instructions

  2. hbase-sep demo instructions的配置复制集和其他设置。

  3. Unzip the binary distribution (instructions for creating the binary distribution are listed above).

  4. 解压发布包(生成发布包的方式已经在上文列出)。

    1
    $ tar zxvf hbase_indexer.tar.gz
  5. Copy the hbase-sep jar files from the lib directory of the binary distribution into the lib directory of HBase.

  6. 将发布包下的lib目录的hbase-sep jar文件拷贝到Hbase的lib目录。

    1
    2
    $ cd hbase_indexer
    $ sudo cp lib/hbase-sep-* /usr/lib/hbase/lib
  7. Create a table in HBase that has replication enabled. For this example, we’ll create a table called “record” with a single column family called ‘data’.

  8. 创建一个开启复制集功能的表。这个例子中,我们会创建“record”表,有一个列簇“data”。

    1
    hbase> create 'record', {NAME => 'data', REPLICATION_SCOPE => 1}
  9. Start the hbase-indexer server

  10. 启动hbase-indexer服务

    1
    $ ./bin/hbase-indexer server
  11. Create an indexer definition. For this example, we’ll just index anything in the data column family into the “data” field in Solr. Save the below contents in a file called ‘sample.xml’.

  12. 创建索引器定义。在这个例子中,我们只是把data列簇中所有内容都放到Solr的“data”字段中进行索引。将以下内容保存为”sample.xml”。

    1
    2
    3
    4
    <?xml version="1.0"?>
    <indexer table="record">
    <field name="data" value="data:*" type="string"/>
    </indexer>
  13. Add the indexer definition to the indexer server. The following command assumes that the Solr ZooKeeper is running on the current host, and the name of the collection to be used for indexing is “core0”.

  14. 把索引定义添加到inderxer服务中。下面的命令假设Solr ZooKeeper运行在当前的主机中,并且用于索引的集合名为“core0”。

    1
    $ ./bin/hbase-indexer add-indexer  -n sampleindex -c sample.xml --cp solr.collection=core0 
  15. Add some data to the record table in HBase. The data added to the data column family in the record table should show up in the Solr index.

  16. 向Hbase的recode表添加一些数据。添加到record表中的数据应该会出现在Solr的索引中。

    1
    hbase> put 'record', 'row1', 'data:value', 'Test of HBase Indexer'

The following software is required for running the HBase Indexer:

运行Hbase Indexer需要下面的这些软件:

  • HBase 0.94.x
  • Solr 4.x in cloud mode
  • ZooKeeper 3.x (required by the two above packages)

All components can be run on a single machine, or they can be run on multiple machines on a cluster.

所有的组件可以运行在单机,也可运行在多台机器的集群上。

详情(Details)

HBase

HBase 0.94.x is the supported version of HBase for the HBase Indexer. It is recommended to use the version of HBase 0.94.2 that is bundled with Cloudera CDH 4.2. However, other versions of HBase 0.94.x may also work. CDH 4.2 is currently used for testing.

Hbase 0.94.x是Hbase Indexer支持的版本。推荐使用Cloudera CDH 4.2附带的HBase 0.94.2版本。尽管,其他的0.94.x版本也能正常工作,但CDH 4.2被用于当前的测试。

HBase should be configured to use HDFS as its filesystem – HBase Indexer is not fully functional if the local filesystem implementation is used instead of HDFS.

Hbase要配置HDFS做为它的文件系统,如果使用本地文件系统而不是HDFS,HBase Indexer就不行完全运行了。

Solr

Solr 4.x is required for the HBase Indexer, and it must be configured to run in cloud mode. Solr 4.2.0 is currently used for development testing.

Hbase Indexer 需要Solr 4.x版本,并且要求配置在云模式下运行。Solr 4.2.0是当并开发测试的版本。

ZooKeeper

It is recommended that the version of ZooKeeper that is bundled in CDH 4.2 is used.

推荐使用和CDH4.2附带的ZooKeeper版本。

简介(Introduction)

The HBase Indexer project provides indexing (via Solr) for content stored in HBase. It provides a flexible and extensible way of defining indexing rules, and is designed to scale.

Hbase Indexer项目可以为存储在HBase中的内容提供Solr索引。它提供灵活的可扩展的方式来定义索引规则,且为大规模而生。

Indexing is performed asynchronously, so it does not impact write throughput on HBase. SolrCloud is used for storing the actual index in order to ensure scalability of the indexing.

索引是异步的,所以不会影响Hbase的写入吞吐量。SolrCloud用于存储实际的索引,以确保索引的可伸缩性。

开始使用Hbase Indexer(Getting started with the HBase Indexer)

  1. Make sure you’ve got the required software installed, as detailed on the Requirements page.

  2. Follow the Tutorial to get a feel for how to use the HBase Indexer.

  3. Customize your indexing setup as needed using the other reference documentation provided here.

  4. 确认所有要求的软件已经安装,具体内容在[要求]页。

  5. 按照教程来体验下如何使用Hbase Indexer。

  6. 通过提供的文档来调整索引的配置。

工作原理(How it works)

The HBase Indexer works by acting as an HBase replication sink. As updates are written to HBase region servers, they are “replicated” asynchronously to the HBase Indexer processes.

Hbase Indxer扮演了Hbase复制集的角色。当数据写入Hbase的分区时,数据被异步的“复制”给Hbase Indexer处理器。

The indexer analyzes incoming HBase mutation events, and where applicable it creates Solr documents and pushes them to SolrCloud servers.

Hbase Indexer分析从Hbase发送过来的变化事件,当合适的时候创建Solr文档并发送给SolrCloud服务器。

The indexed documents in Solr contain enough information to uniquely identify the HBase row that they are based on, allowing you to use Solr to search for content that is stored in HBase.

Solr文档维护了足够多的信息用于唯一标识一条Hbase记录,这样允许你可能通过Solr来检索Hbase内容。

HBase replication is based on reading the HBase log files, which are the precise source of truth of the what is stored in HBase: there are no missing or no extra events. In various cases, the log also contains all the information needed to index, so that no expensive random-read on HBase is necessary (see the read-rowattribute in the Indexer Configuration).

HBase复制集是通过读取Hbase的日志文件,这些日志文件是HBASE中存储内容的精确来源:没有遗漏也没有额外的事件。在大多数情况下,日志含了索引需要的全部信息,因此不需要对Hbase进行昂贵的随机读取。(在[Indexer配置]中可查看read-row属性)。

HBase replication delivers (small) batches of events. HBase-indexer exploits this by avoiding double-indexing of the same row if it would have been updated twice in a short time frame, and as well will batch/buffer the updates towards Solr, which gives important performance gains. The updates are applied to Solr before confirming the processing of the events to HBase, so that no event loss is possible.

Hbase复制集(小规模)批量分发事件。Hbase indexer利用这一特性用于避免在一个很小的时间窗口期一条记录被更新两次而引起重复索引,也通过批量/缓存的方式来更新Solr,这样可以获得更好的性能。所有的更新会在Hbase处理确认之前更新到Solr中,因此不会出现丢失数据的情况。

横向扩展(Horizontal scalability)

All information about indexers is stored in ZooKeeper. New indexer hosts can always be added to a cluster, in the same way that HBase regionservers can be added to to an HBase cluster.

所有的索引信息都是保存在ZooKeeper中的。新的Indexer主机可以被添加为一个集群中,就像Hbase的分区服务器被添加到Hbase集群一样。

All indexing work for a single configured indexer is shared over all machines in the cluster. In this way, adding additional indexer nodes allows horizontal scaling.

同一索引配置的所有索引工作被分配给集群中的所有机器。这样说来,添加额外的索引节点就可以横向扩展。

自动的错误处理(Automatic failure handling)

The HBase replication system upon which the HBase Indexer is based is designed to handle hardware failures. Because the HBase Indexer is based on this system, it also benefits from the same ability to handle failures.

Hbase复制集系统为硬件错误处理做了设计。Hbase Indexer其于此系统,因此也从中获得了错误处理的能力。

In general, indexing nodes going down or Solr nodes going down will not result in any lost data in the HBase Indexer.

通常情况,索引节点或者Solr宕机不会导致Hbase Indexer中的数据丢失。

背景

公司使用Hbase indexer做二级索引,最近在做数据统计时发现,数据存在有缺失的情况。在网上查找时发现可能是Hbase Indexer的一个BUG,详情看这里。大意是说修改read-row=”never”或者修改源码。我们使用的组件不是完全开源的Hbase Indexer,有被提供商做了部分调整,为了保险起见,自己还是做了一次测试。同时也是进一步了解Hbase和Habse Indexer的机会。

验证方案

  1. 把ES的qc索引做为数据来源,数据量比较大
  2. 写测试程序从ES拉数据,100万条。
  3. 调整不同的read-row方式
  4. 修改程序验证部分更新。

    验证准备

    创建Hbase表

    1
    create 'qc',{NAME =>'d', REPLICATION_SCOPE =>1}
    此处需要,注意设置REPLICATION_SCOPE为1,第一次验证时未开启。如果未开启的情况,可以进行如下操作:
    1
    2
    3
    disable 'qc'
    alter 'qc',{NAME =>'d', REPLICATION_SCOPE =>1}
    enable 'qc'

    配置Hbase Indexer

    之前已经有配置,拷贝一份及可
    1
    2
    3
    cd  /opt/morphline_config
    cp -a xyz.xml qc.xml
    cp -a xyz.conf qc.conf

修改qc.xml

1
2
3
4
5
<indexer table="qc" unique-key-field="rowkey"
unique-key-formatter="com.ngdata.hbaseindexer.uniquekey.StringUniqueKeyFormatter"
mapper="com.ngdata.hbaseindexer.morphline.MorphlineResultToSolrMapper" read-row="never">
<param name="morphlineFile" value="/opt/morphline_config/qc.conf" />
</indexer>

修改qc.conf

可以把文件下载回来修改

1
sz qc.conf

通过’rz’可以上传修改后的配置文件。

调整后的qc.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
morphlines : [
{
id : morphline1
importCommands : ["org.kitesdk.morphline.**", "com.ngdata.**"]

commands : [
{
extractHBaseCells {
mappings : [
{
inputColumn : "d:_id"
outputField : "_id"
type : string
isAllowEmpty : true
source : value
},
{
inputColumn : "d:code"
outputField : "code"
type : string
isAllowEmpty : true
source : value
},
{
inputColumn : "d:errorCode"
outputField : "errorCode"
type : string
isAllowEmpty : true
source : value
},
{
inputColumn : "d:errorMsg"
outputField : "errorMsg"
type : string
isAllowEmpty : true
source : value
},
{
inputColumn : "d:eventNo"
outputField : "eventNo"
type : string
isAllowEmpty : true
source : value
},
{
inputColumn : "d:eventTime"
outputField : "eventTime"
type : string
isAllowEmpty : true
source : value
},
{
inputColumn : "d:orgCode"
outputField : "orgCode"
type : string
isAllowEmpty : true
source : value
},
{
inputColumn : "d:patientId"
outputField : "patientId"
type : string
isAllowEmpty : true
source : value
},
{
inputColumn : "d:receiveTime"
outputField : "receiveTime"
type : string
isAllowEmpty : true
source : value
},
{
inputColumn : "d:rowKey"
outputField : "rowKey"
type : string
isAllowEmpty : true
source : value
},
{
inputColumn : "d:table"
outputField : "table"
type : string
isAllowEmpty : true
source : value
},
{
inputColumn : "d:value"
outputField : "value"
type : string
isAllowEmpty : true
source : value
},
{
inputColumn : "d:version"
outputField : "version"
type : string
isAllowEmpty : true
source : value
}
]
}
}

{ logTrace { format : "output record: {}", args : ["@{}"] } }
]
}
]

添加映射

1
hbase-indexer add-indexer -c qc.xml -n qc -z node1,node3,node2  -cp solr.zk=node1:2181,node3:2181,node2:2181/solr -cp solr.collection=qc

检查配置是否生效

1
hbase-indexer list-indexers -dump

删除映射

如果配置没有生效的情况,最好先删掉映射后重新添加。

1
hbase-indexer delete-indexer --name 'qc'

重新拉取Hbase数据

1
nohup hadoop jar /opt/hbase-indexer/latest/tools/hbase-indexer-mr-1.6-ngdata-job.jar  --conf /etc/hbase/conf/hbase-site.xml -D 'mapred.child.java.opts=-Xmx500m' --hbase-indexer-file /opt/morphline_config/qc.xml --zk-host node1/solr --collection qc  --reduce 0 &

配置Solr

修改配置

之前有配置的,可直接拷贝一份开始配置

1
2
cd /root
cp -a xyz qc

修改后的scheme.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xmlversion="1.0"encoding="UTF-8"standalone="no"?>
<schemaname="qc"version="1.5">
<field indexed="true" name="_version_" stored="true" type="long"/>
<field indexed="true"name="_root_"stored="false" type="string"/>
<field indexed="true"multiValued="false"name="_id"stored="true" type="string"/>
<field indexed="true" multiValued="false" name="rowkey" stored="true" type="string"/>
<field indexed="true" name="code" stored="false" type="string"/>
<field indexed="true" name="errorCode" stored="true" type="string"/>
<field indexed="true" name="errorMsg" stored="true" type="string"/>
<field indexed="true" name="eventNo" stored="true" type="string"/>
<field indexed="true" name="eventTime" stored="true" type="string"/>
<field indexed="true" name="orgCode" stored="true" type="string"/>
<field indexed="true" name="patientId" stored="true" type="string"/>
<field indexed="true" name="receiveTime" stored="false" type="string"/>
<field indexed="true" name="rowKey" stored="true" type="string"/>
<field indexed="true" name="table" stored="true" type="string"/>
<field indexed="true" name="value" stored="true" type="string"/>
<field indexed="true" name="version" stored="true" type="string"/>
<uniqueKey>rowkey</uniqueKey>
</schema>

此处注意配置rowkey字段,之前一就因为rowkey没有导致创建索引失败

上传配置

1
/opt/solr/latest/server/scripts/cloud-scripts/zkcli.sh -zkhost node1:2181/solr -cmd upconfig --confdir /root/qc/conf/ --confname qc

创建索引

1
/opt/solr/latest/bin/solr create_collection -c qc -d /root/qc/conf/ -n qc

修改ES配置

拉取测试数据时,提示只有10000的窗口数据,需要设计max_result_window,修改方法如下:

1
2
3
4
curl -XPOST 'http://xx:9200/qc/_close'
curl -XPUT 'http://xx:9200/qc/_settings?preserve_existing=true' -d '{"max_result_window" : "1000000"}'
curl -XGET 'http://xx:9200/qc/_settings?preserve_existing=true'
curl -XPOST 'http://xx:9200/qc/_open'

测试

read-row为never

  1. 测试数据为100万条,全量数据更新。
    数据测试,导入数据时出现服务连接问题,中间出现Hbase Indexer异常停止,重启后,数据能对上。
  2. 测试数据为100万条,部分数据更新。
    数据字段出现丢失情况,
  3. 验证配置字段顺序问题。

    清理Hbase数据

    1
    truncate 'qc'

    清理Solr数据

    1
    2
    hdfs dfs -rm -r /solr/qc
    hdfs dfs -ls /solr
    验证的情况,与配置文件的顺序无关

验证重跑MapRedurce

删除solr中qc的记录

1
2
<delete><query>*:*</query></delete>
<commit/>

重跑

1
nohup hadoop jar /opt/hbase-indexer/latest/tools/hbase-indexer-mr-1.6-ngdata-job.jar  --conf /etc/hbase/conf/hbase-site.xml -D 'mapred.child.java.opts=-Xmx500m' --hbase-indexer-file /opt/morphline_config/qc.xml --zk-host node1/solr --collection qc  --reduce 0 &

测试时发现可以正常拉取数据,正式线发现不能拉取到之前遗漏的数据。

解决方案

  1. 修改read-row为never
  2. 重新检查写入Hbase相关代码,确保数据是整条记录更新(即需要合并旧数据的方式进行更新)

注意事项,采用read-row为never时,只会从WAL中获取数据去更新Solr,也就是说如果,数据只更新部分,Solr也只会有最后更新的那部分数据。
3. 通过写程序将缺失数据提取出来重新更新Hbase,该工作已让郑维协助处理,保持跟进。

参考链接

Lily HBase Indexer同步HBase二级索引到Solr丢失数据的问题分析

使用Notepad++有挺长一段时间了。因为打开速度快,经常会用它来编绎有一些小文本,或者文件的格式化。在一次升级后发现Json Viwer插件不见了。
当时也没太在意,换了一台电脑用了。最近因为查问题需要格式化的JSON也多了起来,就想查查到底是怎么回事,顺便记录下处理方式。

网上一搜还有不少碰到这个问题的人notepad++64位添加Plugin Manager。大意是64位已经不提供plugin manager了。可以通过https://github.com/bruderstein/nppPluginManager/releases下载Plugin Manager。下载之后,用覆盖的方式粘贴plugins和updater文件夹,重新启动就可以。

启动之后提示,32位Notepad++不能运行64位插件。索性重新下载了个新版本的Notepad++64位,plugin manager已经改名为Plugin Admin了。下载我自己需要的插件,一切正常。