HBase source code analysis-GET operation-to-scan Conversion

Source: Internet
Author: User
GET operation for HBase source code analysis converts get to scan1, or you should first look at the constructor publicGet (byte [] row) {this (row, null);} publicGe

For HBase source code analysis, convert GET to scan 1 by using the get operation. Let's take a look at the constructor public Get (byte [] row) {this (row, null);} public Ge

HBase source code analysis-GET operation-to-scan Conversion

1. Let's look at the constructor first.

Public Get (byte [] row ){
This (row, null );
}


Public Get (byte [] row, RowLock rowLock ){
This. row = row;
If (rowLock! = Null ){
This. lockId = rowLock. getLockId ();
}
}

Public Get addFamily (byte [] family ){
FamilyMap. remove (family );
FamilyMap. put (family, null );
Return this;
}

Public Get addColumn (byte [] family, byte [] qualifier ){
NavigableSet Set = familyMap. get (family );
If (set = null ){
Set = new TreeSet (Bytes. BYTES_COMPARATOR );
}
Set. add (qualifier );
FamilyMap. put (family, set );
Return this;


Public Get addColumn (final byte [] column ){
If (column = null) return this;
Byte [] [] split = KeyValue. parseColumn (column );
If (split. length> 1 & split [1]! = Null & split [1]. length> 0 ){
AddColumn (split [0], split [1]);
} Else {
AddFamily (split [0]);
}
Return this;
}


2. The get method in HTable. java actually calls the get method of HregionServer.

Public Result get (final Get) throws IOException {
Return connection. getRegionServerWithRetries (
New ServerCallable (Connection, tableName, get. getRow ()){
Public Result call () throws IOException {
Return server. get (location. getRegionInfo (). getRegionName (), get );
}
}
);
}


3. Let's take a look at HregionServer. java.

/** {@ InheritDoc }*/
Public Result get (byte [] regionName, Get get) throws IOException {
CheckOpen ();
RequestCount. incrementAndGet ();
Try {
HRegion region = getRegion (regionName );
Return region. get (get, getLockFromId (get. getLockId ()));
} Catch (Throwable t ){
Throw convertThrowableToIOE (cleanup (t ));
}
}

Let's take a look at the get method of Hregion:

1) First, check the family to ensure that the family in the Table is consistent with that in get.

Public Result get (final Get, final Integer lockid) throws IOException {
// Verify families are all valid
If (get. hasFamilies ()){
For (byte [] family: get. familySet ()){
CheckFamily (family );
}
} Else {// Adding all families to your
For (byte [] family: regionInfo. getTableDesc (). getFamiliesKeys ()){
Get. addFamily (family );
}
}
List Result = get (get );


Return new Result (result );
}


The final GET is actually converted to scan.

/*
* Do a get based on the get parameter.
*/
Private List Get (final Get) throws IOException {
Scan scan = new Scan (get );


List Results = new ArrayList ();


Internal1_timeout = null;
Try {
Rows = getrows (scan );
Response. next (results );
} Finally {
If (response! = Null)
Response. close ();
}
Return results;
}

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.