HBase Source Analysis-HBase region split (split)

Source: Internet
Author: User

Code version: hbase-1.2.6

Project: Hbase-server

Class: Org.apache.hadoop.hbase.regionserver.HRegion


Issues that need to be addressed:

1, when to trigger the split.

2. What is the strategy for splitting?



1. Determine if you need to slice

Method: Checksplit

return value: Splitpoint

After doing some judgment, it is actually called:

byte[] ret = Splitpolicy.getsplitpoint ();

2. Segmentation Strategy

Org.apache.hadoop.hbase.regionserver.RegionSplitPolicy

/**
   * @return The key at which the should is split, or null
   * If it cannot be split. This is only being called if Shouldsplit
   * previously returned true.
   *
  /protected byte[] Getsplitpoint () {
    byte[] Explicitsplitpoint = This.region.getExplicitSplitPoint ();
    if (explicitsplitpoint! = null) {
      return explicitsplitpoint;
    }
    List<store> stores = Region.getstores ();

    byte[] Splitpointfromlargeststore = null;
    Long largeststoresize = 0;
    for (Store s:stores) {
      byte[] Splitpoint = S.getsplitpoint ();
      Long storesize = S.getsize ();
      if (splitpoint! = null && largeststoresize < storesize) {
        splitpointfromlargeststore = splitpoint;
        Largeststoresize = storesize;
      }
    }

    return splitpointfromlargeststore;
  }

From the above code to see if Explicitsplitpoint is not empty, then use this, and then look up is Forcesplit assignment

If Explicitsplitpoint is empty, then region. Getstores (), according to Storesize find Splitpoint

The Getsplitpoint method for Hstore is called:

@Override public
  byte[] Getsplitpoint () {
    this.lock.readLock (). Lock ();
    try {
      //should already is enforced by the split policy!
      Assert!this.getregioninfo (). Ismetaregion ();
      Not split-able If we find a reference store file present in the store.
      if (Hasreferences ()) {
        return null;
      }
      Return This.storeEngine.getStoreFileManager (). Getsplitpoint ();
    } catch (IOException e) {
      Log.warn ("Failed getting store size for" + this, e);
    } finally {
      this.lock.readLock (). Unlock ();
    }
    return null;
  }

Defaultstorefilemanager

@Override public
  Final byte[] Getsplitpoint () throws IOException {
    if (This.storefiles.isEmpty ()) {
      return null;
    }
    Return Storeutils.getlargestfile (this.storefiles). Getfilesplitpoint (This.kvcomparator);
  }

Then to Sotrefile's:

 /** * Gets The approximate mid-point of this file, which is optimal for use in splitting it.
   * @param comparator comparator used to compare KVs.
   * @return The split point row, or null if splitting are not possible, or reader is null. */@SuppressWarnings ("deprecation") byte[] Getfilesplitpoint (Kvcomparator comparator) throws IOException {if (thi S.reader = = null) {Log.warn ("StoreFile" + This + "reader is null;
      Cannot get split point ");
    return null;  }//Get First, last, and mid keys.  Midkey is the key, starts block//in middle of hfile.  has column and timestamp.
    Need to return just//the row we want to split on as Midkey.
    byte [] Midkey = This.reader.midkey ();
      if (Midkey! = null) {KeyValue mk = Keyvalue.createkeyvaluefromkey (midkey, 0, midkey.length);
      byte [] FK = This.reader.getFirstKey ();
      KeyValue Firstkey = Keyvalue.createkeyvaluefromkey (FK, 0, Fk.length); byte [] lk = This.reader.getLastKey ();
      KeyValue Lastkey = Keyvalue.createkeyvaluefromkey (lk, 0, lk.length);
      If the Midkey is the same as the first or last keys, we cannot (ever) split this region. if (Comparator.comparerows (MK, firstkey) = = 0 | | comparator.comparerows (mk, lastkey) = = 0) {if (log.isdebugenable
        D ()) {Log.debug ("cannot split because Midkey is the same as first or last row");
      } return null;
    } return Mk.getrow ();
  } return null; }




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.