HBase system Architecture diagram
Constituent Parts Description
Client:
Communicating with Hmaster and hregionserver using the hbase RPC mechanism
Client communicates with Hmaster to manage class operations
Client and Hregionserver data read and write class operation
Zookeeper:
Zookeeper Quorum storage-root-table address, Hmaster address
Hregionserver the Ephedral way to zookeeper, Hmaster feel the health of each hregionserver at any time
Zookeeper avoid hmaster single point problem
Hmaster:
Hmaster there is no single point of issue, HBase can start multiple hmaster, through the zookeeper Master election mechanism to ensure that there is always a master running
Mainly responsible for the management of table and region:
1 Manage users to change the table and delete the operation
2 Manage Hregionserver load Balancing, adjust region distribution
3 Region split, responsible for the distribution of the new region
4 after Hregionserver outage, responsible for failure hregionserver on region migration
Hregionserver:
The most core module in HBase, primarily responsible for responding to user I/O requests and reading and writing data to the HDFs file system
Hregionserver manages some column hregion objects;
Each hregion corresponds to a region,hregion in table consisting of multiple hstore;
Each hstore corresponds to the storage of a column family in the table;
Column family is a centralized storage unit, so it is more efficient to put a column with the same IO characteristics in a column family
Hstore:
The core of hbase storage. Made up of Memstore and StoreFile.
Memstore is sorted Memory Buffer. The process by which a user writes data:
Client write-to-memstore, until Memstore full, flush into a storefile, until it grows to a certain threshold, trigger compact merge operations Multiple StoreFile merged into one storefile, simultaneous version merging and data deletion, when the Storefiles compact is gradually formed, the larger StoreFile-a single storefile size exceeds a certain threshold value, Trigger split operation, the current region split into 2 region,region will be offline, the new split out of the 2 children region will be hmaster assigned to the corresponding hregionserver, The pressure of the original 1 region was diverted to 2 region.
As a result of this process, hbase only adds data, and the resulting update and delete operations are all done in the compact phase, so the user writes only need to go into memory to return immediately, thus ensuring I/O is high performance.
HLog
introduced HLog reason:
in a distributed system environment, there is no way to avoid system errors or downtime, and once hregionserver exits unexpectedly, Memstore memory data will be lost, the introduction of Hlog is to prevent this situation
working mechanism:
There is a Hregionserver object in each Hlog, Hlog is a class that implements the write Ahead log , each time a user action is written to Memstore, a copy of the data to the Hlog file is written, the Hlog file periodically scrolls out of the new file and deletes the old one (data that has persisted to the storefile). When the hregionserver unexpected termination, hmaster through zookeeper sense, hmaster first processing the legacy hlog files, the different region of the log data split, respectively, placed in the corresponding region directory, Then redistribute the failed region, pick up the hregionserver of these region in the process of load region, will find that there is a history hlog need to deal with, so will replay Hlog data into Memstore, Then flush to Storefiles to complete the data recovery.
hbase Storage Format
All data files in HBase are stored on the Hadoop HDFs file system in two main formats:
1 hfile hbase keyvalue data storage format, hfile is a hadoop binary format file, in fact StoreFile is the hfile to do a lightweight packaging, that is storefile the bottom is hfile
2 HLog file,hbase in the storage format of the Wal (Write Ahead Log), which is physically the sequence File of Hadoop
hfile
Picture explanation:
The hfile file is variable length, with fixed lengths of only two blocks: trailer and FileInfo
Trailer The pointer points to the starting point of the other data block
Some meta information for files is recorded in file info, for example: Avg_key_len, Avg_value_len, Last_key, COMPARATOR, Max_seq_id_key, etc.
The data index and Meta index blocks record the starting point for each data block and meta block
The Data block is the basic unit of HBase I/O, and in order to improve efficiency, there is an LRU-based block cache mechanism in Hregionserver
The size of each data block can be specified by parameter when creating a table, large block facilitates sequential scan, small block for random query
Each data block in addition to the beginning of the magic is a keyvalue pairs of stitching, magic content is some random numbers, the purpose is to prevent data corruption
Each keyvalue pair inside the hfile is a simple byte array. This byte array contains many items and has a fixed structure.
Keylength and Valuelength: Two fixed lengths representing the length of key and value, respectively
Key part: Row length is a fixed-length value, indicating the length of the Rowkey, row is Rowkey
Column Family length is a fixed-length value that represents the lengths of the Family
Then the column Family, then the qualifier, then the two fixed-length values representing the time stamp and key Type (Put/delete)
The value section does not have such a complex structure, that is, pure binary data
HLog File
The Hlog file is an ordinary Hadoop Sequence file,sequence The key is the Hlogkey object, the Hlogkey records the attribution information written to the data, in addition to table and region names, but also includes Sequence number and Timestamp,timestamp are "write Time", the starting value of sequence is 0, or the last time the file system was deposited in sequence.
The value of HLog sequece file is the KeyValue object of HBase, which corresponds to KeyValue in hfile
Concluding remarks: This article is I specifically on the internet to get down, is the hbase part of the ultimate article bar, my server source series also to be based on this order to carry out.
HBase Learning (16) system architecture diagram