mdb.c(3)

✨ mdb.c(3) β€” NAME ✨

okay bestie, this is the manual page for mdb.c(3), and it’s all about the Lightning memory-mapped database library. πŸ’–

mdb.c β€” Lightning memory-mapped database library. periodt. πŸ’…


✨ SYNOPSIS ✨

fr fr, bestie, you gotta include these headers or nothing compiles. no cap. ✨

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/uio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <netinet/in.h>
#include <resolv.h>
#include <pthread.h>
#include <signal.h>
#include 'lmdb.h'
#include 'midl.h'

✨ Data Structures ✨

the whole cast, in order, no skips. 🫢

  • struct MDB_rxbody
  • struct MDB_reader
  • struct MDB_txbody
  • struct MDB_txninfo
  • struct MDB_page
  • struct MDB_page2
  • struct MDB_node
  • struct MDB_db
  • struct MDB_meta
  • union MDB_metabuf
  • struct MDB_dbx
  • struct MDB_txn β€” opaque structure for a transaction handle. iykyk, don’t peek behind the curtain πŸ’…
  • struct MDB_cursor β€” opaque structure for navigating through a database. so you can scroll the data, bestie ✨
  • struct MDB_xcursor
  • struct MDB_pgstate
  • struct MDB_env β€” opaque structure for a database environment. the whole vibe container 🫢
  • struct MDB_ntxn
  • struct MDB_name
  • struct mdb_copy

✨ Macros ✨

the macro drawer is DEEP. every single #define from the page, exactly as written, no edits, no cap: πŸ”₯

