Region split Logic

Source: Internet
Author: User

Table of Contents

Region split
The premise of splitting
Get Split Point
Perform split
Rollback operation
Region split

The split logic of region is triggered by the Requestsplit method of the Compactsplitthread thread, which is invoked whenever a memstoreflush operation is performed, to see if it is necessary to split the target.

The premise of splitting

The prerequisite for region splitting is that the following constraints need to be met:

  1. The number of region on the line of the target Regionserver does not reach the Hbase.regionserver.regionSplitLimit parameter threshold

    The default value of this parameter is 1000, and when you reach 900 regionserver will print a warning: Total number of regions is approaching the upper limit.

  2. The number of storefile files does not reach the Hbase.hstore.blockingStoreFiles parameter threshold

    This will trigger the grooming operation (detailed reference to the Region collation section)

  3. The region you want to split is not part of the meta table

    HBase does not support splitting operations on the region in the meta table.

  4. Region is not in recovering state (refer to Region recovery section)

  5. The decision is made by a specific split strategy, through its Shouldsplit method

    HBase provides a 5 split strategy, all derived from Regionsplitpolicy, and the 5 policy is:

    • Constantsizeregionsplitpolicy

      Split when a store data volume in region reaches the Hbase.hregion.max.filesize parameter threshold

    • Increasingtoupperboundregionsplitpolicy

      When a store data volume in the region reaches the Sizetocheck threshold, the Sizetocheck is calculated by the following method, if the number of region containing the specified table on Regionserver is between (0,100], Returns the value of the following formula:

      Min (hbase.hregion.max.filesize, regioncount^3 * initialsize)

      Otherwise, the Hbase.hregion.max.filesize parameter value is returned. This shows that the split strategy is incremental, with the number of region increased, the split threshold is gradually greater, until the target limit is reached.

    • Delimitedkeyprefixregionsplitpolicy

      The split policy is as follows: If you define Rowkey with ' _ ' as the field delimiter (for example: Userid_eventtype_eventid), then the policy is split to ensure that records with the same userid belong to the same region.

      The class inherits to Increasingtoupperboundregionsplitpolicy, with the same split premise as the parent class, but slightly different from the fetch of the split point (refer to the next section).

    • Keyprefixregionsplitpolicy

      Similar to Delimitedkeyprefixregionsplitpolicy, except that a character prefix of the specified length is selected as the grouping of the row.

    • Disabledregionsplitpolicy

      The policy Shouldsplit method always returns false, which means that the Split function is not enabled and any splits are not made for region.

Get Split Point

The split point is mainly obtained by invoking the Getsplitpoint method of the split policy, which has different acquisition logic, as follows:

  1. Returns the user-specified split point if the split point was used by the split command to force the Declaration.

  2. If the split policy is constantsizeregionsplitpolicy or increasingtoupperboundregionsplitpolicy, select the store with the largest amount of data in region, Get the Shard point by its Getsplitpoint method.

    Method also takes into account the implementation type of Storefilemanager during execution:

    • If it is Defaultstorefilemanager

      Select a storefile from the destination store with the largest amount of data, Execute the Getfilesplitpoint method on it to get the Midkey as a split point (read from the root index, refer to the hfile storage structure).

    • If Stripestorefilemanager (with stripecompaction)

      If there is only one stripe in the store, Get the StoreFile with the largest amount of data, and execute the Getfilesplitpoint method on it to get midkey information as a split point for that region.

      If you have more than one stripe, try to find the divider shown in the middle of all stripe so that the total amount of data on the left and right side of the split line is closest. After the


      Split Line is established, you can directly determine the region's split point if the following constraints are met.

      Largesidesize/smallsidesize < 1.5

      Where largesidesize is data A party with a large amount (that is, the total amount of data on the left side of the split line in the figure), Smallsidesize is the party with a small amount of data (that is, the amount of data to the right of the split line), And 1.5 is declared through the Hbase.store.stripe.region.split.max.imbalance configuration item. The

      Takes the example picture to illustrate: since Largesidesize (3072m)/smallsidesize (2560M) = 1.2, the value is less than 1.5, the endrow of Stripe-2 is directly used as the region's split point. If the size of the Stripe-2 is 20480m, then there is no way to meet the above constraints, you need to do the following:


      Divides half the size of stripe-2 into the right area (where the split line will be drawn), and then regenerates the radio value.

      Largesidesize (12800)/smallsidesize (11264) = 1.14

      If the newly generated Radio value is larger than the previous radio, then discard this approach, still use the previous processing, otherwise from the stripe-2 to select the largest amount of data storefile, the implementation of Getfilesplitpoint method to obtain Midkey information, and returns it as a split point for that region.

Perform split

Region in the process of splitting, need to hmaster and regionserver of the joint participation, the coordination of the work through zookeeper to achieve. A/hbase/region-intransition/{regionname} splitter node is created for each region,regionserver end to be split, and the node content is Regiontransition object, Objects consist of the following pieces of information:

    • EventType

      Event type, where the event type is captured by the Rs_zk_request_region_split,master side and the corresponding callback is processed.

    • Regionname

      Represents the conversion operation to which region is executed.

    • ServerName

      On which regionserver the target region is deployed.

    • Payload

      Loading additional information to handle the target event, here is the Hregioninfo information for the sub region.

After the split node is created successfully, the Hmaster side will perform the appropriate callback processing by listening to the target node path of the Zookeeper (refer to the Handleregion method of the AssignmentManager class). In callback processing, first read out the Regiontransition object from the target splitter node, modify its EventType property value to Rs_zk_region_splitting, and reassign the object to the target split node. The region State participating in the split operation is then modified to mark the parent region to be split into the splitting state, with the two newly generated sub-region marked as splitting_new. Through the Updateregionstate method of the Regionstates class.

