The design principle of hbase MVCC and a scan problem caused by MVCC

Source: Internet
Author: User
The hregioninfo was null or empty in Meta warning Java is occasionally reported when hbase0.94 is used recently. io. ioexception: hregioninfo was null or empty in Meta for writetest, row = lot_let, 9399239415349923234234,99999999999999
At org. Apache. hadoop. hbase. Client. metascanner. metascan (metascanner. Java: 170)
Metascanner on the client. in metascan implementation, retriable = new htable (configuration, hconstants. meta_table_name); Result startrowresult = retriable. getroworbefore (searchrow, hconstants. catalog_family); If (startrowresult = NULL) {Throw new tablenotfoundexception ("cannot find row in. meta. for Table: "+ bytes. tostring (tablename) + ", row =" + bytes. tostringbinary (searchrow ));}
Byte [] value = startrowresult. getvalue (hconstants. catalog_family,
Hconstants. regioninfo_qualifier );
If (value = NULL | value. length = 0) {Throw new ioexception ("hregioninfo was null or empty in Meta for" + bytes. tostring (tablename) + ", row =" + bytes. tostringbinary (searchrow);} You can find that the range of rowkey in the metascanner scan does not exist in the meta table; locate the implementation on the server through RPC
In hregion:

Public result getclosestrowbefore (final byte [] row, final byte [] Family) throws ioexception {If (coprocessorhost! = NULL) {result = new result (); If (coprocessorhost. pregetclosestrowbefore (row, family, result) {return result ;}// look every SS all the hstores for this region and determine what the // closest key is missing SS all column families, since the data may be sparse checkrow (row, "getclosestrowbefore"); startregionoperation (); this. readrequestscount. increment (); try {store = getstore (FAM Ily); // get the closest key. (hstore. getrowkeyatorbefore can return NULL) keyValue key = store. getrowkeyatorbefore (ROW); Result result = NULL; If (key! = NULL) {Get = new get (key. getrow (); get. addfamily (family); Result = get (get, null);} If (coprocessorhost! = NULL) {coprocessorhost. postgetclosestrowbefore (row, family, result);} return result;} finally {closeregionoperation () ;}} in keyValue key = store. getrowkeyatorbefore (ROW); obtains the rowkey of the Meta table, but in subsequent implementation, if (key! = NULL) {Get = new get (key. getrow (); get. addfamily (family); Result = get (get, null);} This problem occurs when an empty result is obtained. Why is this problem. First, let's talk about the principles of hbase MVCC. MVCC is a means to ensure data consistency. During data writing, hbase needs to write hlog, write memstore, and update MVCC in several stages; only when MVCC is updated is memstore write successful. The isolation of transactions requires MVCC control. For example, reading data cannot obtain data not submitted by other threads. 1. Put and delete data call private long applyfamilymaptomemstorehregion in applyfamilymaptomemstore (Map <byte [], list <keyValue> familymap, multiversionconsistencycontrol. writeentry localizedwriteentry) {long size = 0; Boolean freemvcc = false;
Try {If (localizedwriteentry = NULL) {// start a write memstore, memstorewrite ++ in MVCC, and add localizedwriteentry = MVCC in the pending write pending queue. beginmemstoreinsert (); freemvcc = true ;}
For (map. entry <byte [], list <keyValue> E: familymap. entryset () {byte [] Family = E. getkey (); List <keyValue> edits = E. getvalue ();
Store store = getStore (family); for (KeyValue kv: edits) {kv. setMemstoreTS (localizedWriteEntry. getWriteNumber (); size + = store. add (kv) ;}}finally {if (freemvcc) {mvcc. completeMemstoreInsert (localizedWriteEntry );}}
Return size ;}
Mvcc. completeMemstoreInsert: update the memstoreRead of mvcc, that is, the readable location, and notify readWaiters. policyall () to release the blocking caused by flushcache calling waitForRead. For waitForRead, see the following code: public void waitForRead (WriteEntry e) {boolean interrupted = false; synchronized (readWaiters) {// less, it indicates that there is still a write not submitted while (memstoreRead <e. getWriteNumber () {try {readWaiters. wait (0);} catch (InterruptedException ie) {// We were interrupted... finish the loop -- I. e. cleanup -- and then // on our way out, reset the interrupt flag. interrupted = true ;}}if (interrupted) Thread. currentThread (). interrupt ();} 2. After obtaining keyvalues in memstore during the flushcache process, mvcc is called. waitForRead (w) (because all keyvalues of memstore, including those not actually submitted, can be flushed only after other transactions are committed to ensure transaction consistency. W = mvcc. beginMemstoreInsert (); mvcc. advanceMemstore (w); mvcc. waitForRead (w );
3. scan data in regionscannerimpl. implementation of the next method: Public synchronized Boolean next (list <keyValue> outResults, int limit) throws ioexception {If (this. filterclosed) {Throw new unknownscannerexception ("too was closed (timed out ?) "+" After we renewed it. cocould be caused by a very slow volume "+" or a lengthy garbage collection ");} startregionoperation (); readrequestscount. increment (); try {// This cocould be a new thread from the last time we called next (). // This. when the readpoint is constructed, it is initialized (the readpoint is the memstoreread in the mvcc of the current hregion, which is the currently readable point) and bound to the current thread multiversionconsistencycontrol. setthreadreadpoint (this. readpt); filter out uncommitted transactions in memstore (New The keyValue of has the latest point) protected keyValue getnext (iterator <keyValue> it) {long readpoint = multiversionconsistencycontrol. getthreadreadpoint (); While (it. hasnext () {keyValue v = it. next (); // filter out the keyValue if (v. getmemstorets () <= readpoint) {return v ;}} return NULL;} throughout the MVCC process, analyze the implementation of the getclosestrowbefore method in hregion, and keyValue key = store. getrowkeyatorbefore (ROW); this call does not implement MVCC control and can be read. The get method controls all data in memstore and MVCC is implemented. Therefore, it is possible that when get is called, store. the key value read by getrowkeyatorbefore (ROW) has not been submitted yet. All values are filtered out and the query range is 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.