LMDB
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
LMDB Internals

Modules

 ID List Management
 
 Compatibility Macros
 A bunch of macros to minimize the amount of platform-specific ifdefs needed throughout the rest of the code. When the features this library needs are similar enough to POSIX to be hidden in a one-or-two line replacement, this macro approach is used.
 
 Debug Macros
 
 Reader Lock Table
 Readers don't acquire any locks for their data access. Instead, they simply record their transaction ID in the reader table. The reader mutex is needed just to find an empty slot in the reader table. The slot's address is saved in thread-specific data so that subsequent read transactions started by the same thread need no further locking to proceed.
 
 Page Flags
 
 Node Flags
 
 Transaction DB Flags
 
 Transaction Flags
 
 Cursor Flags
 

Data Structures

struct  MDB_page
 
struct  MDB_node
 
struct  MDB_db
 
struct  MDB_meta
 
union  MDB_metabuf
 
struct  MDB_dbx
 
struct  MDB_txn
 Opaque structure for a transaction handle. More...
 
struct  MDB_cursor
 Opaque structure for navigating through a database. More...
 
struct  MDB_xcursor
 
struct  MDB_pgstate
 
struct  MDB_env
 Opaque structure for a database environment. More...
 
struct  MDB_ntxn
 
struct  MDB_name
 
struct  mdb_copy
 

Macros

#define LOCK_MUTEX(rc, env, mutex)   ((rc) = LOCK_MUTEX0(mutex))
 
#define mdb_mutex_failed(env, mutex, rc)   (rc)
 
#define MDB_DSYNC   O_SYNC
 
#define MDB_FDATASYNC   fdatasync
 
#define MDB_MSYNC(addr, len, flags)   msync(addr,len,flags)
 
#define MS_SYNC   1
 
#define MS_ASYNC   0
 
#define MAX_PAGESIZE   (PAGEBASE ? 0x10000 : 0x8000)
 The maximum size of a database page. More...
 
#define MDB_MINKEYS   2
 
#define MDB_MAGIC   0xBEEFC0DE
 
#define MDB_DATA_VERSION   ((MDB_DEVEL) ? 999 : 1)
 
#define MDB_LOCK_VERSION   1
 
#define MDB_MAXKEYSIZE   ((MDB_DEVEL) ? 0 : 511)
 The max size of a key we can write, or 0 for computed max. More...
 
#define ENV_MAXKEY(env)   (MDB_MAXKEYSIZE)
 
#define MAXDATASIZE   0xffffffffUL
 The maximum size of a data item. More...
 
#define DKBUF
 
#define DKEY(x)   0
 
#define P_INVALID   (~(pgno_t)0)
 
#define F_ISSET(w, f)   (((w) & (f)) == (f))
 
#define EVEN(n)   (((n) + 1U) & -2) /* sign-extending -2 to match n+1U */
 
#define DEFAULT_MAPSIZE   1048576
 
#define PAGEHDRSZ   ((unsigned) offsetof(MDB_page, mp_ptrs))
 
#define METADATA(p)   ((void *)((char *)(p) + PAGEHDRSZ))
 
#define PAGEBASE   ((MDB_DEVEL) ? PAGEHDRSZ : 0)
 
#define NUMKEYS(p)   (((p)->mp_lower - (PAGEHDRSZ-PAGEBASE)) >> 1)
 
#define SIZELEFT(p)   (indx_t)((p)->mp_upper - (p)->mp_lower)
 
#define PAGEFILL(env, p)
 
#define FILL_THRESHOLD   250
 
#define IS_LEAF(p)   F_ISSET((p)->mp_flags, P_LEAF)
 
#define IS_LEAF2(p)   F_ISSET((p)->mp_flags, P_LEAF2)
 
#define IS_BRANCH(p)   F_ISSET((p)->mp_flags, P_BRANCH)
 
#define IS_OVERFLOW(p)   F_ISSET((p)->mp_flags, P_OVERFLOW)
 
#define IS_SUBP(p)   F_ISSET((p)->mp_flags, P_SUBP)
 
