python xapian storage structure
Dec 09, 2016 pm 02:21 PMIn order to support the search service in the project, we use xapian as the back-end search engine. It is popular for its good performance and ease of use. The following is the basic code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Although it is very simple to use, I have always been concerned about its storage The engine was a little curious, so I took a look at the implementation of the latest storage engine brass. The following is the hierarchy of the entire data directory:
/tmp/user_index
flintlock
iamchert
postlist.baseA
postlist.baseB
postlist.DB //Storage all Term to docid mapping.
record.baseA
record.baseB
record.DB //Storage all docid to corresponding data mapping
termlist.baseA
termlist.baseB
termlist.DB //Storage all docid to corresponding term Mapping. The data structure used by the
brass storage engine is BTree. So each *.DB above stores a BTree. *.baseA/B stores the meta information of the corresponding .DB. Including this large data Which data blocks of the file have been used, which free bitmaps, and version numbers and other related information.
BTree is represented as N Level in xapian. Each level corresponds to a layer of BTree. And maintains a cursor of this layer .Used to point to a certain data block currently being accessed, and a certain position in the data block. The data structure of each data block is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
The above comments from xapian have clearly explained each block The data composition. In addition to the data element information, it is a small data unit composed of items. Each small item includes I (the length of the entire data unit), K (the length of the data unit key + x (key identifier)) , C (indicates how many items the corresponding key consists of, because if the value corresponding to a certain key is too large, value segmentation will be performed. So C means how many points there are in total. And the previous x means that this unit is Which piece of data, if you need to read the entire large value of this key, you can merge it according to the serial number x.), tag is the value corresponding to the key we just mentioned, but xapian defines it as tag. Because it is a Universal storage structure, so this definition makes sense. For example, the non-leaf node tag of a BTree stores the address of the next layer of data blocks. For leaf nodes, related data is stored. Now the entire tree The storage structure has been clearly displayed.
There is an interesting problem here, which is the storage of postlist. Imagine that a certain hot word contains many docids, for example, 1 million. Then when we perform incremental updates Sometimes, if you want to delete a certain docid from this term, how can you find out which data block this docid is in as soon as possible? The author uses term+docid as the key of BTree to solve this problem. The value is all docids larger than this docid. And each block is set to a size. This allows us to locate a docid as quickly as possible. block, instead of reading all blocks and then searching.
xapian also supports multiple readers and single-threaded writers for incremental updates. It adopts a method similar to MVCC in the database, so that there will be no The update blocks the read operation.
Currently, the author is developing the replication method, which can support incremental updates to other machines. This can achieve data reliability (no data loss due to single-machine disk damage) and high availability (single-machine disk damage) Unavailable, the application layer can be switched to a backup machine).
BTW: I have read the xapian devel mailing list in the past two days. Although I have not submitted any questions, I have seen that the author (Olly Betts) will give answers to every question. He is really nice for his patient and detailed reply. I admire him very much.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the advantages and disadvantages of templating?

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

For only $250, Hugging Face's technical director teaches you how to fine-tune Llama 3 step by step

Share several .NET open source AI and LLM related project frameworks

A complete guide to golang function debugging and analysis