#define _GNU_SOURCE   1
#define MDB_PID_T   pid_t
#define MDB_THR_T   pthread_t
#define CACHEFLUSH(addr,  bytes,  cache)
#define MDB_USE_POSIX_MUTEX   1
#define VGMEMP_CREATE(h,  r,  z)
#define VGMEMP_ALLOC(h,  a,  s)
#define VGMEMP_FREE(h,  a)
#define VGMEMP_DESTROY(h)
#define VGMEMP_DEFINED(a,  s)
#define BYTE_ORDER   __BYTE_ORDER
#define LITTLE_ENDIAN   __LITTLE_ENDIAN
#define BIG_ENDIAN   __BIG_ENDIAN
#define ESECT   __attribute__ ((section('text_env')))
#define CALL_CONV
#define MDB_DEVEL   0
#define mdb_func_   '<mdb_unknown>'
#define MDB_NO_ROOT   (MDB_LAST_ERRCODE + 10)
#define MDB_USE_ROBUST   1
#define THREAD_RET   void *
#define THREAD_CREATE(thr,  start,  arg)
#define THREAD_FINISH(thr)
#define Z   'z'
#define MDB_PIDLOCK   1
#define LOCK_MUTEX0(mutex)
#define UNLOCK_MUTEX(mutex)
#define mdb_mutex_consistent(mutex)
#define ErrCode()
#define HANDLE   int
#define INVALID_HANDLE_VALUE   (-1)
#define GET_PAGESIZE(x)
#define MNAME_LEN   (sizeof(pthread_mutex_t))
#define LOCK_MUTEX(rc,  env,  mutex)
#define mdb_mutex_failed(env,  mutex,  rc)
#define MDB_DSYNC   O_SYNC
#define MDB_FDATASYNC   fdatasync
#define MDB_MSYNC(addr,  len,  flags)
#define MS_SYNC   1
#define MS_ASYNC   0
#define MDB_DEBUG   0
#define MDB_DBG_INFO   1
#define MDB_DBG_TRACE   2
#define DPRINTF(args)
#define MDB_TRACE(args)
#define DPUTS(arg)
#define DDBI(mc)
#define MAX_PAGESIZE   (PAGEBASE ? 0x10000 : 0x8000)
#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)
#define ENV_MAXKEY(env)
#define MAXDATASIZE   0xffffffffUL
#define DKBUF
#define DDBUF
#define DKEY(x)
#define P_INVALID   (~(pgno_t)0)
#define F_ISSET(w,  f)
#define EVEN(n)
#define DEFAULT_MAPSIZE   1048576
#define DEFAULT_READERS   126
#define CACHELINE   64
#define mr_txnid   mru.mrx.mrb_txnid
#define mr_pid   mru.mrx.mrb_pid
#define mr_tid   mru.mrx.mrb_tid
#define mti_magic   mt1.mtb.mtb_magic
#define mti_format   mt1.mtb.mtb_format
#define mti_rmutex   mt1.mtb.mtb_rmutex
#define mti_rmname   mt1.mtb.mtb_rmname
#define mti_txnid   mt1.mtb.mtb_txnid
#define mti_numreaders   mt1.mtb.mtb_numreaders
#define mti_wmutex   mt2.mt2_wmutex
#define MDB_LOCK_FORMAT
#define mp_pgno   mp_p.p_pgno
#define mp_next   mp_p.p_next
#define P_BRANCH   0x01
#define P_LEAF   0x02
#define P_OVERFLOW   0x04
#define P_META   0x08
#define P_DIRTY   0x10
#define P_LEAF2   0x20
#define P_SUBP   0x40
#define P_LOOSE   0x4000
#define P_KEEP   0x8000
#define mp_lower   mp_pb.pb.pb_lower
#define mp_upper   mp_pb.pb.pb_upper
#define mp_pages   mp_pb.pb_pages
#define MP_PGNO(p)
#define MP_PAD(p)
#define MP_FLAGS(p)
#define MP_LOWER(p)
#define MP_UPPER(p)
#define MP_PTRS(p)
#define PAGEHDRSZ   ((unsigned) offsetof(MDB_page, mp_ptrs))
#define METADATA(p)
#define PAGEBASE   ((MDB_DEVEL) ? PAGEHDRSZ : 0)
#define NUMKEYS(p)
#define SIZELEFT(p)
#define PAGEFILL(env,  p)
#define FILL_THRESHOLD   250
#define IS_LEAF(p)
#define IS_LEAF2(p)
#define IS_BRANCH(p)
#define IS_OVERFLOW(p)
#define IS_SUBP(p)
#define OVPAGES(size,  psize)
#define NEXT_LOOSE_PAGE(p)
#define F_BIGDATA   0x01
#define F_SUBDATA   0x02
#define F_DUPDATA   0x04
#define NODE_ADD_FLAGS   (F_DUPDATA|F_SUBDATA|MDB_RESERVE|MDB_APPEND)
#define NODESIZE   offsetof(MDB_node, mn_data)
#define PGNO_TOPWORD   ((pgno_t)-1 > 0xffffffffu ? 32 : 0)
#define INDXSIZE(k)
#define LEAFSIZE(k,  d)
#define NODEPTR(p,  i)
#define NODEKEY(node)
#define NODEDATA(node)
#define NODEPGNO(node)
#define SETPGNO(node,  pgno)
#define NODEDSZ(node)
#define SETDSZ(node,  size)
#define NODEKSZ(node)
#define COPY_PGNO(dst,  src)
#define LEAF2KEY(p,  i,  ks)
#define MDB_GET_KEY(node,  keyptr)
#define MDB_GET_KEY2(node,  key)
#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 mm_psize   mm_dbs[FREE_DBI].md_pad
#define mm_flags   mm_dbs[FREE_DBI].md_flags
#define DB_DIRTY   0x01
#define DB_STALE   0x02
#define DB_NEW   0x04
#define DB_VALID   0x08
#define DB_USRVALID   0x10
#define DB_DUPDATA   0x20
#define MDB_TXN_BEGIN_FLAGS   MDB_RDONLY
#define MDB_TXN_RDONLY   MDB_RDONLY
#define MDB_TXN_WRITEMAP   MDB_WRITEMAP
#define MDB_TXN_FINISHED   0x01
#define MDB_TXN_ERROR   0x02
#define MDB_TXN_DIRTY   0x04
#define MDB_TXN_SPILLS   0x08
#define MDB_TXN_HAS_CHILD   0x10
#define MDB_TXN_BLOCKED
    (MDB_TXN_FINISHED|MDB_TXN_ERROR|MDB_TXN_HAS_CHILD)