#define OVPAGES(size, psize)   ((PAGEHDRSZ-1 + (size)) / (psize) + 1)
 
#define NEXT_LOOSE_PAGE(p)   (*(MDB_page **)((p) + 2))
 
#define NODESIZE   offsetof(MDB_node, mn_data)
 
#define PGNO_TOPWORD   ((pgno_t)-1 > 0xffffffffu ? 32 : 0)
 
#define INDXSIZE(k)   (NODESIZE + ((k) == NULL ? 0 : (k)->mv_size))
 
#define LEAFSIZE(k, d)   (NODESIZE + (k)->mv_size + (d)->mv_size)
 
#define NODEPTR(p, i)   ((MDB_node *)((char *)(p) + (p)->mp_ptrs[i] + PAGEBASE))
 
#define NODEKEY(node)   (void *)((node)->mn_data)
 
#define NODEDATA(node)   (void *)((char *)(node)->mn_data + (node)->mn_ksize)
 
#define NODEPGNO(node)
 
#define SETPGNO(node, pgno)
 
#define NODEDSZ(node)   ((node)->mn_lo | ((unsigned)(node)->mn_hi << 16))
 
#define SETDSZ(node, size)
 
#define NODEKSZ(node)   ((node)->mn_ksize)
 
#define COPY_PGNO(dst, src)
 
#define LEAF2KEY(p, i, ks)   ((char *)(p) + PAGEHDRSZ + ((i)*(ks)))
 
#define MDB_GET_KEY(node, keyptr)
 
#define MDB_GET_KEY2(node, key)   { key.mv_size = NODEKSZ(node); key.mv_data = NODEKEY(node); }
 
#define MDB_VALID   0x8000
 
#define PERSISTENT_FLAGS   (0xffff & ~(MDB_VALID))
 
#define VALID_FLAGS
 
#define FREE_DBI   0
 
#define MAIN_DBI   1
 
#define CORE_DBS   2
 
#define NUM_METAS   2
 
#define CURSOR_STACK   32
 
#define XCURSOR_INITED(mc)   ((mc)->mc_xcursor && ((mc)->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED))
 
#define XCURSOR_REFRESH(mc, top, mp)
 
#define MDB_COMMIT_PAGES   64
 
#define MAX_WRITE   (0x40000000U >> (sizeof(ssize_t) == 4))
 
#define TXN_DBI_EXIST(txn, dbi, validity)   ((txn) && (dbi)<(txn)->mt_numdbs && ((txn)->mt_dbflags[dbi] & (validity)))
 
#define TXN_DBI_CHANGED(txn, dbi)   ((txn)->mt_dbiseqs[dbi] != (txn)->mt_env->me_dbiseqs[dbi])
 
#define MDB_END_NAMES
 
#define MDB_END_OPMASK   0x0F
 
#define MDB_END_UPDATE   0x10
 
#define MDB_END_FREE   0x20
 
#define MDB_END_SLOT   MDB_NOTLS
 
#define MDB_PS_MODIFY   1
 
#define MDB_PS_ROOTONLY   2
 
#define MDB_PS_FIRST   4
 
#define MDB_PS_LAST   8
 
#define MDB_SPLIT_REPLACE   MDB_APPENDDUP
 
#define mdb_env_close0(env, excl)   mdb_env_close1(env)
 
#define mdb_cmp_clong   mdb_cmp_cint
 
#define mdb_cassert(mc, expr)   mdb_assert0((mc)->mc_txn->mt_env, expr, #expr)
 
#define mdb_tassert(txn, expr)   mdb_assert0((txn)->mt_env, expr, #expr)
 
#define mdb_eassert(env, expr)   mdb_assert0(env, expr, #expr)
 
#define mdb_assert0(env, expr, expr_txt)
 
#define MDB_NAME(str)   str
 
#define mdb_name_cpy   strcpy
 
#define MDB_SUFFLEN   9
 
#define mdb_fname_destroy(fname)   do { if ((fname).mn_alloced) free((fname).mn_val); } while (0)
 
