HBase Authoritative Guide Client API Foundation Summary notes (unfinished)

Source: Internet
Author: User

Client API: Basic

The primary client interface for HBase is provided by the Htable class in the Org.apache.hadoop.hbase.client package, which allows users to complete operations such as storing and retrieving data to hbase, and deleting invalid data.

Client read operations are typically not affected by the client side of other modified data under normal load and under regular operation because the conflicts between them are negligible. However, the problem arises when the client is allowed to modify the same row of data at the same time. Therefore, users should try to use bulk processing (batch) updates to reduce the number of times a single row of data is manipulated. (If the system is real-time, you need to add the Synchronized keyword)

  there is a cost to creating an htable instance. Each instance needs to be scanned. Meta table to check if the table exists, is available, and to perform some other operations that cause the instance invocation to be time consuming, so it is recommended that users create only one htable instance (just like creating an instance in Hadoop's setup), For subsequent MapReduce calls, eventually close in cleanup)

To insert data into HBase example:

 Packagehbasetest;Importorg.apache.hadoop.conf.Configuration;Importorg.apache.hadoop.hbase.HBaseConfiguration;ImportOrg.apache.hadoop.hbase.client.Get;Importorg.apache.hadoop.hbase.client.HTable;ImportOrg.apache.hadoop.hbase.client.Put;ImportOrg.apache.hadoop.hbase.client.Result;Importorg.apache.hadoop.hbase.util.Bytes;Importjava.io.IOException;/*** Created by Root on 5/27/16.*/ Public classPutexample { Public Static voidMain (string[] args) {//Load configuration fileConfiguration conf =hbaseconfiguration.create (); htable Table=NULL; Try {           //Create a Htable objectTable =NewHtable (conf, "practice"); //Set RowkeyPut put =NewPut (Bytes.tobytes ("RowKeyNum1")); //set the column family to write to, column and value
       Put.add (bytes.tobytes ("F1"), Bytes.tobytes ("Cardno"), Bytes.tobytes ("123456789")); Table.put (Put); //Get RowkeyGet result =NewGet ("RowKeyNum1". GetBytes ()); //Place the acquired value into the result of HBaseResult rs =table.get (Result); //gets the value of the column of the specified column familyString Cardno = bytes.tostring (Rs.getvalue ("F1". GetBytes (), "Cardno". GetBytes ())); System.out.println ("---cardno---" +Cardno); } Catch(IOException e) {e.printstacktrace (); } }}

  The data and coordinates are stored in the form of Java byte[] , which is stored as a byte array. The purpose of this underlying storage type is to allow any type of data to be stored and to effectively store only the required bytes, which guarantees minimal internal data structure overhead . Another reason is that each byte array has a offerset parameter and a length parameter, which allows the user to commit an existing byte array and perform a highly efficient byte-level operation .

Write Buffers for clients

Each put operation is actually an RPC operation that transfers the client data to the server and then returns. this is only appropriate for small data volumes , and if an application needs to store thousands of rows of data per second into the HBase table, this is not a good deal. (Typically, it takes about 1 milliseconds in a LAN network, which means that only 1000 RPC round-trip responses can be completed in a 1-second period.) )

The HBase API is equipped with a write buffer for the client, which collects the put operation and then calls the RPC operation to send the put to the server at once. (By default, the client buffer is disabled, and you can activate the buffer by setting the auto-brush-write AutoFlush to False )

New Htable (conf, "practice"); Table.setautoflush (false);

The size of the client write buffer is 2MB by default, and if you need to store large data, you can add a larger preset to the Hbase-site.xml configuration file in order to avoid modifying the buffer size each time the instance is created.

<property>        <name>hbase.client.write.buffer</name>        <value>20971520</value ></property>

This will increase the buffer size to 20MB, size can be based on the amount of data such as reference settings.

Forced brush write data can be called table.flushcommits (); directly generates an RPC request.

Attention:

  The client buffer is a simple list that is saved in the client process memory , and the user needs to be aware that the program cannot be terminated at run time, and if this happens, the data that has not been brushed will be lost and the server will not be able to receive the data, so no copy of the data can be used for data recovery.

Also note that a larger buffer requires more memory to be consumed by the client and server side, so the server side also needs to write the data to the server to consume more memory, because the server side also needs to write the data to the server's write buffer before processing it. Estimating server-side memory consumption can be multiplied by Hbase.regionserver.handle.count times the number of region servers using Hbase.client.write.buffer.

If the user only stores large cells, the client buffers do not work because the transfer time takes up most of the request time.

HBase Authoritative Guide Client API Foundation Summary notes (unfinished)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.