mdbx: rename the rest MDBX_xyz.

This commit is contained in:
Leo Yuriev
2017-05-24 01:42:10 +03:00
parent 62ebc59330
commit 06de7a5155
30 changed files with 1993 additions and 1974 deletions

View File

@@ -70,11 +70,11 @@
#include "./osal.h"
#ifndef MDB_DEBUG
# define MDB_DEBUG 0
#ifndef MDBX_DEBUG
# define MDBX_DEBUG 0
#endif
#if MDB_DEBUG
#if MDBX_DEBUG
# undef NDEBUG
#endif
@@ -168,19 +168,19 @@ typedef uint64_t txnid_t;
* IDs are in the list. In the original back-bdb code, IDLs are
* sorted in ascending order. For libmdb IDLs are sorted in
* descending order. */
typedef pgno_t *MDB_IDL;
typedef pgno_t *MDBX_IDL;
/* An ID2 is an ID/pointer pair. */
typedef struct MDB_ID2 {
typedef struct MDBX_ID2 {
pgno_t mid; /* The ID */
void *mptr; /* The pointer */
} MDB_ID2;
} MDBX_ID2;
/* An ID2L is an ID2 List, a sorted array of ID2s.
* The first element's mid member is a count of how many actual
* elements are in the array. The mptr member of the first element is
* unused. The array is sorted in ascending order by mid. */
typedef MDB_ID2 *MDB_ID2L;
typedef MDBX_ID2 *MDBX_ID2L;
/* Used for offsets within a single page.
* Since memory pages are typically 4 or 8KB in size, 12-13 bits,
@@ -220,7 +220,7 @@ typedef struct MDBX_reader {
} MDBX_reader;
/* Information about a single database in the environment. */
typedef struct MDB_db {
typedef struct MDBX_db {
uint32_t md_xsize; /* also ksize for LEAF2 pages */
uint16_t md_flags; /* see mdbx_dbi_open */
uint16_t md_depth; /* depth of this tree */
@@ -230,20 +230,20 @@ typedef struct MDB_db {
pgno_t md_overflow_pages; /* number of overflow pages */
pgno_t md_root; /* the root page of this tree */
uint64_t md_entries; /* number of data items */
} MDB_db;
} MDBX_db;
/* 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). */
typedef struct MDB_meta {
/* Stamp identifying this as an LMDB file. It must be set
* to MDB_MAGIC. */
typedef struct MDBX_meta {
/* Stamp identifying this as an MDBX file. It must be set
* to MDBX_MAGIC. */
uint32_t mm_magic;
/* Version number of this file. Must be set to MDB_DATA_VERSION. */
/* Version number of this file. Must be set to MDBX_DATA_VERSION. */
uint32_t mm_version;
size_t mm_mapsize; /* size of mmap region */
MDB_db mm_dbs[CORE_DBS]; /* first is free space, 2nd is main db */
/* The size of pages used in this DB */
size_t mm_mapsize; /* size of mmap region */
MDBX_db mm_dbs[CORE_DBS]; /* first is free space, 2nd is main db */
/* The size of pages used in this DB */
#define mm_psize mm_dbs[FREE_DBI].md_xsize
/* Any persistent environment flags, see mdbx_env */
#define mm_flags mm_dbs[FREE_DBI].md_flags
@@ -251,21 +251,21 @@ typedef struct MDB_meta {
* Actually the file may be shorter if the freeDB lists the final pages. */
pgno_t mm_last_pg;
volatile txnid_t mm_txnid; /* txnid that committed this page */
#define MDB_DATASIGN_NONE 0u
#define MDB_DATASIGN_WEAK 1u
#define MDBX_DATASIGN_NONE 0u
#define MDBX_DATASIGN_WEAK 1u
volatile uint64_t mm_datasync_sign;
#define SIGN_IS_WEAK(sign) ((sign) == MDB_DATASIGN_WEAK)
#define SIGN_IS_STEADY(sign) ((sign) > MDB_DATASIGN_WEAK)
#define SIGN_IS_WEAK(sign) ((sign) == MDBX_DATASIGN_WEAK)
#define SIGN_IS_STEADY(sign) ((sign) > MDBX_DATASIGN_WEAK)
#define META_IS_WEAK(meta) SIGN_IS_WEAK((meta)->mm_datasync_sign)
#define META_IS_STEADY(meta) SIGN_IS_STEADY((meta)->mm_datasync_sign)
volatile mdbx_canary mm_canary;
} MDB_meta;
} MDBX_meta;
/* Common header for all page types. The page type depends on mp_flags.
*
* P_BRANCH and P_LEAF pages have unsorted 'MDBX_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.
* omit mp_ptrs and pack sorted MDBX_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.
@@ -274,9 +274,9 @@ typedef struct MDB_meta {
* 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.
* P_META pages contain MDBX_meta, the start point of an MDBX snapshot.
*
* Each non-metapage up to MDB_meta.mm_last_pg is reachable exactly once
* Each non-metapage up to MDBX_meta.mm_last_pg is reachable exactly once
* in the snapshot: Either used by a database or listed in a freeDB record. */
typedef struct MDBX_page {
union {
@@ -289,8 +289,8 @@ typedef struct MDBX_page {
#define P_OVERFLOW 0x04 /* overflow page */
#define P_META 0x08 /* meta page */
#define P_DIRTY 0x10 /* dirty page, also set for P_SUBP pages */
#define P_LEAF2 0x20 /* for MDB_DUPFIXED records */
#define P_SUBP 0x40 /* for MDB_DUPSORT sub-pages */
#define P_LEAF2 0x20 /* for MDBX_DUPFIXED records */
#define P_SUBP 0x40 /* for MDBX_DUPSORT sub-pages */
#define P_LOOSE 0x4000 /* page was dirtied then freed, can be reused */
#define P_KEEP 0x8000 /* leave this page alone during spill */
uint16_t mp_flags;
@@ -311,19 +311,19 @@ typedef struct MDBX_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. */
typedef union MDB_metabuf {
typedef union MDBX_metabuf {
MDBX_page mb_page;
struct {
char mm_pad[PAGEHDRSZ];
MDB_meta mm_meta;
MDBX_meta mm_meta;
} mb_metabuf;
} MDB_metabuf;
} MDBX_metabuf;
/* The header for the reader table (a memory-mapped lock file). */
typedef struct MDBX_lockinfo {
/* Stamp identifying this as an LMDB file. It must be set to MDB_MAGIC. */
/* Stamp identifying this as an MDBX file. It must be set to MDBX_MAGIC. */
uint64_t mti_magic;
/* Format of this lock file. Must be set to MDB_LOCK_FORMAT. */
/* Format of this lock file. Must be set to MDBX_LOCK_FORMAT. */
uint64_t mti_format;
/* Flags which environment was opened. */
uint64_t mti_envmode;
@@ -348,11 +348,11 @@ typedef struct MDBX_lockinfo {
/* Auxiliary DB info.
* The information here is mostly static/read-only. There is
* only a single copy of this record in the environment. */
typedef struct MDB_dbx {
MDBX_val md_name; /* name of the database */
MDB_cmp_func *md_cmp; /* function for comparing keys */
MDB_cmp_func *md_dcmp; /* function for comparing data items */
} MDB_dbx;
typedef struct MDBX_dbx {
MDBX_val md_name; /* name of the database */
MDBX_cmp_func *md_cmp; /* function for comparing keys */
MDBX_cmp_func *md_dcmp; /* function for comparing data items */
} MDBX_dbx;
/* A database transaction.
* Every operation requires a transaction handle. */
@@ -360,18 +360,18 @@ struct MDBX_txn {
#define MDBX_MT_SIGNATURE (0x93D53A31)
unsigned mt_signature;
MDBX_txn *mt_parent; /* parent of a nested txn */
/* Nested txn under this txn, set together with flag MDB_TXN_HAS_CHILD */
/* Nested txn under this txn, set together with flag MDBX_TXN_HAS_CHILD */
MDBX_txn *mt_child;
pgno_t mt_next_pgno; /* next unallocated page */
/* The ID of this transaction. IDs are integers incrementing from 1.
* Only committed write transactions increment the ID. If a transaction
* aborts, the ID may be re-used by the next writer. */
txnid_t mt_txnid;
MDB_env *mt_env; /* the DB environment */
/* The list of reclaimed txns from freeDB */
MDB_IDL mt_lifo_reclaimed;
MDBX_env *mt_env; /* the DB environment */
/* The list of reclaimed txns from freeDB */
MDBX_IDL mt_lifo_reclaimed;
/* The list of pages that became unused during this transaction. */
MDB_IDL mt_free_pages;
MDBX_IDL mt_free_pages;
/* The list of loose pages that became unused and may be reused
* in this transaction, linked through NEXT_LOOSE_PAGE(page). */
MDBX_page *mt_loose_pages;
@@ -380,17 +380,17 @@ struct MDBX_txn {
/* The sorted list of dirty pages we temporarily wrote to disk
* because the dirty list was full. page numbers in here are
* shifted left by 1, deleted slots have the LSB set. */
MDB_IDL mt_spill_pages;
MDBX_IDL mt_spill_pages;
union {
/* For write txns: Modified pages. Sorted when not MDB_WRITEMAP. */
MDB_ID2L mt_rw_dirtylist;
/* For write txns: Modified pages. Sorted when not MDBX_WRITEMAP. */
MDBX_ID2L mt_rw_dirtylist;
/* For read txns: This thread/txn's reader table slot, or NULL. */
MDBX_reader *mt_ro_reader;
};
/* Array of records for each DB known in the environment. */
MDB_dbx *mt_dbxs;
/* Array of MDB_db records for each known DB */
MDB_db *mt_dbs;
MDBX_dbx *mt_dbxs;
/* Array of MDBX_db records for each known DB */
MDBX_db *mt_dbs;
/* Array of sequence numbers for each DB handle */
unsigned *mt_dbiseqs;
@@ -398,34 +398,35 @@ struct MDBX_txn {
#define DB_DIRTY 0x01 /* DB was written in this txn */
#define DB_STALE 0x02 /* Named-DB record is older than txnID */
#define DB_NEW 0x04 /* Named-DB handle opened in this txn */
#define DB_VALID 0x08 /* DB handle is valid, see also MDB_VALID */
#define DB_VALID 0x08 /* DB handle is valid, see also MDBX_VALID */
#define DB_USRVALID 0x10 /* As DB_VALID, but not set for FREE_DBI */
#define DB_DUPDATA 0x20 /* DB is MDB_DUPSORT data */
#define DB_DUPDATA 0x20 /* DB is MDBX_DUPSORT data */
/* In write txns, array of cursors for each DB */
MDB_cursor **mt_cursors;
MDBX_cursor **mt_cursors;
/* Array of flags for each DB */
uint8_t *mt_dbflags;
/* Number of DB records in use, or 0 when the txn is finished.
* This number only ever increments until the txn finishes; we
* don't decrement it when individual DB handles are closed. */
MDB_dbi mt_numdbs;
MDBX_dbi mt_numdbs;
/* Transaction Flags */
/* mdbx_txn_begin() flags */
#define MDB_TXN_BEGIN_FLAGS (MDB_NOMETASYNC | MDB_NOSYNC | MDB_RDONLY)
#define MDB_TXN_NOMETASYNC \
MDB_NOMETASYNC /* don't sync meta for this txn on commit */
#define MDB_TXN_NOSYNC MDB_NOSYNC /* don't sync this txn on commit */
#define MDB_TXN_RDONLY MDB_RDONLY /* read-only transaction */
/* internal txn flags */
#define MDB_TXN_WRITEMAP MDB_WRITEMAP /* copy of MDB_env flag in writers */
#define MDB_TXN_FINISHED 0x01 /* txn is finished or never began */
#define MDB_TXN_ERROR 0x02 /* txn is unusable after an error */
#define MDB_TXN_DIRTY 0x04 /* must write, even if dirty list is empty */
#define MDB_TXN_SPILLS 0x08 /* txn or a parent has spilled pages */
#define MDB_TXN_HAS_CHILD 0x10 /* txn has an MDBX_txn.mt_child */
#define MDBX_TXN_BEGIN_FLAGS (MDBX_NOMETASYNC | MDBX_NOSYNC | MDBX_RDONLY)
#define MDBX_TXN_NOMETASYNC \
MDBX_NOMETASYNC /* don't sync meta for this txn on commit */
#define MDBX_TXN_NOSYNC MDBX_NOSYNC /* don't sync this txn on commit */
#define MDBX_TXN_RDONLY MDBX_RDONLY /* read-only transaction */
/* internal txn flags */
#define MDBX_TXN_WRITEMAP MDBX_WRITEMAP /* copy of MDBX_env flag in writers */
#define MDBX_TXN_FINISHED 0x01 /* txn is finished or never began */
#define MDBX_TXN_ERROR 0x02 /* txn is unusable after an error */
#define MDBX_TXN_DIRTY 0x04 /* must write, even if dirty list is empty */
#define MDBX_TXN_SPILLS 0x08 /* txn or a parent has spilled pages */
#define MDBX_TXN_HAS_CHILD 0x10 /* txn has an MDBX_txn.mt_child */
/* most operations on the txn are currently illegal */
#define MDB_TXN_BLOCKED (MDB_TXN_FINISHED | MDB_TXN_ERROR | MDB_TXN_HAS_CHILD)
#define MDBX_TXN_BLOCKED \
(MDBX_TXN_FINISHED | MDBX_TXN_ERROR | MDBX_TXN_HAS_CHILD)
unsigned mt_flags;
/* dirtylist room: Array size - dirty pages visible to this txn.
* Includes ancestor txns' dirty pages not hidden by other txns'
@@ -440,34 +441,34 @@ struct MDBX_txn {
* raise this on a 64 bit machine. */
#define CURSOR_STACK 32
struct MDB_xcursor;
struct MDBX_xcursor;
/* Cursors are used for all DB operations.
* A cursor holds a path of (page pointer, key index) from the DB
* root to a position in the DB, plus other state. MDB_DUPSORT
* root to a position in the DB, plus other state. MDBX_DUPSORT
* cursors include an xcursor to the current data item. Write txns
* track their cursors and keep them up to date when data moves.
* Exception: An xcursor's pointer to a P_SUBP page can be stale.
* (A node with F_DUPDATA but no F_SUBDATA contains a subpage). */
struct MDB_cursor {
struct MDBX_cursor {
#define MDBX_MC_SIGNATURE (0xFE05D5B1)
#define MDBX_MC_READY4CLOSE (0x2817A047)
#define MDBX_MC_WAIT4EOT (0x90E297A7)
unsigned mc_signature;
/* Next cursor on this DB in this txn */
MDB_cursor *mc_next;
MDBX_cursor *mc_next;
/* Backup of the original cursor if this cursor is a shadow */
MDB_cursor *mc_backup;
/* Context used for databases with MDB_DUPSORT, otherwise NULL */
struct MDB_xcursor *mc_xcursor;
MDBX_cursor *mc_backup;
/* Context used for databases with MDBX_DUPSORT, otherwise NULL */
struct MDBX_xcursor *mc_xcursor;
/* The transaction that owns this cursor */
MDBX_txn *mc_txn;
/* The database handle this cursor operates on */
MDB_dbi mc_dbi;
MDBX_dbi mc_dbi;
/* The database record for this cursor */
MDB_db *mc_db;
MDBX_db *mc_db;
/* The database auxiliary record for this cursor */
MDB_dbx *mc_dbx;
MDBX_dbx *mc_dbx;
/* The mt_dbflag for this database */
uint8_t *mc_dbflag;
uint16_t mc_snum; /* number of pushed pages */
@@ -488,16 +489,16 @@ struct MDB_cursor {
* We could have gone to a fully recursive design, with arbitrarily
* deep nesting of sub-databases. But for now we only handle these
* levels - main DB, optional sub-DB, sorted-duplicate DB. */
typedef struct MDB_xcursor {
typedef struct MDBX_xcursor {
/* A sub-cursor for traversing the Dup DB */
MDB_cursor mx_cursor;
MDBX_cursor mx_cursor;
/* The database record for this Dup DB */
MDB_db mx_db;
MDBX_db mx_db;
/* The auxiliary DB record for this Dup DB */
MDB_dbx mx_dbx;
MDBX_dbx mx_dbx;
/* The mt_dbflag for this Dup DB */
uint8_t mx_dbflag;
} MDB_xcursor;
} MDBX_xcursor;
/* Check if there is an inited xcursor, so XCURSOR_REFRESH() is proper */
#define XCURSOR_INITED(mc) \
@@ -514,42 +515,42 @@ typedef struct MDB_xcursor {
(mc)->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(xr_node); \
} while (0)
/* State of FreeDB old pages, stored in the MDB_env */
typedef struct MDB_pgstate {
/* State of FreeDB old pages, stored in the MDBX_env */
typedef struct MDBX_pgstate {
pgno_t *mf_pghead; /* Reclaimed freeDB pages, or NULL before use */
txnid_t mf_pglast; /* ID of last used record, or 0 if !mf_pghead */
} MDB_pgstate;
} MDBX_pgstate;
#define MDBX_LOCKINFO_WHOLE_SIZE \
((sizeof(MDBX_lockinfo) + MDBX_CACHELINE_SIZE - 1) & \
~((size_t)MDBX_CACHELINE_SIZE - 1))
/* Lockfile format signature: version, features and field layout */
#define MDB_LOCK_FORMAT \
#define MDBX_LOCK_FORMAT \
(((uint64_t)(MDBX_OSAL_LOCK_SIGN) << 32) + \
((MDBX_LOCKINFO_WHOLE_SIZE + MDBX_CACHELINE_SIZE - 1) << 16) + \
(MDB_LOCK_VERSION) /* Flags which describe functionality */)
(MDBX_LOCK_VERSION) /* Flags which describe functionality */)
/* The database environment. */
struct MDB_env {
struct MDBX_env {
#define MDBX_ME_SIGNATURE (0x9A899641)
unsigned me_signature;
mdbx_filehandle_t me_fd; /* The main data file */
mdbx_filehandle_t me_lfd; /* The lock file */
/* Failed to update the meta page. Probably an I/O error. */
#define MDB_FATAL_ERROR 0x80000000U
#define MDBX_FATAL_ERROR 0x80000000U
/* Some fields are initialized. */
#define MDB_ENV_ACTIVE 0x20000000U
#define MDBX_ENV_ACTIVE 0x20000000U
/* me_txkey is set */
#define MDB_ENV_TXKEY 0x10000000U
#define MDBX_ENV_TXKEY 0x10000000U
uint32_t me_flags; /* see mdbx_env */
unsigned me_psize; /* DB page size, inited from me_os_psize */
unsigned me_os_psize; /* OS page size, from mdbx_syspagesize() */
unsigned me_maxreaders; /* size of the reader table */
/* Max MDBX_lockinfo.mti_numreaders of interest to mdbx_env_close() */
unsigned me_close_readers;
MDB_dbi me_numdbs; /* number of DBs opened */
MDB_dbi me_maxdbs; /* size of the DB table */
MDBX_dbi me_numdbs; /* number of DBs opened */
MDBX_dbi me_maxdbs; /* size of the DB table */
mdbx_pid_t me_pid; /* process ID of this env */
char *me_path; /* path to the DB files */
char *me_map; /* the memory map of the data file */
@@ -559,19 +560,19 @@ struct MDB_env {
MDBX_txn *me_txn0; /* prealloc'd write transaction */
size_t me_mapsize; /* size of the data memory map */
pgno_t me_maxpg; /* me_mapsize / me_psize */
MDB_dbx *me_dbxs; /* array of static DB info */
uint16_t *me_dbflags; /* array of flags from MDB_db.md_flags */
MDBX_dbx *me_dbxs; /* array of static DB info */
uint16_t *me_dbflags; /* array of flags from MDBX_db.md_flags */
unsigned *me_dbiseqs; /* array of dbi sequence numbers */
mdbx_thread_key_t me_txkey; /* thread-key for readers */
txnid_t me_pgoldest; /* ID of oldest reader last time we looked */
MDB_pgstate me_pgstate; /* state of old pages from freeDB */
MDBX_pgstate me_pgstate; /* state of old pages from freeDB */
#define me_pglast me_pgstate.mf_pglast
#define me_pghead me_pgstate.mf_pghead
MDBX_page *me_dpages; /* list of malloc'd blocks for re-use */
/* IDL of pages that became unused in a write txn */
MDB_IDL me_free_pgs;
/* ID2L of pages written during a write txn. Length MDB_IDL_UM_SIZE. */
MDB_ID2L me_dirtylist;
MDBX_IDL me_free_pgs;
/* ID2L of pages written during a write txn. Length MDBX_IDL_UM_SIZE. */
MDBX_ID2L me_dirtylist;
/* Max number of freelist items that can fit in a single overflow page */
unsigned me_maxfree_1pg;
/* Max size of a node on a page */
@@ -579,8 +580,8 @@ struct MDB_env {
unsigned me_maxkey_limit; /* max size of a key */
int me_live_reader; /* have liveness lock in reader table */
void *me_userctx; /* User-settable context */
#if MDB_DEBUG
MDB_assert_func *me_assert_func; /* Callback for assertion failures */
#if MDBX_DEBUG
MDBX_assert_func *me_assert_func; /* Callback for assertion failures */
#endif
uint64_t me_sync_pending; /* Total dirty/non-sync'ed bytes
* since the last mdbx_env_sync() */
@@ -592,10 +593,10 @@ struct MDB_env {
};
/* Nested transaction */
typedef struct MDB_ntxn {
MDBX_txn mnt_txn; /* the transaction */
MDB_pgstate mnt_pgstate; /* parent transaction's saved freestate */
} MDB_ntxn;
typedef struct MDBX_ntxn {
MDBX_txn mnt_txn; /* the transaction */
MDBX_pgstate mnt_pgstate; /* parent transaction's saved freestate */
} MDBX_ntxn;
/*----------------------------------------------------------------------------*/
@@ -616,7 +617,7 @@ void mdbx_panic(const char *fmt, ...)
#endif
;
#if MDB_DEBUG
#if MDBX_DEBUG
#define mdbx_assert_enabled() unlikely(mdbx_runtime_flags &MDBX_DBG_ASSERT)
@@ -633,7 +634,7 @@ void mdbx_panic(const char *fmt, ...)
#else
#define mdbx_assert_enabled() (0)
#endif /* NDEBUG */
#endif /* MDB_DEBUG */
#endif /* MDBX_DEBUG */
#define mdbx_print(fmt, ...) \
mdbx_debug_log(MDBX_DBG_PRINT, NULL, 0, fmt, ##__VA_ARGS__)
@@ -748,18 +749,18 @@ static __inline void mdbx_jitter4testing(bool tiny) {
#endif
}
int mdbx_reader_check0(MDB_env *env, int rlocked, int *dead);
int mdbx_reader_check0(MDBX_env *env, int rlocked, int *dead);
#define METAPAGE_1(env) (&((MDB_metabuf *)(env)->me_map)->mb_metabuf.mm_meta)
#define METAPAGE_1(env) (&((MDBX_metabuf *)(env)->me_map)->mb_metabuf.mm_meta)
#define METAPAGE_2(env) \
(&((MDB_metabuf *)((env)->me_map + env->me_psize))->mb_metabuf.mm_meta)
(&((MDBX_metabuf *)((env)->me_map + env->me_psize))->mb_metabuf.mm_meta)
static __inline MDB_meta *mdbx_meta_head(MDB_env *env) {
static __inline MDBX_meta *mdbx_meta_head(MDBX_env *env) {
mdbx_jitter4testing(true);
MDB_meta *a = METAPAGE_1(env);
MDBX_meta *a = METAPAGE_1(env);
mdbx_jitter4testing(true);
MDB_meta *b = METAPAGE_2(env);
MDBX_meta *b = METAPAGE_2(env);
mdbx_jitter4testing(true);
return (a->mm_txnid > b->mm_txnid) ? a : b;