#define MDB_CLOEXEC   0
 
#define CHANGEABLE   (MDB_NOSYNC|MDB_NOMETASYNC|MDB_MAPASYNC|MDB_NOMEMINIT)
 
#define CHANGELESS
 
#define MDB_NOSPILL   0x8000
 
#define WITH_CURSOR_TRACKING(mn, act)
 
#define MDB_WBUF   (1024*1024)
 
#define MDB_EOF   0x10
 

Typedefs

typedef MDB_ID pgno_t
 
typedef MDB_ID txnid_t
 
typedef uint16_t indx_t
 
typedef char mdb_nchar_t
 

Enumerations

enum  {
  MDB_END_COMMITTED, MDB_END_EMPTY_COMMIT, MDB_END_ABORT, MDB_END_RESET,
  MDB_END_RESET_TMP, MDB_END_FAIL_BEGIN, MDB_END_FAIL_BEGINCHILD
}
 
enum  Pidlock_op { Pidset = F_SETLK, Pidcheck = F_GETLK }
 
enum  mdb_fopen_type {
  MDB_O_RDONLY = O_RDONLY, MDB_O_RDWR = O_RDWR |O_CREAT, MDB_O_META = O_WRONLY|MDB_DSYNC |MDB_CLOEXEC, MDB_O_COPY = O_WRONLY|O_CREAT|O_EXCL|MDB_CLOEXEC,
  MDB_O_MASK = MDB_O_RDWR|MDB_CLOEXEC | MDB_O_RDONLY|MDB_O_META|MDB_O_COPY, MDB_O_LOCKS = MDB_O_RDWR|MDB_CLOEXEC | ((MDB_O_MASK+1) & ~MDB_O_MASK)
}
 

Functions

static int mdb_page_alloc (MDB_cursor *mc, int num, MDB_page **mp)
 
static int mdb_page_new (MDB_cursor *mc, uint32_t flags, int num, MDB_page **mp)
 
static int mdb_page_touch (MDB_cursor *mc)
 
static void mdb_txn_end (MDB_txn *txn, unsigned mode)
 
static int mdb_page_get (MDB_cursor *mc, pgno_t pgno, MDB_page **mp, int *lvl)
 
static int mdb_page_search_root (MDB_cursor *mc, MDB_val *key, int modify)
 
static int mdb_page_search (MDB_cursor *mc, MDB_val *key, int flags)
 
static int mdb_page_merge (MDB_cursor *csrc, MDB_cursor *cdst)
 
static int mdb_page_split (MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno, unsigned int nflags)
 
static int mdb_env_read_header (MDB_env *env, MDB_meta *meta)
 
static MDB_meta * mdb_env_pick_meta (const MDB_env *env)
 
static int mdb_env_write_meta (MDB_txn *txn)
 
static void mdb_env_close0 (MDB_env *env, int excl)
 
static MDB_node * mdb_node_search (MDB_cursor *mc, MDB_val *key, int *exactp)
 
static int mdb_node_add (MDB_cursor *mc, indx_t indx, MDB_val *key, MDB_val *data, pgno_t pgno, unsigned int flags)
 
static void mdb_node_del (MDB_cursor *mc, int ksize)
 
static void mdb_node_shrink (MDB_page *mp, indx_t indx)
 
static int mdb_node_move (MDB_cursor *csrc, MDB_cursor *cdst, int fromleft)
 
static int mdb_node_read (MDB_cursor *mc, MDB_node *leaf, MDB_val *data)
 
static size_t mdb_leaf_size (MDB_env *env, MDB_val *key, MDB_val *data)
 
static size_t mdb_branch_size (MDB_env *env, MDB_val *key)
 
static int mdb_rebalance (MDB_cursor *mc)
 
static int mdb_update_key (MDB_cursor *mc, MDB_val *key)
 
static void mdb_cursor_pop (MDB_cursor *mc)
 
static int mdb_cursor_push (MDB_cursor *mc, MDB_page *mp)
 
