HBase is a Hadoop database that provides random, real-time read/write access to big data. It is an open-source, distributed, multi-version, column-oriented, and storage model.
I will first explain the overall structure of HBase, for example:
HBase Master is the Server responsible for managing all the HRegion servers. HBase Master does not store any data on HBase servers. HBase logical tables may be divided into multiple HRegion and stored in the HRegion Server group, HBase Master Server stores the ing from data to HRegion Server.
One machine can only run one HRegion server, and data operations are recorded in Hlog. When reading data, HRegion first accesses the Hmemcache cache. If there is no data in the cache, it returns to the Hstore for retrieval, no column has an Hstore set. Each Hstore set contains many specific HstoreFile files. These files are in the B-tree structure and can be read quickly.
Let's look at the physical views of HBase data as follows:
| Row Key |
Timestamp |
Column Family |
| URI |
Parser |
| R1 |
T3 |
Url = http://www.taobao.com |
Title = daily specials |
| T2 |
Host = taobao.com |
|
| T1 |
|
|
| R2 |
T5 |
Url = http://www.alibaba.com |
Content = every day... |
| T4 |
Host = alibaba.com |
|
ØRow Key: the Row Key, the primary Key of the Table. Records in the Table are sorted by Row Key.
ØTimestamp: The Timestamp corresponding to each data operation. It can be viewed as the version number of the data.
ØColumn Family: A Column cluster. The Table is composed of one or more Column families in the horizontal direction. A Column Family can contain any number of columns, that is, Column Family supports dynamic expansion, you do not need to define the number and type of columns in advance. All columns are stored in binary format. You need to perform type conversion on your own.
I understand the HBase architecture and HBase data view. Now let's take a look at how to operate HBase data through Java!
Let's talk about the specific API first, as follows:
HBaseConfigurationIs the object used by every hbase client, which representsIs HBase configuration information. It has two constructor methods:
Public HBaseConfiguration ()
Public HBaseConfiguration (final Configuration c)
The default constructor attempts to read the configuration from the hbase-default.xml and hbase-site.xml. If classpath does not have these two files, you need to configure them yourself.
Configuration HBASE_CONFIG = new Configuration ();
HBASE_CONFIG.set ("hbase. zookeeper. quorum", "zkServer ");
HBASE_CONFIG.set ("hbase. zookeeper. property. clientPort", "2181 ″);
HBaseConfiguration cfg = new HBaseConfiguration (HBASE_CONFIG );