At the same time, the Regionserver side enters the loop wait state after the split node is created (the Waitforsplittransaction method of the Code logic reference Zksplittransactioncoordination Class), Until its EventType property value becomes rs_zk_region_splitting, and then begins to perform the following processing:

  1. Create a. Splits subdirectory under the region directory to be split as a split directory.

  2. Closes the region to be split, no longer provides online services, through the Hregion Close method.

  3. Splits the storefile in region. The

    assumes that the target region is split into split-a (the data before the split point is stored) and split-b (the data after the split point is stored), and the split rule is as follows:

    First defines the following 3 variables:

    (1) Firstkey: Used to represent the starting key of the StoreFile file;

    (2) Lastkey: Used to denote the end key of the StoreFile file;

    (3) Splitkey: The split point used to represent the region.

    • If StoreFile satisfies Firstkey < Splitkey < Lastkey, the data on the [Firstkey,splitkey] interval is assigned to SPLIT-A.

    • If StoreFile satisfies Firstkey < Lastkey < Splitkey, the entire storefile is given region-a.

    • If StoreFile satisfies Splitkey < Firstkey < Lastkey, the entire storefile is given region-b

    • /ul>tip in HBase, the split storefile sub-file is described by reference, its data content is serialized with Protobuf, and each reference file is stored on the HDFs path path/to/table/ Parentregion/.splits/childregion/cf/storefile.parentregion

      The sub region needs to be removed from path/to/table/parentregion/after the split is complete. The splits/childregion path is moved to the path/to/table/path.

  4. Modify the region metadata information in the meta table through the Splitregion method of the Metatableaccessor class

    Add the child region to the meta table and mark the parent region as the splitting state (new Splita and SPLITB column information, which is the hregioninfo of the child region).

    Tip

    From the beginning of this step, the region split operation cannot be rolled back, and in the event of an error, the regionserver needs to be stopped so that Servershutdownhandler can fix the metadata for the target region. Refer to the section on state management for status fixes in detail.

  5. Start the split sub region by Hregion the Openhregion method

    The child region that is started is deployed on the same regionserver as the parent region, and because the split sub region contains the reference file internally, it needs to be collated (refer to the Region Collation section).

After the regionserver end of the sub region is started, it is necessary to notify the startup results to the Hmaster side, and the notification logic is also implemented with the help of zookeeper. First get the Regiontransition object from zookeeper's target splitter node and modify its EventType property value to Rs_zk_region_split. After the node state is modified, the master side will handle the following callback:

(1) To mark the parent region as split state and to process it offline;

(2) After the split sub-region is on-line, marking it as open state;

(3) Delete the split node in the zookeeper.

At this point, the split logic for region is executed successfully, and the child region begins to provide online services.

Rollback operation

Region is managed with transactions during the split process, and if an exception occurs during the split process, the transaction can be rolled back to avoid dirty data generation. Transaction logic is primarily encapsulated by the Splittransaction class, which uses the following templates:

Splittransaction st = new Splittransaction (conf, parent, Midkey), if (!st.prepare ()) return;try {   St.execute (server, Services);} catch (IOException IoE) {   try {      st.rollback (server, services);      return;   } catch (RuntimeException e) {      myabortable.abort ("Failed split, Abort");}   }

You can see that the rollback logic is mainly implemented by the Rollback method, which is handled as follows:

  1. First gets the split progress for the current region and what has been done before the progress is reached.

    Region is roughly going through the following stages during the split process (the detailed split process can refer to the previous section):

    (1) STARTED-split logic is triggered;

    (2) PREPARED-To perform the pre-split preparation work;

    (3) Before_pre_split_hook-Call the coprocessor to intercept before splitting;

    (4) After_pre_split_hook-coprocessor processing is finished;

    (5) Create a split node in Set_splitting-zookeeper;

    (6) Create_split_dir-Split directory is generated;

    (7) Closed_parent_region-The parent region is closed;

    (8) Offlined_parent-Parent region is offline and no longer provides online services;

    (9) Started_region_a_creation-the first child region was successfully created;

    (10) Started_region_b_creation-the second sub region was successfully created;

    (11) PONR-rollback of the demarcation point, that is, the operation before the stage can be rolled back;

    (12) Opened_region_a-The first sub region is opened;

    (13) Opened_region_b-the second sub region is opened;

    (14) Before_post_split_hook-Call coprocessor for interception after splitting;

    (15) After_post_split_hook-coprocessor processing is complete.

    Each time you arrive at a stage, HBase creates a journalentry entity to mark the current progress and add the entity to the journal collection. This way, by journal the collection, you can tell which stage the current split progress has entered, and then roll back backward through each phase in turn. It is important to note that if the split progress reaches the PONR stage (Point-of-no-return), you will not be able to perform a rollback operation and only stop Regionserver to servershutdownhandler the region's metadata for repair (Refer to the section of Region state management for status fixes).

    The following message will be printed when regionserver is down for this situation:

    Abort; We got an error after Point-of-no-return

  2. Rolls back all operations prior to the current progress.

    The rollback operation is done through iterative iterations, each of which is performed at a specific stage.

    (1) If the rollback is in the set_splitting stage, delete the split node in the zookeeper;

    (2) If the rollback is in the create_split_dir stage, clean up the split directory under the parent region;

    (3) If the rollback is in the closed_parent_region phase, re-initializes the parent region;

    (4) If the rollback is in the started_region_a_creation phase, clean up the storage directory of the first child region;

    (5) If the rollback is in the started_region_b_creation phase, clean up the storage directory of the second sub region;

    (6) If the rollback is in the offlined_parent stage, the parent region will be re-launched;

    (7) If the rollback is in the Ponr or later stage, the Regionserver will be stopped.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Region split Logic

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.