static int mdb_cursor_del0 (MDB_cursor *mc)
 
static int mdb_del0 (MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data, unsigned flags)
 
static int mdb_cursor_sibling (MDB_cursor *mc, int move_right)
 
static int mdb_cursor_next (MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op)
 
static int mdb_cursor_prev (MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op)
 
static int mdb_cursor_set (MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op, int *exactp)
 
static int mdb_cursor_first (MDB_cursor *mc, MDB_val *key, MDB_val *data)
 
static int mdb_cursor_last (MDB_cursor *mc, MDB_val *key, MDB_val *data)
 
static void mdb_cursor_init (MDB_cursor *mc, MDB_txn *txn, MDB_dbi dbi, MDB_xcursor *mx)
 
static void mdb_xcursor_init0 (MDB_cursor *mc)
 
static void mdb_xcursor_init1 (MDB_cursor *mc, MDB_node *node)
 
static void mdb_xcursor_init2 (MDB_cursor *mc, MDB_xcursor *src_mx, int force)
 
static int mdb_drop0 (MDB_cursor *mc, int subs)
 
static void mdb_default_cmp (MDB_txn *txn, MDB_dbi dbi)
 
static int mdb_reader_check0 (MDB_env *env, int rlocked, int *dead)
 
char *ESECT mdb_version (int *major, int *minor, int *patch)
 Return the LMDB library version information. More...
 
char * mdb_strerror (int err)
 Return a string describing a given error code. More...
 
static void ESECT mdb_assert_fail (MDB_env *env, const char *expr_txt, const char *func, const char *file, int line)
 
int mdb_cmp (MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b)
 Compare two data items according to a particular database. More...
 
int mdb_dcmp (MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b)
 Compare two data items according to a particular database. More...
 
static MDB_page * mdb_page_malloc (MDB_txn *txn, unsigned num)
 
static void mdb_page_free (MDB_env *env, MDB_page *mp)
 
static void mdb_dpage_free (MDB_env *env, MDB_page *dp)
 
static void mdb_dlist_free (MDB_txn *txn)
 
static int mdb_page_loose (MDB_cursor *mc, MDB_page *mp)
 
static int mdb_pages_xkeep (MDB_cursor *mc, unsigned pflags, int all)
 
static int mdb_page_flush (MDB_txn *txn, int keep)
 
static int mdb_page_spill (MDB_cursor *m0, MDB_val *key, MDB_val *data)
 
static txnid_t mdb_find_oldest (MDB_txn *txn)
 
static void mdb_page_dirty (MDB_txn *txn, MDB_page *mp)
 
static void mdb_page_copy (MDB_page *dst, MDB_page *src, unsigned int psize)
 
static int mdb_page_unspill (MDB_txn *txn, MDB_page *mp, MDB_page **ret)
 
int mdb_env_sync (MDB_env *env, int force)
 Flush the data buffers to disk. More...
 
static int mdb_cursor_shadow (MDB_txn *src, MDB_txn *dst)
 
static void mdb_cursors_close (MDB_txn *txn, unsigned merge)
 
static int mdb_reader_pid (MDB_env *env, enum Pidlock_op op, MDB_PID_T pid)
 
static int mdb_txn_renew0 (MDB_txn *txn)
 
int mdb_txn_renew (MDB_txn *txn)
 Renew a read-only transaction. More...
 
int mdb_txn_begin (MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **ret)
 Create a transaction for use with the environment. More...
 
MDB_env * mdb_txn_env (MDB_txn *txn)
 Returns the transaction's MDB_env. More...
 
size_t mdb_txn_id (MDB_txn *txn)
 Return the transaction's ID. More...
 
static void mdb_dbis_update (MDB_txn *txn, int keep)
 
void mdb_txn_reset (MDB_txn *txn)
 Reset a read-only transaction. More...
 
void mdb_txn_abort (MDB_txn *txn)
 Abandon all the operations of the transaction instead of saving them. More...
 
static int mdb_freelist_save (MDB_txn *txn)
 
