Berkeley dB source code analysis 2 !!

Source: Internet
Author: User

Nothing can be done at work. Many places are speculation or inaccurate.

1) bdb compilation is performed under the build_windows and build_unix directories. VC directly converts the DSW of vc6 to vc9. Remember to set the compilation option to debug x86.

2) in the past two days, the research mainly involves the B-tree part. The code starting with Bt is the B-tree operation part, including put, open, delete, search, and split parts, where split is the page.

 

I don't think there are too many bdb documents, especially those with diagrams in Chinese. You can refer to the btree of SQLite. Everyone is doing almost the same thing. After knowing the principles, carefully analyze the code.

 

Just say a function:

/*
* _ Bam_split --
* Split a page.
*
* Public: int _ bam_split _ p (DBC *, void *, db_pgno_t *));
*/
Int
_ Bam_split (DBC, ARG, root_pgnop)
DBC * dBc;
Void * ARG;
Db_pgno_t * root_pgnop;
{

For (DIR = up, level = leaflevel; Dir = up? ++ Level: -- level ){
/*
* Acquire a page and its parent, locked.
*/
If (ret = (DBC-> dbtype = db_btree?
_ Bam_search (DBC, pgno_invalid,
Arg, sr_wrpair, level, null, & exact ):
_ Bam_rsearch (DBC,
(Db_recno_t *) Arg, sr_wrpair, level, & exact )))! = 0)
Break;

 

...

Bdb comments are very good. You can see the comments in many places. Below is the translation

 

When the space of the leaf node is full, the split will be triggered. A new leaf node will be returned.

In this case, you need to search for the leaf node based on the key to be inserted. In this case, you need to lock the leaf node and its parent page.

Then we can split this leaf page. Then we need to check the new Internal Key (the Internal Key is an internal Node ?) Suitable for parent page.

 

If it is not suitable, discard the current lock and re-do it. This lock is the parent and parent of the leaf page. This will continue iteration until the split is successful.

The general meaning is actually the process of B-tree split. After work, I will understand it carefully tomorrow.

 

 

 

 

 

 

 

 

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.