#define CURSOR_STACK   32
#define C_INITIALIZED   0x01
#define C_EOF   0x02
#define C_SUB   0x04
#define C_DEL   0x08
#define C_UNTRACK   0x40
#define XCURSOR_INITED(mc)
#define XCURSOR_REFRESH(mc,  top,  mp)
#define MDB_FATAL_ERROR   0x80000000U
#define MDB_ENV_ACTIVE   0x20000000U
#define MDB_ENV_TXKEY   0x10000000U
#define MDB_FSYNCONLY   0x08000000U
#define me_pglast   me_pgstate.mf_pglast
#define me_pghead   me_pgstate.mf_pghead
#define me_rmutex   me_txns->mti_rmutex
#define me_wmutex   me_txns->mti_wmutex
#define MDB_COMMIT_PAGES   64
#define MAX_WRITE   (0x40000000U >> (sizeof(ssize_t) == 4))
#define TXN_DBI_EXIST(txn,  dbi,  validity)
#define TXN_DBI_CHANGED(txn,  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)
#define mdb_cmp_clong   mdb_cmp_cint
#define mdb_cassert(mc,  expr)
#define mdb_tassert(txn,  expr)
#define mdb_eassert(env,  expr)
#define mdb_assert0(env,  expr,  expr_txt)
#define DO_PWRITE(rc,  fd,  ptr,  size,  len,  pos)
#define MDB_NAME(str)
#define mdb_name_cpy   strcpy
#define MDB_SUFFLEN   9
#define mdb_fname_destroy(fname)
#define MDB_CLOEXEC   0
#define MDB_ERRCODE_ROFS   EROFS
#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
#define DO_WRITE(rc,  fd,  ptr,  w2,  len)
#define DO_WRITE(rc,  fd,  ptr,  w2,  len)

and the page also drops lore for these three:

  • MAX_PAGESIZE β€” The maximum size of a database page. (value: (PAGEBASE ? 0x10000 : 0x8000))
  • MDB_MAXKEYSIZE β€” The max size of a key we can write, or 0 for computed max. (value: ((MDB_DEVEL) ? 0 : 511))
  • MAXDATASIZE β€” The maximum size of a data item. (value: 0xffffffffUL)

✨ Typedefs ✨

the typedefs, exactly as given. πŸ’–

typedef pthread_mutex_t mdb_mutex_t[1]
typedef pthread_mutex_t * mdb_mutexref_t
typedef MDB_ID pgno_t
typedef MDB_ID txnid_t
typedef uint16_t indx_t
typedef char mdb_nchar_t

✨ Enumerations ✨

enum energy, exactly as written. no cap. 🌈

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 ✨