int mdb_txn_commit (MDB_txn *txn)
 Commit all the operations of a transaction into the database. More...
 
static void ESECT mdb_env_init_meta0 (MDB_env *env, MDB_meta *meta)
 
static int ESECT mdb_env_init_meta (MDB_env *env, MDB_meta *meta)
 
int ESECT mdb_env_create (MDB_env **env)
 Create an LMDB environment handle. More...
 
static int ESECT mdb_env_map (MDB_env *env, void *addr)
 
int ESECT mdb_env_set_mapsize (MDB_env *env, size_t size)
 Set the size of the memory map to use for this environment. More...
 
int ESECT mdb_env_set_maxdbs (MDB_env *env, MDB_dbi dbs)
 Set the maximum number of named databases for the environment. More...
 
int ESECT mdb_env_set_maxreaders (MDB_env *env, unsigned int readers)
 Set the maximum number of threads/reader slots for the environment. More...
 
int ESECT mdb_env_get_maxreaders (MDB_env *env, unsigned int *readers)
 Get the maximum number of threads/reader slots for the environment. More...
 
static int ESECT mdb_fsize (HANDLE fd, size_t *size)
 
static int ESECT mdb_fname_init (const char *path, unsigned envflags, MDB_name *fname)
 
static int ESECT mdb_fopen (const MDB_env *env, MDB_name *fname, enum mdb_fopen_type which, mdb_mode_t mode, HANDLE *res)
 
static int ESECT mdb_env_open2 (MDB_env *env)
 
static void mdb_env_reader_dest (void *ptr)
 
static int ESECT mdb_env_share_locks (MDB_env *env, int *excl)
 
static int ESECT mdb_env_excl_lock (MDB_env *env, int *excl)
 
static int ESECT mdb_env_setup_locks (MDB_env *env, MDB_name *fname, int mode, int *excl)
 
int ESECT mdb_env_open (MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode)
 Open an environment handle. More...
 
void ESECT mdb_env_close (MDB_env *env)
 Close the environment and release the memory map. More...
 
static int mdb_cmp_long (const MDB_val *a, const MDB_val *b)
 
static int mdb_cmp_int (const MDB_val *a, const MDB_val *b)
 
static int mdb_cmp_cint (const MDB_val *a, const MDB_val *b)
 
static int mdb_cmp_memn (const MDB_val *a, const MDB_val *b)
 
static int mdb_cmp_memnr (const MDB_val *a, const MDB_val *b)
 
static int mdb_page_search_lowest (MDB_cursor *mc)
 
static int mdb_ovpage_free (MDB_cursor *mc, MDB_page *mp)
 
int mdb_get (MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data)
 Get items from a database. More...
 
int mdb_cursor_get (MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op)
 Retrieve by cursor. More...
 
static int mdb_cursor_touch (MDB_cursor *mc)
 
int mdb_cursor_put (MDB_cursor *mc, MDB_val *key, MDB_val *data, unsigned int flags)
 Store by cursor. More...
 
int mdb_cursor_del (MDB_cursor *mc, unsigned int flags)
 Delete current key/data pair. More...
 
int mdb_cursor_open (MDB_txn *txn, MDB_dbi dbi, MDB_cursor **ret)
 Create a cursor handle. More...
 
int mdb_cursor_renew (MDB_txn *txn, MDB_cursor *mc)
 Renew a cursor handle. More...
 
int mdb_cursor_count (MDB_cursor *mc, size_t *countp)
 Return count of duplicates for current key. More...
 
void mdb_cursor_close (MDB_cursor *mc)
 Close a cursor handle. More...
 
MDB_txn * mdb_cursor_txn (MDB_cursor *mc)
 Return the cursor's transaction handle. More...
 
MDB_dbi mdb_cursor_dbi (MDB_cursor *mc)
 Return the cursor's database handle. More...
 
static void mdb_cursor_copy (const MDB_cursor *csrc, MDB_cursor *cdst)
 
int mdb_del (MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data)
 Delete items from a database. More...
 
int mdb_put (MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data, unsigned int flags)
 Store items into a database. More...
 
