"leveldb Five:memtable details "
Leveldb the previous section describes the important static structure of disk files, this section describes the in-memory data structure memtable,memtable important position in the whole system is also self-evident. Overall, all kv data is stored in memtable,immutable memtable and sstable, and immutable memtable is structurally and memtable exactly the same, except that it is read-only and does not allow write operations , while Memtable is allowed to write and read. When the data written by memtable reaches a specified amount of memory, it is automatically converted to immutable memtable, waits for dump to disk, the system automatically generates a new memtable for write operations to write new data, and understands memtable, then immutable Memtable Nature is a cinch.
LEVELDB's memtable provides an operational interface for writing KV data, deleting and reading KV records, but in fact memtable does not have a real delete operation, and the value of deleting a key is implemented as a record insertion in memtable, But will hit a key delete tag, the actual deletion is lazy, will be removed in the subsequent compaction process of this KV.
It is important to note that the KV pair in the Leveldb memtable is stored sequentially according to the key size, and when the system is plugged into a new kv, the LEVELDB is to plug the kv into the appropriate position to maintain the key ordering. In fact, Leveldb's memtable class is just an interface class, the real operation is done through the skiplist behind, including insert operations and read operations, so memtable core data structure is a skiplist.
Skiplist is an alternative data structure for a balanced tree, but not the same as the red and black trees, skiplist is based on a randomized algorithm for the balance of the tree, which means that the insertion and deletion of skiplist is relatively straightforward.
For more information about Skiplist, refer to this article:http://www. Cnblogs. COM/xuqiang/archive/2011/05/22/2053516. HTML, telling the very clear, leveldb skiplist is basically a concrete implementation, There is no special place.
Skiplist is not only a simple implementation of maintaining ordered data, but compared to the balance tree, when inserting data can avoid frequent tree node adjustment operations, so the write efficiency is very high, leveldb overall is a high write system, Skiplist should also play a very important role in it. Redis also uses skiplist as an internal implementation data structure in order to speed up the insert Operation .
Reference: http://www.cnblogs.com/haippy/archive/2011/12/04/2276064.html
LEVELDB Five: memtable details