MDBX is a C library that implements a fast and efficient key-value database.
The entire database (environment) is exposed in a memory map, and all data fetches return data directly from the mapped memory, so no malloc's or memcpy's occur during data fetches.
Data pages use a copy-on-write strategy so no active data pages are ever overwritten, which also provides resistance to corruption and eliminates the need of any special recovery procedures after a system crash.
Writes are fully serialized; only one write transaction may be active at a time, which guarantees that writers can never deadlock. The database structure is multi-versioned so readers run with no locks; writers cannot block readers, and readers don't block writers.
It all starts with an environment. Then it can be opened and, after used, closed.
.dat
: file where data are stored..lck
: lock file.Once an environment is opened, a transaction can be created. Transactions may be:
The transaction provides a consistent view of the data.
Once a transaction has been created, a database (i.e. key-value space inside the environment) can be opened.
Within a transaction you can get and/or put different values inside the database.
To do more powerful things, we must use a cursor. For example for getting or saving a value in a specific position inside the database. Common methods on cursors are:
.first
: set the cursor at the first position in the key-value table of the database..next
: set the cursor to the next key-value pair in the database.