static THREAD_RET ESECT CALL_CONV mdb_env_copythr (void *arg)
 
static int ESECT mdb_env_cthr_toggle (mdb_copy *my, int adjust)
 
static int ESECT mdb_env_cwalk (mdb_copy *my, pgno_t *pg, int flags)
 
static int ESECT mdb_env_copyfd1 (MDB_env *env, HANDLE fd)
 
static int ESECT mdb_env_copyfd0 (MDB_env *env, HANDLE fd)
 
int ESECT mdb_env_copyfd2 (MDB_env *env, HANDLE fd, unsigned int flags)
 
int ESECT mdb_env_copyfd (MDB_env *env, HANDLE fd)
 
int ESECT mdb_env_copy2 (MDB_env *env, const char *path, unsigned int flags)
 Copy an LMDB environment to the specified path, with options. More...
 
int ESECT mdb_env_copy (MDB_env *env, const char *path)
 Copy an LMDB environment to the specified path. More...
 
int ESECT mdb_env_set_flags (MDB_env *env, unsigned int flag, int onoff)
 Set environment flags. More...
 
int ESECT mdb_env_get_flags (MDB_env *env, unsigned int *arg)
 Get environment flags. More...
 
int ESECT mdb_env_set_userctx (MDB_env *env, void *ctx)
 Set application information associated with the MDB_env. More...
 
void *ESECT mdb_env_get_userctx (MDB_env *env)
 Get the application information associated with the MDB_env. More...
 
int ESECT mdb_env_set_assert (MDB_env *env, MDB_assert_func *func)
 
int ESECT mdb_env_get_path (MDB_env *env, const char **arg)
 Return the path that was used in mdb_env_open(). More...
 
int ESECT mdb_env_get_fd (MDB_env *env, mdb_filehandle_t *arg)
 Return the filedescriptor for the given environment. More...
 
static int ESECT mdb_stat0 (MDB_env *env, MDB_db *db, MDB_stat *arg)
 
int ESECT mdb_env_stat (MDB_env *env, MDB_stat *arg)
 Return statistics about the LMDB environment. More...
 
int ESECT mdb_env_info (MDB_env *env, MDB_envinfo *arg)
 Return information about the LMDB environment. More...
 
int mdb_dbi_open (MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi)
 Open a database in the environment. More...
 
int ESECT mdb_stat (MDB_txn *txn, MDB_dbi dbi, MDB_stat *arg)
 Retrieve statistics for a database. More...
 
void mdb_dbi_close (MDB_env *env, MDB_dbi dbi)
 Close a database handle. Normally unnecessary. Use with care: More...
 
int mdb_dbi_flags (MDB_txn *txn, MDB_dbi dbi, unsigned int *flags)
 Retrieve the DB flags for a database handle. More...
 
int mdb_drop (MDB_txn *txn, MDB_dbi dbi, int del)
 Empty or delete+close a database. More...
 
int mdb_set_compare (MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp)
 Set a custom key comparison function for a database. More...
 
int mdb_set_dupsort (MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp)
 Set a custom data comparison function for a MDB_DUPSORT database. More...
 
int mdb_set_relfunc (MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel)
 Set a relocation function for a MDB_FIXEDMAP database. More...
 
int mdb_set_relctx (MDB_txn *txn, MDB_dbi dbi, void *ctx)
 Set a context pointer for a MDB_FIXEDMAP database's relocation function. More...
 
int ESECT mdb_env_get_maxkeysize (MDB_env *env)
 Get the maximum size of keys and MDB_DUPSORT data we can write. More...
 
int ESECT mdb_reader_list (MDB_env *env, MDB_msg_func *func, void *ctx)
 Dump the entries in the reader lock table. More...
 
static int ESECT mdb_pid_insert (MDB_PID_T *ids, MDB_PID_T pid)
 
int ESECT mdb_reader_check (MDB_env *env, int *dead)
 Check for stale entries in the reader lock table. More...
 

Variables

static char *const mdb_errstr []
 
