Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

HBASE secondary index

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

HBASE implements second-level Index based on coprocessor

The scenario is as follows: store UC_TWEETS table, ROWKEY design: folderId_dayId_siteId_docId, export has the following requirements: export according to campaignId, so you need to store the index table of campaignId

The implementation steps are as follows:

First, the code is implemented as follows:

Public class HbaseCoprocessor extends BaseRegionObserver {

@ Override

Public void prePut (final ObserverContext e, final Put put

Final WALEdit edit, final Durability durability) throws IOException {

Configuration configuration = HBaseConfiguration.create ()

Configuration.set ("hbase.regionserver.lease.period", "900000")

Configuration.set ("hbase.rpc.timeout", "1800000")

Configuration.set ("hbase.client.scanner.timeout.period", "1800000")

Configuration.set ("hbase.zookeeper.property.clientPort", "2181")

Configuration.set ("hbase.zookeeper.quorum", "DEV-HADOOP-01,DEV-HADOOP-02,DEV-HADOOP-03")

Configuration.set ("hbase.master", "DEV-HADOOP-01:60000")

HTable table = new HTable (configuration, "UC_INDEX")

List kv = put.get ("F1" .getBytes (), "campaignId" .getBytes ())

Iterator kvItor = kv.iterator ()

While (kvItor.hasNext ()) {

KeyValue tmp = (KeyValue) kvItor.next ()

String rowkey = new String (tmp.getRow ())

String value = new String (tmp.getValue ())

String newRowkey = value + "_" + rowkey

Put indexPut = new Put (newRowkey.getBytes ())

IndexPut.add ("F1" .getBytes (), tmp.getQualifier (), tmp.getValue ())

Table.put (indexPut)

}

Table.close ()

}

}

Second, export the above HbaseCoprocessor class. Select Export-> Jar File to export to a ucTweet.jar file

Third, upload the ucTweet.jar file to HDFS with the following command:. / hadoop fs-put / data/server/ucTweet_index.jar / jars

4. Set the coprocessor attribute of the UC_TWEETS table. The command is as follows: alter 'UC_TWEETS',METHOD= >' table_att','coprocessor'= > 'hdfs://192.168.9.110:9000/jars/ucTweet.jar | com.prime.dsc.inputservice.coprocessor.HbaseCoprocessor | 1001 |'

Fifth, insert the data into the UC_TWEETS table. If the UC_INDEX table also has data and conforms to the design, the secondary index is established successfully.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report