bestie, this is the whole function lineup. some are static (LMDB's own little helpers πŸ’…), some are the public API you actually call. all of them matter, so here we go 🫢

  • 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_del (MDB_cursor *mc, unsigned int flags)
  • static int _mdb_cursor_put (MDB_cursor *mc, MDB_val *key, MDB_val *data, unsigned int flags)
  • 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) β€” returns the LMDB library version information 😍 you love to see it
  • char * mdb_strerror (int err) β€” returns a string describing a given error code ✨ so you know what went wrong
  • 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) β€” compares two data items according to a particular database πŸ’…
  • int mdb_dcmp (MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b) β€” compares two data items according to a particular database πŸŽ€
  • 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) β€” flushes the data buffers to disk 🌊 make it persist, bestie
  • 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) β€” renews a read-only transaction πŸ”„
  • int mdb_txn_begin (MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **ret) β€” creates a transaction for use with the environment πŸ‘‘
  • MDB_env * mdb_txn_env (MDB_txn *txn) β€” returns the transaction's MDB_env πŸ’–
  • size_t mdb_txn_id (MDB_txn *txn) β€” returns the transaction's ID πŸ”’
  • static void mdb_dbis_update (MDB_txn *txn, int keep)
  • void mdb_txn_reset (MDB_txn *txn) β€” resets a read-only transaction 🧼
  • static void _mdb_txn_abort (MDB_txn *txn)
  • void mdb_txn_abort (MDB_txn *txn) β€” abandons all the operations of the transaction instead of saving them πŸ’€ no take-backs
  • static int mdb_freelist_save (MDB_txn *txn)
  • static int _mdb_txn_commit (MDB_txn *txn)
  • int mdb_txn_commit (MDB_txn *txn) β€” commits all the operations of a transaction into the database βœ… periodt
  • 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) β€” creates an LMDB environment handle 🌱
  • static int ESECT mdb_env_map (MDB_env *env, void *addr)
  • int ESECT mdb_env_set_mapsize (MDB_env *env, size_t size) β€” sets the size of the memory map to use for this environment πŸ“
  • int ESECT mdb_env_set_maxdbs (MDB_env *env, MDB_dbi dbs) β€” sets the maximum number of named databases for the environment πŸ—‚οΈ
  • int ESECT mdb_env_set_maxreaders (MDB_env *env, unsigned int readers) β€” sets the maximum number of threads/reader slots for the environment 🧡
  • int ESECT mdb_env_get_maxreaders (MDB_env *env, unsigned int *readers) β€” gets the maximum number of threads/reader slots for the environment πŸ”
  • 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) β€” opens an environment handle πŸšͺ
  • void ESECT mdb_env_close (MDB_env *env) β€” closes the environment and releases the memory map 🧹
  • 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) β€” gets items from a database πŸ“₯
  • int mdb_cursor_get (MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op) β€” retrieves by cursor πŸ–±οΈ
  • static int mdb_cursor_touch (MDB_cursor *mc)
  • int mdb_cursor_put (MDB_cursor *mc, MDB_val *key, MDB_val *data, unsigned int flags) β€” stores by cursor πŸ“€
  • int mdb_cursor_del (MDB_cursor *mc, unsigned int flags) β€” deletes current key/data pair βœ‚οΈ
  • int mdb_cursor_open (MDB_txn *txn, MDB_dbi dbi, MDB_cursor **ret) β€” creates a cursor handle 🎯
  • int mdb_cursor_renew (MDB_txn *txn, MDB_cursor *mc) β€” renews a cursor handle πŸ”
  • int mdb_cursor_count (MDB_cursor *mc, size_t *countp) β€” returns count of duplicates for current key πŸ”’
  • void mdb_cursor_close (MDB_cursor *mc) β€” closes a cursor handle πŸšͺ
  • MDB_txn * mdb_cursor_txn (MDB_cursor *mc) β€” returns the cursor's transaction handle πŸ’³
  • MDB_dbi mdb_cursor_dbi (MDB_cursor *mc) β€” returns the cursor's database handle πŸ—„οΈ
  • 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) β€” deletes items from a database πŸ—‘οΈ
  • int mdb_put (MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data, unsigned int flags) β€” stores items into a database πŸ’Ύ
  • 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) β€” copies an LMDB environment to the specified path, with options πŸ“‹
  • int ESECT mdb_env_copy (MDB_env *env, const char *path) β€” copies an LMDB environment to the specified path πŸ“
  • int ESECT mdb_env_set_flags (MDB_env *env, unsigned int flag, int onoff) β€” sets environment flags 🚩
  • int ESECT mdb_env_get_flags (MDB_env *env, unsigned int *arg) β€” gets environment flags 🏁
  • int ESECT mdb_env_set_userctx (MDB_env *env, void *ctx) β€” sets application information associated with the MDB_env 🏷️
  • void *ESECT mdb_env_get_userctx (MDB_env *env) β€” gets the application information associated with the MDB_env πŸ”–
  • 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) β€” returns the path that was used in mdb_env_open() πŸ›€οΈ
  • int ESECT mdb_env_get_fd (MDB_env *env, mdb_filehandle_t *arg) β€” returns the filedescriptor for the given environment πŸ”Œ
  • 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) β€” returns statistics about the LMDB environment πŸ“Š
  • int ESECT mdb_env_info (MDB_env *env, MDB_envinfo *arg) β€” returns information about the LMDB environment ℹ️
  • int mdb_dbi_open (MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi) β€” opens a database in the environment πŸ”“