static const mdb_nchar_t *const mdb_suffixes [2][2]
 

Detailed Description


Data Structure Documentation

◆ MDB_page

struct MDB_page

Common header for all page types. The page type depends on mp_flags.

P_BRANCH and P_LEAF pages have unsorted 'MDB_node's at the end, with sorted mp_ptrs[] entries referring to them. Exception: P_LEAF2 pages omit mp_ptrs and pack sorted MDB_DUPFIXED values after the page header.

P_OVERFLOW records occupy one or more contiguous pages where only the first has a page header. They hold the real data of F_BIGDATA nodes.

P_SUBP sub-pages are small leaf "pages" with duplicate data. A node with flag F_DUPDATA but not F_SUBDATA contains a sub-page. (Duplicate data can also go in sub-databases, which use normal pages.)

P_META pages contain MDB_meta, the start point of an LMDB snapshot.

Each non-metapage up to MDB_meta.mm_last_pg is reachable exactly once in the snapshot: Either used by a database or listed in a freeDB record.

Data Fields

union {
   pgno_t   p_pgno
 
   struct MDB_page *   p_next
 
} mp_p
 
uint16_t mp_pad
 
uint16_t mp_flags
 
union {
   struct {
      indx_t   pb_lower
 
      indx_t   pb_upper
 
   }   pb
 
   uint32_t   pb_pages
 
} mp_pb
 
indx_t mp_ptrs [1]
 

Field Documentation

◆ p_pgno

pgno_t MDB_page::p_pgno

page number

◆ p_next

struct MDB_page* MDB_page::p_next

for in-memory list of freed pages

◆ mp_pad

uint16_t MDB_page::mp_pad

key size if this is a LEAF2 page

◆ mp_flags

uint16_t MDB_page::mp_flags

◆ pb_lower

indx_t MDB_page::pb_lower

lower bound of free space

◆ pb_upper

indx_t MDB_page::pb_upper

upper bound of free space

◆ pb_pages

uint32_t MDB_page::pb_pages

number of overflow pages

◆ mp_ptrs

indx_t MDB_page::mp_ptrs[1]

dynamic size

◆ MDB_node

struct MDB_node

Header for a single key/data pair within a page. Used in pages of type P_BRANCH and P_LEAF without P_LEAF2. We guarantee 2-byte alignment for 'MDB_node's.

mn_lo and mn_hi are used for data size on leaf nodes, and for child pgno on branch nodes. On 64 bit platforms, mn_flags is also used for pgno. (Branch nodes have no flags). Lo and hi are in host byte order in case some accesses can be optimized to 32-bit word access.

Leaf node flags describe node contents. F_BIGDATA says the node's data part is the page number of an overflow page with actual data. F_DUPDATA and F_SUBDATA can be combined giving duplicate data in a sub-page/sub-database, and named databases (just F_SUBDATA).

Data Fields

unsigned short mn_flags
 
unsigned short mn_ksize
 
char mn_data [1]
 
unsigned short mn_lo
 
unsigned short mn_hi
 

Field Documentation

◆ mn_lo

unsigned short MDB_node::mn_lo

part of data size or pgno

◆ mn_hi

unsigned short MDB_node::mn_hi

part of data size or pgno

◆ mn_flags

unsigned short MDB_node::mn_flags

◆ mn_ksize

unsigned short MDB_node::mn_ksize

key size

◆ mn_data

char MDB_node::mn_data[1]

key and data are appended here

◆ MDB_db

struct MDB_db

Information about a single database in the environment.

Data Fields

uint32_t md_pad
 
uint16_t md_flags
 
uint16_t md_depth
 
pgno_t md_branch_pages
 
pgno_t md_leaf_pages
 
pgno_t md_overflow_pages
 
size_t md_entries
 
pgno_t md_root
 

Field Documentation

◆ md_pad

uint32_t MDB_db::md_pad

also ksize for LEAF2 pages

◆ md_flags

uint16_t MDB_db::md_flags

◆ md_depth

uint16_t MDB_db::md_depth

depth of this tree

