Region Splitting 過程

官方文檔:http://hbase.apache.org/book.html#regionserver_splitting_implementation

這裏寫圖片描述

  1. The RegionServer decides locally to split the region, and prepares the split. THE SPLIT TRANSACTION IS STARTED. As a first step, the RegionServer acquires a shared read lock on the table to prevent schema modifications during the splitting process. Then it creates a znode in zookeeper under /hbase/region-in-transition/region-name, and sets the znode’s state to SPLITTING.

    RegionServer決定本地分割region,THE SPLIT TRANSACTION IS STARTED。RegionServer首先在要進行region split的table上獲得一個共享的讀文件鎖,避免table的schema在region分割期間被修改。然後在Zookeeper中創建一個znode,/hbase/region-in-transition/region-name,並將該znode狀態設置爲SPLITTING。

  2. The Master learns about this znode, since it has a watcher for the parent region-in-transition znode.

    Master通過監視/hbase/region-in-transition這個znode獲得/hbase/region-in-transition/region-name的狀態信息。

  3. The RegionServer creates a sub-directory named .splits under the parent’s region directory in HDFS.

    RegionServer在HDFS中parent的目錄中創建.splits子目錄。

  4. The RegionServer closes the parent region and marks the region as offline in its local data structures. THE SPLITTING REGION IS NOW OFFLINE. At this point, client requests coming to the parent region will throw NotServingRegionException. The client will retry with some backoff. The closing region is flushed.

    RegionServer關閉parent region並且標記該region下線。在當前時刻,客戶端對parent region的請求會拋出NotServingRegionException。

  5. The RegionServer creates region directories under the .splits directory, for daughter regions A and B, and creates necessary data structures. Then it splits the store files, in the sense that it creates two Reference files per store file in the parent region. Those reference files will point to the parent regions’files.

    RegionServer在.splits目錄下創建子regions A和B以及一些需要的數據結構。然後開始分割store files,爲分割後的每個store files創建一個reference文件並存儲在parent region中,這些reference文件會指向parent的region file。

  6. The RegionServer creates the actual region directory in HDFS, and moves the reference files for each daughter.

    RegionServer 在HDFS中實際創建子region的目錄並且將reference文件移動到子region中。

  7. The RegionServer sends a Put request to the .META. table, to set the parent as offline in the .META. table and add information about daughter regions. At this point, there won’t be individual entries in .META. for the daughters. Clients will see that the parent region is split if they scan .META., but won’t know about the daughters until they appear in .META.. Also, if this Put to .META. succeeds, the parent will be effectively split. If the RegionServer fails before this RPC succeeds, Master and the next Region Server opening the region will clean dirty state about the region split. After the .META. update, though, the region split will be rolled-forward by Master.

    RegionServer發送Put請求到.META.表,將parent region在.META.表中的狀態設置爲offline,並將daughter regions的信息插入到.META.表中。如果用戶scan .META.表的話可以看到parent region已經在分割,但是在daughter region的信息被插入.META.表之前無法查看到。如果該Put操作成功的話,parent region就會被有效的分割。如果RegionServer在RPC成功之前失效的話,Master和下一個打開該region的RegionServer會清理region split過程中產生的臨時狀態,.META.表更新之後,region 的split會由Master進行回滾。

  8. The RegionServer opens daughters A and B in parallel.

    RegionServer並行打開A和B這兩個region。

  9. The RegionServer adds the daughters A and B to .META., together with information that it hosts the regions. THE SPLIT REGIONS (DAUGHTERS WITH REFERENCES TO PARENT) ARE NOW ONLINE. After this point, clients can discover the new regions and issue requests to them. Clients cache the .META. entries locally, but when they make requests to the RegionServer or .META., their caches will be invalidated, and they will learn about the new regions from .META..

    RegionServer將daughter A和daughter B所在的主機信息插入到.META.表中,並且狀態被標記爲online。在這個時間過後,客戶端就可以發現新region的信息並且可以對其發送請求。客戶端會將.META.實例緩存到本地,但是當客戶端向RegionServer或者.META.發送請求的時候緩存失效,這個時候會重新向.META.獲得新region的位置信息。

  10. The RegionServer updates znode /hbase/region-in-transition/region-name in ZooKeeper to state SPLIT, so that the master can learn about it. The balancer can freely re-assign the daughter regions to other region servers if necessary. THE SPLIT TRANSACTION IS NOW FINISHED.

    RegionServer更新Zookeeper中/hbase/region-in-transition/region-name znode的狀態爲SPLIT,master節點會通過監視器獲得該znode的狀態。如果有必要的話balancer會將daughter region重新標記到其他regionserver節點。THE SPLIT TRANSACTION IS NOW FINISHED.

  11. After the split, .META. and HDFS will still contain references to the parent region. Those references will be removed when compactions in daughter regions rewrite the data files. Garbage collection tasks in the master periodically check whether the daughter regions still refer to the parent region’s files. If not, the parent region will be removed.

    在分割之後,.META.表中和HDFS中仍然會在parent region中保存reference文件,這些reference文件會在daughter region進行compactionca操作重寫數據的時候被刪除。master的垃圾回收任務會週期性的檢查daughter region是否還引用parent region,如果沒有,這些parent region會被移除。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章