So yeah, the function list keeps going β€” here's the rest of them, no gatekeeping πŸ’–

  • int ESECT mdb_stat (MDB_txn *txn, MDB_dbi dbi, MDB_stat *arg) β€” grabs the statistics for a database and drops them into arg πŸ“Š
  • void mdb_dbi_close (MDB_env *env, MDB_dbi dbi) β€” closes a database handle. Normally unnecessary β€” like, usually you don't need this AT ALL. Use with care:
  • int mdb_dbi_flags (MDB_txn *txn, MDB_dbi dbi, unsigned int *flags) β€” fishes out the DB flags for a database handle 🚩
  • int mdb_drop (MDB_txn *txn, MDB_dbi dbi, int del) β€” empties a database, or straight up deletes + closes it πŸ’€
  • int mdb_set_compare (MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp) β€” sets a custom key comparison function for a database πŸ”
  • int mdb_set_dupsort (MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp) β€” sets a custom data comparison function for a MDB_DUPSORT database ✨
  • int mdb_set_relfunc (MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel) β€” sets a relocation function for a MDB_FIXEDMAP database πŸ“¦
  • int mdb_set_relctx (MDB_txn *txn, MDB_dbi dbi, void *ctx) β€” sets a context pointer for a MDB_FIXEDMAP database's relocation function 🧷
  • int ESECT mdb_env_get_maxkeysize (MDB_env *env) β€” the max size of keys AND MDB_DUPSORT data that we can actually write πŸ“
  • int ESECT mdb_reader_list (MDB_env *env, MDB_msg_func *func, void *ctx) β€” dumps all the entries in the reader lock table πŸ—‚οΈ
  • static int ESECT mdb_pid_insert (MDB_PID_T *ids, MDB_PID_T pid) β€” bestie, the docs literally give this one no description. It is just sitting there, unbothered, in the list πŸ™ˆ
  • int ESECT mdb_reader_check (MDB_env *env, int *dead) β€” checks for stale entries in the reader lock table 🧹

✨ Variables ✨

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

πŸ¦‹ Detailed Description πŸ¦‹

Lightning memory-mapped database library. βš‘πŸ—„οΈ

A Btree-based database management library modeled loosely on the BerkeleyDB API, but much simplified. (loosely!! simplified!! we love a glow-down that's actually a glow-up πŸ’…)


πŸ’… Macro Definition Documentation πŸ’…

#define mr_txnid mru.mrx.mrb_txnid

shorthand for mrb_txnid βœ‚οΈ

#define mm_psize mm_dbs[FREE_DBI].md_pad

The size of pages used in this DB πŸ“

#define mm_flags mm_dbs[FREE_DBI].md_flags

Any persistent environment flags. Environment Flags 🚩

#define MDB_FATAL_ERROR 0x80000000U

Failed to update the meta page. Probably an I/O error. 😱

#define MDB_ENV_ACTIVE 0x20000000U

Some fields are initialized. βœ…

#define MDB_ENV_TXKEY 0x10000000U

me_txkey is set πŸ”‘

#define MDB_FSYNCONLY 0x08000000U

fdatasync is unreliable 😬

#define me_rmutex me_txns->mti_rmutex

Shared reader lock πŸ”’

#define me_wmutex me_txns->mti_wmutex

Shared writer lock πŸ”

#define DO_PWRITE( rc, fd, ptr, size, len, pos)

Value:

do { \
len = pwrite(fd, ptr, size, pos);   \
if (len == -1 && ErrCode() == EINTR) continue; \
rc = (len >= 0); break; } while(1)

#define DO_WRITE( rc, fd, ptr, w2, len)

Value:

len = write(fd, ptr, w2); rc = (len >= 0)

#define DO_WRITE( rc, fd, ptr, w2, len)

Value:

len = write(fd, ptr, w2); rc = (len >= 0)
Not a typo, bestie β€” DO_WRITE really does show up twice in the docs, same signature, same value, twice. The docs said it twice so I'm saying it twice. Periodt. πŸ’€βœ¨

πŸ‘‘ Author πŸ‘‘

Generated automatically by Doxygen for LMDB from the source code. πŸ€–πŸ’–


aaaand that's a wrap on the whole thing, fr fr πŸŽ€ this was the LMDB manual page, the one and only mdb.c(3), auto-generated straight out of the source code with Doxygen πŸ’« thanks for reading all the way to the bottom with me, you're literally the main character πŸ‘‘πŸ’œ

πŸ“¦ where this page comes from