◆ md_branch_pages

pgno_t MDB_db::md_branch_pages

number of internal pages

◆ md_leaf_pages

pgno_t MDB_db::md_leaf_pages

number of leaf pages

◆ md_overflow_pages

pgno_t MDB_db::md_overflow_pages

number of overflow pages

◆ md_entries

size_t MDB_db::md_entries

number of data items

◆ md_root

pgno_t MDB_db::md_root

the root page of this tree

◆ MDB_meta

struct MDB_meta

Meta page content. A meta page is the start point for accessing a database snapshot. Pages 0-1 are meta pages. Transaction N writes meta page #(N % 2).

Data Fields

uint32_t mm_magic
 
uint32_t mm_version
 
void * mm_address
 
size_t mm_mapsize
 
MDB_db mm_dbs [CORE_DBS]
 
pgno_t mm_last_pg
 
volatile txnid_t mm_txnid
 

Field Documentation

◆ mm_magic

uint32_t MDB_meta::mm_magic

Stamp identifying this as an LMDB file. It must be set to MDB_MAGIC.

◆ mm_version

uint32_t MDB_meta::mm_version

Version number of this file. Must be set to MDB_DATA_VERSION.

◆ mm_address

void* MDB_meta::mm_address

address for fixed mapping

◆ mm_mapsize

size_t MDB_meta::mm_mapsize

size of mmap region

◆ mm_dbs

MDB_db MDB_meta::mm_dbs[CORE_DBS]

first is free space, 2nd is main db

◆ mm_last_pg

pgno_t MDB_meta::mm_last_pg

Last used page in the datafile. Actually the file may be shorter if the freeDB lists the final pages.

◆ mm_txnid

volatile txnid_t MDB_meta::mm_txnid

txnid that committed this page

◆ MDB_metabuf

union MDB_metabuf

Buffer for a stack-allocated meta page. The members define size and alignment, and silence type aliasing warnings. They are not used directly; that could mean incorrectly using several union members in parallel.

Data Fields

MDB_page mb_page
 
struct {
   char   mm_pad [PAGEHDRSZ]
 
   MDB_meta   mm_meta
 
} mb_metabuf
 

◆ MDB_dbx

struct MDB_dbx

Auxiliary DB info. The information here is mostly static/read-only. There is only a single copy of this record in the environment.

Data Fields

MDB_val md_name
 
MDB_cmp_func * md_cmp
 
MDB_cmp_func * md_dcmp
 
MDB_rel_func * md_rel
 
void * md_relctx
 

Field Documentation

◆ md_name

MDB_val MDB_dbx::md_name

name of the database

◆ md_cmp

MDB_cmp_func* MDB_dbx::md_cmp

function for comparing keys

◆ md_dcmp

MDB_cmp_func* MDB_dbx::md_dcmp

function for comparing data items

◆ md_rel

MDB_rel_func* MDB_dbx::md_rel

user relocate function

◆ md_relctx

void* MDB_dbx::md_relctx

user-provided context for md_rel

◆ MDB_txn

struct MDB_txn

Opaque structure for a transaction handle.

A database transaction. Every operation requires a transaction handle.

All database operations require a transaction handle. Transactions may be read-only or read-write.

Data Fields

MDB_txn * mt_parent
 
MDB_txn * mt_child
 
pgno_t mt_next_pgno
 
txnid_t mt_txnid
 
MDB_env * mt_env
 
MDB_IDL mt_free_pgs
 
MDB_page * mt_loose_pgs
 
int mt_loose_count
 
MDB_IDL mt_spill_pgs
 
union {
   MDB_ID2L   dirty_list
 
   MDB_reader *   reader
 
} mt_u
 
MDB_dbx * mt_dbxs
 
MDB_db * mt_dbs
 
unsigned int * mt_dbiseqs
 
MDB_cursor ** mt_cursors
 
unsigned char * mt_dbflags
 
MDB_dbi mt_numdbs
 
unsigned int mt_flags
 
unsigned int mt_dirty_room
 

Field Documentation