RegionServer Splitting Implementation:regionServer 分裂过程分析
-
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 toSPLITTING
. -
The Master learns about this znode, since it has a watcher for the parent
region-in-transition
znode. -
The RegionServer creates a sub-directory named
.splits
under the parent’sregion
directory in HDFS. -
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. -
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 region’s files. -
The RegionServer creates the actual region directory in HDFS, and moves the reference files for each daughter.
-
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 thisPut
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. -
The RegionServer opens daughters A and B in parallel.
-
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.
. -
The RegionServer updates znode
/hbase/region-in-transition/region-name
in ZooKeeper to stateSPLIT
, 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. -
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. - 本文链接地址:http://hbase.apache.org/book.html#regionserver.arch