hbase中的資料儲存架構與格式 (2)

(問題) 
hbase中資料如何儲存的?
(2) HFile的資料格式?

(方法)
HFile是hbase中硬碟資料真實儲存的型態,
在hbase 0.94版本中, 使用的是HFile V2的格式,
不同於0.92版本(HFile V1)的格式,
擴展了資料的儲存欄位與編目的方式.


在HFile V2中, 仍然以key-value做為資料結構設計的核心,
HFile的組成分成四部分:
分別是Scanned Block (Data Block), Non-Scanned block (META Block), Load-on-open以及trailer.


當對hbase進行一次資料操作時,
將產生一筆key-value的資料, 其中,
key包含了用以標示資料位置的: row, columnfamily, columnqualifier,
以及關於操作資訊的標記: timestamp, keytype (操作種類: put, delete...)

這些資訊將被儲存於Data Block中,
然而, 當hbase進行資料處理時, 卻是從trailer開始讀起,
Trailer field中包含了以下資訊:

BlockType: block類型
FileInfoOffset: fileInfo的起始偏移位址
LoadOnOpenDataOffset: 需要被載入到記憶體中的Hfile部分的起始位址
DataIndexEntriesNum: data index的root index chunk包含的index entry數目
UncompressedDataIndexSize: 所有的未經壓縮的data index的大小
TmetaIndexEntriesNum: meta index entry的數目
totalUncompressedBytes: key value對象未經壓縮的總大小
numEntries: key value物件的數目
compressionCodec: 編解碼演算法
numDataIndexLeves: data block的index level
firstDataBlockOffset: 第一個data block的起始偏移位址, Scan操作的起始
lastDataBlockOffset: 最後一個data block的之後的第一個byte位址, 記錄scan的邊界
version:版本號

一般來說, 讀完trailer接下來將根據FileInfoOffset的數值,
跳到Load-on-open的資料區段, 繼續讀取HFile,
Load-on-open中的資料是當RegionServer啟動時要被加載到記憶體中的資訊,
包括FileInfo, Bloom filter block, data block index和meta block index.

在HFile V2版本中, 支援兩種不同的編目(index)方式,
也就是root index和non-root index,
root index是單層(single-level)的編目, 並會把資料存放至內存,
non-root index是多層(multi-level)的編目方式, 支援二分搜尋方法,
其中, 這裡的編目指的都是對於DataBlock進行,
而一個DataBlock可以對應於多個key-value的資訊.

最後是關於bloom filter(布隆濾波器),
bloom filter透過hash function的計算,
產生出一些0和1的集合, 根據集合和原始數據的映射關係,
bloom filter幫助快速查詢所要的資料是否存在於該Region中,
這裡並沒有對於使用的演算法進行詳細閱讀,
有興趣可以參考以下文章:
http://archive.cloudera.com/cdh/3/hbase-0.90.1-cdh3u0/blooms.html
http://blog.csdn.net/mrtitan/article/details/8445385

參考資料:
http://hbase.apache.org/0.94/apidocs/org/apache/hadoop/hbase/HServerLoad.RegionLoad.html
http://my.oschina.net/zhengyang841117/blog/188723
http://blog.cloudera.com/blog/2012/06/hbase-io-hfile-input-output/
http://www.larsgeorge.com/2009/10/hbase-architecture-101-storage.html
http://duanple.blog.163.com/blog/static/709717672011916103311428/
http://www.binospace.com/index.php/hfile-file-format-to-read-and-write-with-hbase/

留言

熱門文章

LTE筆記: RSRP, RSSI and RSRQ

[WiFi] WiFi 網路的識別: BSS, ESS, SSID, ESSID, BSSID

LTE筆記: 波束成型 (beamforming) 和天線陣列