mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-29 23:19:20 +08:00
mdbx: rename the rest MDBX_xyz.
This commit is contained in:
parent
62ebc59330
commit
06de7a5155
4
Makefile
4
Makefile
@ -24,7 +24,7 @@ suffix ?=
|
||||
|
||||
CC ?= gcc
|
||||
CXX ?= g++
|
||||
XCFLAGS ?= -DNDEBUG=1 -DMDB_DEBUG=0 -DLIBMDBX_EXPORTS=1
|
||||
XCFLAGS ?= -DNDEBUG=1 -DMDBX_DEBUG=0 -DLIBMDBX_EXPORTS=1
|
||||
CFLAGS ?= -O2 -g3 -Wall -Werror -Wextra -ffunction-sections -fPIC -fvisibility=hidden
|
||||
CFLAGS += -D_GNU_SOURCE=1 -std=gnu99 -pthread $(XCFLAGS)
|
||||
CXXFLAGS = -std=c++11 $(filter-out -std=gnu99,$(CFLAGS))
|
||||
@ -117,7 +117,7 @@ endif
|
||||
ci-rule = ( CC=$$(which $1); if [ -n "$$CC" ]; then \
|
||||
echo -n "probe by $2 ($$(readlink -f $$(which $$CC))): " && \
|
||||
$(MAKE) clean >$1.log 2>$1.err && \
|
||||
$(MAKE) CC=$$(readlink -f $$CC) XCFLAGS="-UNDEBUG -DMDB_DEBUG=2" all check 1>$1.log 2>$1.err && echo "OK" \
|
||||
$(MAKE) CC=$$(readlink -f $$CC) XCFLAGS="-UNDEBUG -DMDBX_DEBUG=2" all check 1>$1.log 2>$1.err && echo "OK" \
|
||||
|| ( echo "FAILED"; cat $1.err >&2; exit 1 ); \
|
||||
else echo "no $2 ($1) for probe"; fi; )
|
||||
ci:
|
||||
|
@ -58,7 +58,7 @@ _libmdbx_ наследует все ключевые возможности и
|
||||
[MVCC](https://ru.wikipedia.org/wiki/MVCC) и
|
||||
[COW](https://ru.wikipedia.org/wiki/%D0%9A%D0%BE%D0%BF%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5_%D0%BF%D1%80%D0%B8_%D0%B7%D0%B0%D0%BF%D0%B8%D1%81%D0%B8).
|
||||
Изменения строго последовательны и не блокируются чтением,
|
||||
конфликты между транзакциями не возможны.
|
||||
конфликты между транзакциями не возможны.
|
||||
При этом гарантируется чтение только зафиксированных данных, см [relaxing serializability](https://en.wikipedia.org/wiki/Serializability).
|
||||
|
||||
4. Чтение и поиск [без блокировок](https://ru.wikipedia.org/wiki/%D0%9D%D0%B5%D0%B1%D0%BB%D0%BE%D0%BA%D0%B8%D1%80%D1%83%D1%8E%D1%89%D0%B0%D1%8F_%D1%81%D0%B8%D0%BD%D1%85%D1%80%D0%BE%D0%BD%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F),
|
||||
@ -305,7 +305,7 @@ RECLAIM` в _libmdbx_.
|
||||
посредством `mdbx_cursor_eof()`.
|
||||
|
||||
10. Возможность явно запросить обновление существующей записи, без
|
||||
создания новой посредством флажка `MDB_CURRENT` для `mdbx_put()`.
|
||||
создания новой посредством флажка `MDBX_CURRENT` для `mdbx_put()`.
|
||||
|
||||
11. Возможность обновить или удалить запись с получением предыдущего
|
||||
значения данных посредством `mdbx_replace()`.
|
||||
@ -328,7 +328,7 @@ RECLAIM` в _libmdbx_.
|
||||
который используется одним из читателей.
|
||||
|
||||
17. Функция `mdbx_del()` не игнорирует дополнительный (уточняющий)
|
||||
аргумент `data` для таблиц без дубликатов (без флажка `MDB_DUPSORT`), а
|
||||
аргумент `data` для таблиц без дубликатов (без флажка `MDBX_DUPSORT`), а
|
||||
при его ненулевом значении всегда использует его для сверки с удаляемой
|
||||
записью.
|
||||
|
||||
@ -342,7 +342,7 @@ RECLAIM` в _libmdbx_.
|
||||
изменениях, иначе они будут неизменны).
|
||||
|
||||
20. Корректное обновление текущей записи, в том числе сортированного
|
||||
дубликата, при использовании режима `MDB_CURRENT` в `mdbx_cursor_put()`.
|
||||
дубликата, при использовании режима `MDBX_CURRENT` в `mdbx_cursor_put()`.
|
||||
|
||||
21. Все курсоры, как в транзакциях только для чтения, так и в пишущих,
|
||||
могут быть переиспользованы посредством `mdbx_cursor_renew()` и ДОЛЖНЫ
|
||||
|
@ -77,7 +77,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;%(PreprocessorDefinitions);MDB_DEBUG=1</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;%(PreprocessorDefinitions);MDBX_DEBUG=1</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
@ -121,7 +121,7 @@
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN64;_DEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;%(PreprocessorDefinitions);MDB_DEBUG=1</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN64;_DEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;%(PreprocessorDefinitions);MDBX_DEBUG=1</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<StringPooling>true</StringPooling>
|
||||
</ClCompile>
|
||||
|
209
src/bits.h
209
src/bits.h
@ -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,19 +230,19 @@ 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 */
|
||||
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 */
|
||||
@ -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 {
|
||||
typedef struct MDBX_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;
|
||||
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 */
|
||||
MDBX_env *mt_env; /* the DB environment */
|
||||
/* The list of reclaimed txns from freeDB */
|
||||
MDB_IDL mt_lifo_reclaimed;
|
||||
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 */
|
||||
#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 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_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 {
|
||||
typedef struct MDBX_ntxn {
|
||||
MDBX_txn mnt_txn; /* the transaction */
|
||||
MDB_pgstate mnt_pgstate; /* parent transaction's saved freestate */
|
||||
} MDB_ntxn;
|
||||
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;
|
||||
|
@ -16,18 +16,18 @@
|
||||
|
||||
/* Some platforms define the EOWNERDEAD error code
|
||||
* even though they don't support Robust Mutexes.
|
||||
* Compile with -DMDB_USE_ROBUST=0. */
|
||||
#ifndef MDB_USE_ROBUST
|
||||
* Compile with -DMDBX_USE_ROBUST=0. */
|
||||
#ifndef MDBX_USE_ROBUST
|
||||
/* Howard Chu: Android currently lacks Robust Mutex support */
|
||||
#if defined(EOWNERDEAD) && \
|
||||
!defined(ANDROID) /* LY: glibc before 2.10 has a troubles with Robust \
|
||||
Mutex too. */ \
|
||||
&& __GLIBC_PREREQ(2, 10)
|
||||
#define MDB_USE_ROBUST 1
|
||||
#define MDBX_USE_ROBUST 1
|
||||
#else
|
||||
#define MDB_USE_ROBUST 0
|
||||
#define MDBX_USE_ROBUST 0
|
||||
#endif
|
||||
#endif /* MDB_USE_ROBUST */
|
||||
#endif /* MDBX_USE_ROBUST */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* rthc */
|
||||
@ -91,13 +91,13 @@ static __inline int mdbx_lck_shared(int lfd) {
|
||||
return mdbx_lck_op(lfd, F_SETLKW, F_RDLCK, 0, 1);
|
||||
}
|
||||
|
||||
int mdbx_lck_downgrade(MDB_env *env) { return mdbx_lck_shared(env->me_lfd); }
|
||||
int mdbx_lck_downgrade(MDBX_env *env) { return mdbx_lck_shared(env->me_lfd); }
|
||||
|
||||
int mdbx_rpid_set(MDB_env *env) {
|
||||
int mdbx_rpid_set(MDBX_env *env) {
|
||||
return mdbx_lck_op(env->me_lfd, F_SETLK, F_WRLCK, env->me_pid, 1);
|
||||
}
|
||||
|
||||
int mdbx_rpid_clear(MDB_env *env) {
|
||||
int mdbx_rpid_clear(MDBX_env *env) {
|
||||
return mdbx_lck_op(env->me_lfd, F_SETLKW, F_UNLCK, env->me_pid, 1);
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ int mdbx_rpid_clear(MDB_env *env) {
|
||||
* MDBX_RESULT_TRUE, if pid is live (unable to acquire lock)
|
||||
* MDBX_RESULT_FALSE, if pid is dead (lock acquired)
|
||||
* or otherwise the errcode. */
|
||||
int mdbx_rpid_check(MDB_env *env, mdbx_pid_t pid) {
|
||||
int mdbx_rpid_check(MDBX_env *env, mdbx_pid_t pid) {
|
||||
int rc = mdbx_lck_op(env->me_lfd, F_GETLK, F_WRLCK, pid, 1);
|
||||
if (rc == 0)
|
||||
return MDBX_RESULT_FALSE;
|
||||
@ -118,9 +118,9 @@ int mdbx_rpid_check(MDB_env *env, mdbx_pid_t pid) {
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static int mdbx_mutex_failed(MDB_env *env, pthread_mutex_t *mutex, int rc);
|
||||
static int mdbx_mutex_failed(MDBX_env *env, pthread_mutex_t *mutex, int rc);
|
||||
|
||||
int mdbx_lck_init(MDB_env *env) {
|
||||
int mdbx_lck_init(MDBX_env *env) {
|
||||
pthread_mutexattr_t ma;
|
||||
int rc = pthread_mutexattr_init(&ma);
|
||||
if (rc)
|
||||
@ -130,7 +130,7 @@ int mdbx_lck_init(MDB_env *env) {
|
||||
if (rc)
|
||||
goto bailout;
|
||||
|
||||
#if MDB_USE_ROBUST
|
||||
#if MDBX_USE_ROBUST
|
||||
#if __GLIBC_PREREQ(2, 12)
|
||||
rc = pthread_mutexattr_setrobust(&ma, PTHREAD_MUTEX_ROBUST);
|
||||
#else
|
||||
@ -138,7 +138,7 @@ int mdbx_lck_init(MDB_env *env) {
|
||||
#endif
|
||||
if (rc)
|
||||
goto bailout;
|
||||
#endif /* MDB_USE_ROBUST */
|
||||
#endif /* MDBX_USE_ROBUST */
|
||||
|
||||
#if _POSIX_C_SOURCE >= 199506L
|
||||
rc = pthread_mutexattr_setprotocol(&ma, PTHREAD_PRIO_INHERIT);
|
||||
@ -158,7 +158,7 @@ bailout:
|
||||
return rc;
|
||||
}
|
||||
|
||||
void mdbx_lck_destroy(MDB_env *env) {
|
||||
void mdbx_lck_destroy(MDBX_env *env) {
|
||||
if (env->me_lfd != INVALID_HANDLE_VALUE) {
|
||||
/* try get exclusive access */
|
||||
if (env->me_lck && mdbx_lck_exclusive(env->me_lfd) == 0) {
|
||||
@ -173,28 +173,28 @@ void mdbx_lck_destroy(MDB_env *env) {
|
||||
}
|
||||
}
|
||||
|
||||
static int mdbx_robust_lock(MDB_env *env, pthread_mutex_t *mutex) {
|
||||
static int mdbx_robust_lock(MDBX_env *env, pthread_mutex_t *mutex) {
|
||||
int rc = pthread_mutex_lock(mutex);
|
||||
if (unlikely(rc != 0))
|
||||
rc = mdbx_mutex_failed(env, mutex, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int mdbx_robust_unlock(MDB_env *env, pthread_mutex_t *mutex) {
|
||||
static int mdbx_robust_unlock(MDBX_env *env, pthread_mutex_t *mutex) {
|
||||
int rc = pthread_mutex_unlock(mutex);
|
||||
if (unlikely(rc != 0))
|
||||
rc = mdbx_mutex_failed(env, mutex, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int mdbx_rdt_lock(MDB_env *env) {
|
||||
int mdbx_rdt_lock(MDBX_env *env) {
|
||||
mdbx_trace(">>");
|
||||
int rc = mdbx_robust_lock(env, &env->me_lck->mti_rmutex);
|
||||
mdbx_trace("<< rc %d", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
void mdbx_rdt_unlock(MDB_env *env) {
|
||||
void mdbx_rdt_unlock(MDBX_env *env) {
|
||||
mdbx_trace(">>");
|
||||
int rc = mdbx_robust_unlock(env, &env->me_lck->mti_rmutex);
|
||||
mdbx_trace("<< rc %d", rc);
|
||||
@ -202,14 +202,14 @@ void mdbx_rdt_unlock(MDB_env *env) {
|
||||
mdbx_panic("%s() failed: errcode %d\n", mdbx_func_, rc);
|
||||
}
|
||||
|
||||
int mdbx_txn_lock(MDB_env *env) {
|
||||
int mdbx_txn_lock(MDBX_env *env) {
|
||||
mdbx_trace(">>");
|
||||
int rc = mdbx_robust_lock(env, &env->me_lck->mti_wmutex);
|
||||
mdbx_trace("<< rc %d", rc);
|
||||
return MDBX_IS_ERROR(rc) ? rc : MDB_SUCCESS;
|
||||
return MDBX_IS_ERROR(rc) ? rc : MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
void mdbx_txn_unlock(MDB_env *env) {
|
||||
void mdbx_txn_unlock(MDBX_env *env) {
|
||||
mdbx_trace(">>");
|
||||
int rc = mdbx_robust_unlock(env, &env->me_lck->mti_wmutex);
|
||||
mdbx_trace("<< rc %d", rc);
|
||||
@ -243,7 +243,7 @@ static int internal_seize_lck(int lfd) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
int mdbx_lck_seize(MDB_env *env) {
|
||||
int mdbx_lck_seize(MDBX_env *env) {
|
||||
assert(env->me_fd != INVALID_HANDLE_VALUE);
|
||||
|
||||
if (env->me_lfd == INVALID_HANDLE_VALUE) {
|
||||
@ -256,7 +256,7 @@ int mdbx_lck_seize(MDB_env *env) {
|
||||
return MDBX_RESULT_FALSE;
|
||||
}
|
||||
|
||||
if ((env->me_flags & MDB_RDONLY) == 0) {
|
||||
if ((env->me_flags & MDBX_RDONLY) == 0) {
|
||||
/* Check that another process don't operates in without-lck mode. */
|
||||
int rc = mdbx_lck_op(env->me_fd, F_SETLK, F_WRLCK, env->me_pid, 1);
|
||||
if (rc != 0) {
|
||||
@ -273,20 +273,20 @@ int mdbx_lck_seize(MDB_env *env) {
|
||||
#define pthread_mutex_consistent(mutex) pthread_mutex_consistent_np(mutex)
|
||||
#endif
|
||||
|
||||
static int __cold mdbx_mutex_failed(MDB_env *env, pthread_mutex_t *mutex,
|
||||
static int __cold mdbx_mutex_failed(MDBX_env *env, pthread_mutex_t *mutex,
|
||||
int rc) {
|
||||
#if MDB_USE_ROBUST
|
||||
#if MDBX_USE_ROBUST
|
||||
if (rc == EOWNERDEAD) {
|
||||
/* We own the mutex. Clean up after dead previous owner. */
|
||||
|
||||
int rlocked = (mutex == &env->me_lck->mti_rmutex);
|
||||
rc = MDB_SUCCESS;
|
||||
rc = MDBX_SUCCESS;
|
||||
if (!rlocked) {
|
||||
if (unlikely(env->me_txn)) {
|
||||
/* env is hosed if the dead thread was ours */
|
||||
env->me_flags |= MDB_FATAL_ERROR;
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
env->me_txn = NULL;
|
||||
rc = MDB_PANIC;
|
||||
rc = MDBX_PANIC;
|
||||
}
|
||||
}
|
||||
mdbx_notice("%cmutex owner died, %s", (rlocked ? 'r' : 'w'),
|
||||
@ -299,17 +299,17 @@ static int __cold mdbx_mutex_failed(MDB_env *env, pthread_mutex_t *mutex,
|
||||
if (unlikely(mreco_rc))
|
||||
mdbx_error("mutex recovery failed, %s", mdbx_strerror(mreco_rc));
|
||||
|
||||
rc = (rc == MDB_SUCCESS) ? check_rc : rc;
|
||||
rc = (rc == MDBX_SUCCESS) ? check_rc : rc;
|
||||
if (MDBX_IS_ERROR(rc))
|
||||
pthread_mutex_unlock(mutex);
|
||||
return rc;
|
||||
}
|
||||
#endif /* MDB_USE_ROBUST */
|
||||
#endif /* MDBX_USE_ROBUST */
|
||||
|
||||
mdbx_error("mutex (un)lock failed, %s", mdbx_strerror(rc));
|
||||
if (rc != EDEADLK) {
|
||||
env->me_flags |= MDB_FATAL_ERROR;
|
||||
rc = MDB_PANIC;
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
rc = MDBX_PANIC;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
@ -125,13 +125,13 @@ static __inline BOOL funlock(mdbx_filehandle_t fd, off_t offset, size_t bytes) {
|
||||
#define LCK_BODY LCK_BODY_OFFSET, LCK_BODY_LEN
|
||||
#define LCK_WHOLE 0, LCK_MAXLEN
|
||||
|
||||
int mdbx_txn_lock(MDB_env *env) {
|
||||
int mdbx_txn_lock(MDBX_env *env) {
|
||||
if (flock(env->me_fd, LCK_EXCLUSIVE | LCK_WAITFOR, LCK_BODY))
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
return mdbx_get_errno_checked();
|
||||
}
|
||||
|
||||
void mdbx_txn_unlock(MDB_env *env) {
|
||||
void mdbx_txn_unlock(MDBX_env *env) {
|
||||
if (!funlock(env->me_fd, LCK_BODY))
|
||||
mdbx_panic("%s failed: errcode %u", mdbx_func_, GetLastError());
|
||||
}
|
||||
@ -147,17 +147,17 @@ void mdbx_txn_unlock(MDB_env *env) {
|
||||
#define LCK_LOWER LCK_LO_OFFSET, LCK_LO_LEN
|
||||
#define LCK_UPPER LCK_UP_OFFSET, LCK_UP_LEN
|
||||
|
||||
int mdbx_rdt_lock(MDB_env *env) {
|
||||
int mdbx_rdt_lock(MDBX_env *env) {
|
||||
if (env->me_lfd == INVALID_HANDLE_VALUE)
|
||||
return MDB_SUCCESS; /* readonly database in readonly filesystem */
|
||||
return MDBX_SUCCESS; /* readonly database in readonly filesystem */
|
||||
|
||||
/* transite from S-? (used) to S-E (locked), e.g. exlcusive lock upper-part */
|
||||
if (flock(env->me_lfd, LCK_EXCLUSIVE | LCK_WAITFOR, LCK_UPPER))
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
return mdbx_get_errno_checked();
|
||||
}
|
||||
|
||||
void mdbx_rdt_unlock(MDB_env *env) {
|
||||
void mdbx_rdt_unlock(MDBX_env *env) {
|
||||
if (env->me_lfd != INVALID_HANDLE_VALUE) {
|
||||
/* transite from S-E (locked) to S-? (used), e.g. unlock upper-part */
|
||||
if (!funlock(env->me_lfd, LCK_UPPER))
|
||||
@ -181,9 +181,9 @@ void mdbx_rdt_unlock(MDB_env *env) {
|
||||
E-E = exclusive
|
||||
*/
|
||||
|
||||
int mdbx_lck_init(MDB_env *env) {
|
||||
int mdbx_lck_init(MDBX_env *env) {
|
||||
(void)env;
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
/* Seize state as exclusive (E-E and returns MDBX_RESULT_TRUE)
|
||||
@ -238,7 +238,7 @@ static int internal_seize_lck(HANDLE lfd) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
int mdbx_lck_seize(MDB_env *env) {
|
||||
int mdbx_lck_seize(MDBX_env *env) {
|
||||
int rc;
|
||||
|
||||
assert(env->me_fd != INVALID_HANDLE_VALUE);
|
||||
@ -255,7 +255,7 @@ int mdbx_lck_seize(MDB_env *env) {
|
||||
|
||||
rc = internal_seize_lck(env->me_lfd);
|
||||
mdbx_jitter4testing(false);
|
||||
if (rc == MDBX_RESULT_TRUE && (env->me_flags & MDB_RDONLY) == 0) {
|
||||
if (rc == MDBX_RESULT_TRUE && (env->me_flags & MDBX_RDONLY) == 0) {
|
||||
/* Check that another process don't operates in without-lck mode.
|
||||
* Doing such check by exclusive locking the body-part of db. Should be
|
||||
* noted:
|
||||
@ -280,7 +280,7 @@ int mdbx_lck_seize(MDB_env *env) {
|
||||
}
|
||||
|
||||
/* Transite from exclusive state (E-E) to used (S-?) */
|
||||
int mdbx_lck_downgrade(MDB_env *env) {
|
||||
int mdbx_lck_downgrade(MDBX_env *env) {
|
||||
int rc;
|
||||
assert(env->me_fd != INVALID_HANDLE_VALUE);
|
||||
|
||||
@ -301,10 +301,10 @@ int mdbx_lck_downgrade(MDB_env *env) {
|
||||
mdbx_panic("%s(%s) failed: errcode %u", mdbx_func_,
|
||||
"S-E(locked) >> S-?(used)", GetLastError());
|
||||
}
|
||||
return MDB_SUCCESS /* 5) now at S-? (used), done */;
|
||||
return MDBX_SUCCESS /* 5) now at S-? (used), done */;
|
||||
}
|
||||
|
||||
void mdbx_lck_destroy(MDB_env *env) {
|
||||
void mdbx_lck_destroy(MDBX_env *env) {
|
||||
int rc;
|
||||
|
||||
if (env->me_lfd != INVALID_HANDLE_VALUE) {
|
||||
@ -353,14 +353,14 @@ void mdbx_lck_destroy(MDB_env *env) {
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* reader checking (by pid) */
|
||||
|
||||
int mdbx_rpid_set(MDB_env *env) {
|
||||
int mdbx_rpid_set(MDBX_env *env) {
|
||||
(void)env;
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
int mdbx_rpid_clear(MDB_env *env) {
|
||||
int mdbx_rpid_clear(MDBX_env *env) {
|
||||
(void)env;
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
/* Checks reader by pid.
|
||||
@ -369,7 +369,7 @@ int mdbx_rpid_clear(MDB_env *env) {
|
||||
* MDBX_RESULT_TRUE, if pid is live (unable to acquire lock)
|
||||
* MDBX_RESULT_FALSE, if pid is dead (lock acquired)
|
||||
* or otherwise the errcode. */
|
||||
int mdbx_rpid_check(MDB_env *env, mdbx_pid_t pid) {
|
||||
int mdbx_rpid_check(MDBX_env *env, mdbx_pid_t pid) {
|
||||
(void)env;
|
||||
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
|
||||
int rc;
|
||||
|
2549
src/mdbx.c
2549
src/mdbx.c
File diff suppressed because it is too large
Load Diff
22
src/midl.h
22
src/midl.h
@ -14,21 +14,21 @@
|
||||
|
||||
/* IDL sizes - likely should be even bigger
|
||||
* limiting factors: sizeof(pgno_t), thread stack size */
|
||||
#define MDB_IDL_LOGN 16 /* DB_SIZE is 2^16, UM_SIZE is 2^17 */
|
||||
#define MDB_IDL_DB_SIZE (1 << MDB_IDL_LOGN)
|
||||
#define MDB_IDL_UM_SIZE (1 << (MDB_IDL_LOGN + 1))
|
||||
#define MDBX_IDL_LOGN 16 /* DB_SIZE is 2^16, UM_SIZE is 2^17 */
|
||||
#define MDBX_IDL_DB_SIZE (1 << MDBX_IDL_LOGN)
|
||||
#define MDBX_IDL_UM_SIZE (1 << (MDBX_IDL_LOGN + 1))
|
||||
|
||||
#define MDB_IDL_DB_MAX (MDB_IDL_DB_SIZE - 1)
|
||||
#define MDB_IDL_UM_MAX (MDB_IDL_UM_SIZE - 1)
|
||||
#define MDBX_IDL_DB_MAX (MDBX_IDL_DB_SIZE - 1)
|
||||
#define MDBX_IDL_UM_MAX (MDBX_IDL_UM_SIZE - 1)
|
||||
|
||||
#define MDB_IDL_SIZEOF(ids) (((ids)[0] + 1) * sizeof(pgno_t))
|
||||
#define MDB_IDL_IS_ZERO(ids) ((ids)[0] == 0)
|
||||
#define MDB_IDL_CPY(dst, src) (memcpy(dst, src, MDB_IDL_SIZEOF(src)))
|
||||
#define MDB_IDL_FIRST(ids) ((ids)[1])
|
||||
#define MDB_IDL_LAST(ids) ((ids)[(ids)[0]])
|
||||
#define MDBX_IDL_SIZEOF(ids) (((ids)[0] + 1) * sizeof(pgno_t))
|
||||
#define MDBX_IDL_IS_ZERO(ids) ((ids)[0] == 0)
|
||||
#define MDBX_IDL_CPY(dst, src) (memcpy(dst, src, MDBX_IDL_SIZEOF(src)))
|
||||
#define MDBX_IDL_FIRST(ids) ((ids)[1])
|
||||
#define MDBX_IDL_LAST(ids) ((ids)[(ids)[0]])
|
||||
|
||||
/* Current max length of an #mdbx_midl_alloc()ed IDL */
|
||||
#define MDB_IDL_ALLOCLEN(ids) ((ids)[-1])
|
||||
#define MDBX_IDL_ALLOCLEN(ids) ((ids)[-1])
|
||||
|
||||
/* Append ID to IDL. The IDL must be big enough. */
|
||||
#define mdbx_midl_xappend(idl, id) \
|
||||
|
99
src/osal.c
99
src/osal.c
@ -20,7 +20,7 @@
|
||||
static int waitstatus2errcode(DWORD result) {
|
||||
switch (result) {
|
||||
case WAIT_OBJECT_0:
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
case WAIT_FAILED:
|
||||
return mdbx_get_errno_checked();
|
||||
case WAIT_ABANDONED:
|
||||
@ -48,16 +48,16 @@ __extern_C __declspec(dllimport) void __cdecl _assert(char const *message,
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#ifndef mdbx_assert_fail
|
||||
void __cold mdbx_assert_fail(MDB_env *env, const char *msg, const char *func,
|
||||
void __cold mdbx_assert_fail(MDBX_env *env, const char *msg, const char *func,
|
||||
int line) {
|
||||
#if MDB_DEBUG
|
||||
#if MDBX_DEBUG
|
||||
if (env && env->me_assert_func) {
|
||||
env->me_assert_func(env, msg, func, line);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
(void)env;
|
||||
#endif /* MDB_DEBUG */
|
||||
#endif /* MDBX_DEBUG */
|
||||
|
||||
if (mdbx_debug_logger)
|
||||
mdbx_debug_log(MDBX_DBG_ASSERT, func, line, "assert: %s\n", msg);
|
||||
@ -139,10 +139,10 @@ int mdbx_asprintf(char **strp, const char *fmt, ...) {
|
||||
int mdbx_memalign_alloc(size_t alignment, size_t bytes, void **result) {
|
||||
#if _MSC_VER
|
||||
*result = _aligned_malloc(bytes, alignment);
|
||||
return *result ? MDB_SUCCESS : MDBX_ENOMEM /* ERROR_OUTOFMEMORY */;
|
||||
return *result ? MDBX_SUCCESS : MDBX_ENOMEM /* ERROR_OUTOFMEMORY */;
|
||||
#elif __GLIBC_PREREQ(2, 16) || __STDC_VERSION__ >= 201112L
|
||||
*result = memalign(alignment, bytes);
|
||||
return *result ? MDB_SUCCESS : errno;
|
||||
return *result ? MDBX_SUCCESS : errno;
|
||||
#elif _POSIX_VERSION >= 200112L
|
||||
*result = NULL;
|
||||
return posix_memalign(result, alignment, bytes);
|
||||
@ -166,7 +166,7 @@ void mdbx_memalign_free(void *ptr) {
|
||||
|
||||
int mdbx_condmutex_init(mdbx_condmutex_t *condmutex) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
int rc = MDB_SUCCESS;
|
||||
int rc = MDBX_SUCCESS;
|
||||
condmutex->event = NULL;
|
||||
condmutex->mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
if (!condmutex->mutex)
|
||||
@ -203,13 +203,15 @@ int mdbx_condmutex_destroy(mdbx_condmutex_t *condmutex) {
|
||||
int rc = MDBX_EINVAL;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
if (condmutex->event) {
|
||||
rc = CloseHandle(condmutex->event) ? MDB_SUCCESS : mdbx_get_errno_checked();
|
||||
if (rc == MDB_SUCCESS)
|
||||
rc =
|
||||
CloseHandle(condmutex->event) ? MDBX_SUCCESS : mdbx_get_errno_checked();
|
||||
if (rc == MDBX_SUCCESS)
|
||||
condmutex->event = NULL;
|
||||
}
|
||||
if (condmutex->mutex) {
|
||||
rc = CloseHandle(condmutex->mutex) ? MDB_SUCCESS : mdbx_get_errno_checked();
|
||||
if (rc == MDB_SUCCESS)
|
||||
rc =
|
||||
CloseHandle(condmutex->mutex) ? MDBX_SUCCESS : mdbx_get_errno_checked();
|
||||
if (rc == MDBX_SUCCESS)
|
||||
condmutex->mutex = NULL;
|
||||
}
|
||||
#else
|
||||
@ -238,7 +240,7 @@ int mdbx_condmutex_lock(mdbx_condmutex_t *condmutex) {
|
||||
|
||||
int mdbx_condmutex_unlock(mdbx_condmutex_t *condmutex) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
return ReleaseMutex(condmutex->mutex) ? MDB_SUCCESS
|
||||
return ReleaseMutex(condmutex->mutex) ? MDBX_SUCCESS
|
||||
: mdbx_get_errno_checked();
|
||||
#else
|
||||
return pthread_mutex_unlock(&condmutex->mutex);
|
||||
@ -247,7 +249,7 @@ int mdbx_condmutex_unlock(mdbx_condmutex_t *condmutex) {
|
||||
|
||||
int mdbx_condmutex_signal(mdbx_condmutex_t *condmutex) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
return SetEvent(condmutex->event) ? MDB_SUCCESS : mdbx_get_errno_checked();
|
||||
return SetEvent(condmutex->event) ? MDBX_SUCCESS : mdbx_get_errno_checked();
|
||||
#else
|
||||
return pthread_cond_signal(&condmutex->cond);
|
||||
#endif
|
||||
@ -270,7 +272,7 @@ int mdbx_condmutex_wait(mdbx_condmutex_t *condmutex) {
|
||||
int mdbx_fastmutex_init(mdbx_fastmutex_t *fastmutex) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
InitializeCriticalSection(fastmutex);
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
#else
|
||||
return pthread_mutex_init(fastmutex, NULL);
|
||||
#endif
|
||||
@ -279,7 +281,7 @@ int mdbx_fastmutex_init(mdbx_fastmutex_t *fastmutex) {
|
||||
int mdbx_fastmutex_destroy(mdbx_fastmutex_t *fastmutex) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
DeleteCriticalSection(fastmutex);
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
#else
|
||||
return pthread_mutex_destroy(fastmutex);
|
||||
#endif
|
||||
@ -288,7 +290,7 @@ int mdbx_fastmutex_destroy(mdbx_fastmutex_t *fastmutex) {
|
||||
int mdbx_fastmutex_acquire(mdbx_fastmutex_t *fastmutex) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
EnterCriticalSection(fastmutex);
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
#else
|
||||
return pthread_mutex_lock(fastmutex);
|
||||
#endif
|
||||
@ -297,7 +299,7 @@ int mdbx_fastmutex_acquire(mdbx_fastmutex_t *fastmutex) {
|
||||
int mdbx_fastmutex_release(mdbx_fastmutex_t *fastmutex) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
LeaveCriticalSection(fastmutex);
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
#else
|
||||
return pthread_mutex_unlock(fastmutex);
|
||||
#endif
|
||||
@ -320,7 +322,7 @@ int mdbx_openfile(const char *pathname, int flags, mode_t mode,
|
||||
case O_RDONLY:
|
||||
DesiredAccess = GENERIC_READ;
|
||||
break;
|
||||
case O_WRONLY: /* assume for mdb_env_copy() and friends output */
|
||||
case O_WRONLY: /* assume for MDBX_env_copy() and friends output */
|
||||
DesiredAccess = GENERIC_WRITE;
|
||||
ShareMode = 0;
|
||||
FlagsAndAttributes |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH;
|
||||
@ -378,14 +380,14 @@ int mdbx_openfile(const char *pathname, int flags, mode_t mode,
|
||||
(void)fcntl(*fd, F_SETFD, flags | FD_CLOEXEC);
|
||||
#endif
|
||||
#endif
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
int mdbx_closefile(mdbx_filehandle_t fd) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
return CloseHandle(fd) ? MDB_SUCCESS : mdbx_get_errno_checked();
|
||||
return CloseHandle(fd) ? MDBX_SUCCESS : mdbx_get_errno_checked();
|
||||
#else
|
||||
return (close(fd) == 0) ? MDB_SUCCESS : errno;
|
||||
return (close(fd) == 0) ? MDBX_SUCCESS : errno;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -402,16 +404,16 @@ int mdbx_pread(mdbx_filehandle_t fd, void *buf, size_t bytes, off_t offset) {
|
||||
DWORD read = 0;
|
||||
if (unlikely(!ReadFile(fd, buf, (DWORD)bytes, &read, &ov))) {
|
||||
int rc = mdbx_get_errno_checked();
|
||||
return (rc == MDB_SUCCESS) ? /* paranoia */ ERROR_READ_FAULT : rc;
|
||||
return (rc == MDBX_SUCCESS) ? /* paranoia */ ERROR_READ_FAULT : rc;
|
||||
}
|
||||
#else
|
||||
ssize_t read = pread(fd, buf, bytes, offset);
|
||||
if (read < 0) {
|
||||
int rc = errno;
|
||||
return (rc == MDB_SUCCESS) ? /* paranoia */ MDBX_EIO : rc;
|
||||
return (rc == MDBX_SUCCESS) ? /* paranoia */ MDBX_EIO : rc;
|
||||
}
|
||||
#endif
|
||||
return (bytes == (size_t)read) ? MDB_SUCCESS : MDBX_ENODATA;
|
||||
return (bytes == (size_t)read) ? MDBX_SUCCESS : MDBX_ENODATA;
|
||||
}
|
||||
|
||||
int mdbx_pwrite(mdbx_filehandle_t fd, const void *buf, size_t bytes,
|
||||
@ -427,7 +429,7 @@ int mdbx_pwrite(mdbx_filehandle_t fd, const void *buf, size_t bytes,
|
||||
|
||||
DWORD written;
|
||||
if (likely(WriteFile(fd, buf, (DWORD)bytes, &written, &ov)))
|
||||
return (bytes == written) ? MDB_SUCCESS : MDBX_EIO /* ERROR_WRITE_FAULT */;
|
||||
return (bytes == written) ? MDBX_SUCCESS : MDBX_EIO /* ERROR_WRITE_FAULT */;
|
||||
return mdbx_get_errno_checked();
|
||||
#else
|
||||
int rc;
|
||||
@ -435,7 +437,7 @@ int mdbx_pwrite(mdbx_filehandle_t fd, const void *buf, size_t bytes,
|
||||
do {
|
||||
written = pwrite(fd, buf, bytes, offset);
|
||||
if (likely(bytes == (size_t)written))
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
rc = errno;
|
||||
} while (rc == EINTR);
|
||||
return (written < 0) ? rc : MDBX_EIO /* Use which error code (ENOSPC)? */;
|
||||
@ -448,12 +450,12 @@ int mdbx_pwritev(mdbx_filehandle_t fd, struct iovec *iov, int iovcnt,
|
||||
size_t written = 0;
|
||||
for (int i = 0; i < iovcnt; ++i) {
|
||||
int rc = mdbx_pwrite(fd, iov[i].iov_base, iov[i].iov_len, offset);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
return rc;
|
||||
written += iov[i].iov_len;
|
||||
offset += iov[i].iov_len;
|
||||
}
|
||||
return (expected_written == written) ? MDB_SUCCESS
|
||||
return (expected_written == written) ? MDBX_SUCCESS
|
||||
: MDBX_EIO /* ERROR_WRITE_FAULT */;
|
||||
#else
|
||||
int rc;
|
||||
@ -461,7 +463,7 @@ int mdbx_pwritev(mdbx_filehandle_t fd, struct iovec *iov, int iovcnt,
|
||||
do {
|
||||
written = pwritev(fd, iov, iovcnt, offset);
|
||||
if (likely(expected_written == (size_t)written))
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
rc = errno;
|
||||
} while (rc == EINTR);
|
||||
return (written < 0) ? rc : MDBX_EIO /* Use which error code? */;
|
||||
@ -508,7 +510,7 @@ int mdbx_write(mdbx_filehandle_t fd, const void *buf, size_t bytes) {
|
||||
#ifdef SIGPIPE
|
||||
pthread_sigmask(SIG_SETMASK, &old, NULL);
|
||||
#endif
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
ptr += written;
|
||||
bytes -= written;
|
||||
@ -518,19 +520,19 @@ int mdbx_write(mdbx_filehandle_t fd, const void *buf, size_t bytes) {
|
||||
int mdbx_filesync(mdbx_filehandle_t fd, bool fullsync) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
(void)fullsync;
|
||||
return FlushFileBuffers(fd) ? MDB_SUCCESS : mdbx_get_errno_checked();
|
||||
return FlushFileBuffers(fd) ? MDBX_SUCCESS : mdbx_get_errno_checked();
|
||||
#elif __GLIBC_PREREQ(2, 16) || _BSD_SOURCE || _XOPEN_SOURCE || \
|
||||
(__GLIBC_PREREQ(2, 8) && _POSIX_C_SOURCE >= 200112L)
|
||||
for (;;) {
|
||||
#if _POSIX_C_SOURCE >= 199309L || _XOPEN_SOURCE >= 500 || \
|
||||
defined(_POSIX_SYNCHRONIZED_IO)
|
||||
if (!fullsync && fdatasync(fd) == 0)
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
#else
|
||||
(void)fullsync;
|
||||
#endif
|
||||
if (fsync(fd) == 0)
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
int rc = errno;
|
||||
if (rc != EINTR)
|
||||
return rc;
|
||||
@ -554,7 +556,7 @@ int mdbx_filesize(mdbx_filehandle_t fd, off_t *length) {
|
||||
|
||||
*length = st.st_size;
|
||||
#endif
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
int mdbx_ftruncate(mdbx_filehandle_t fd, off_t length) {
|
||||
@ -562,10 +564,10 @@ int mdbx_ftruncate(mdbx_filehandle_t fd, off_t length) {
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = length;
|
||||
return (SetFilePointerEx(fd, li, NULL, FILE_BEGIN) && SetEndOfFile(fd))
|
||||
? MDB_SUCCESS
|
||||
? MDBX_SUCCESS
|
||||
: mdbx_get_errno_checked();
|
||||
#else
|
||||
return ftruncate(fd, length) == 0 ? MDB_SUCCESS : errno;
|
||||
return ftruncate(fd, length) == 0 ? MDBX_SUCCESS : errno;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -574,7 +576,7 @@ int mdbx_ftruncate(mdbx_filehandle_t fd, off_t length) {
|
||||
int mdbx_thread_key_create(mdbx_thread_key_t *key) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
*key = TlsAlloc();
|
||||
return (*key != TLS_OUT_OF_INDEXES) ? MDB_SUCCESS : mdbx_get_errno_checked();
|
||||
return (*key != TLS_OUT_OF_INDEXES) ? MDBX_SUCCESS : mdbx_get_errno_checked();
|
||||
#else
|
||||
return pthread_key_create(key, mdbx_rthc_dtor);
|
||||
#endif
|
||||
@ -617,7 +619,7 @@ int mdbx_thread_create(mdbx_thread_t *thread,
|
||||
void *arg) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
*thread = CreateThread(NULL, 0, start_routine, arg, 0, NULL);
|
||||
return *thread ? MDB_SUCCESS : mdbx_get_errno_checked();
|
||||
return *thread ? MDBX_SUCCESS : mdbx_get_errno_checked();
|
||||
#else
|
||||
return pthread_create(thread, NULL, start_routine, arg);
|
||||
#endif
|
||||
@ -638,10 +640,11 @@ int mdbx_thread_join(mdbx_thread_t thread) {
|
||||
int mdbx_msync(void *addr, size_t length, int async) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
if (async)
|
||||
return MDB_SUCCESS;
|
||||
return FlushViewOfFile(addr, length) ? MDB_SUCCESS : mdbx_get_errno_checked();
|
||||
return MDBX_SUCCESS;
|
||||
return FlushViewOfFile(addr, length) ? MDBX_SUCCESS
|
||||
: mdbx_get_errno_checked();
|
||||
#else
|
||||
return (msync(addr, length, async ? MS_ASYNC : MS_SYNC) == 0) ? MDB_SUCCESS
|
||||
return (msync(addr, length, async ? MS_ASYNC : MS_SYNC) == 0) ? MDBX_SUCCESS
|
||||
: errno;
|
||||
#endif
|
||||
}
|
||||
@ -654,7 +657,7 @@ int mdbx_mremap_size(void **address, size_t old_size, size_t new_size) {
|
||||
return ERROR_CALL_NOT_IMPLEMENTED;
|
||||
#else
|
||||
*address = mremap(*address, old_size, new_size, 0, address);
|
||||
return (*address != MAP_FAILED) ? MDB_SUCCESS : errno;
|
||||
return (*address != MAP_FAILED) ? MDBX_SUCCESS : errno;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -666,31 +669,31 @@ int mdbx_mmap(void **address, size_t length, int rw, mdbx_filehandle_t fd) {
|
||||
return mdbx_get_errno_checked();
|
||||
*address = MapViewOfFileEx(h, rw ? FILE_MAP_WRITE : FILE_MAP_READ, 0, 0,
|
||||
length, *address);
|
||||
int rc = (*address != MAP_FAILED) ? MDB_SUCCESS : mdbx_get_errno_checked();
|
||||
int rc = (*address != MAP_FAILED) ? MDBX_SUCCESS : mdbx_get_errno_checked();
|
||||
CloseHandle(h);
|
||||
return rc;
|
||||
#else
|
||||
*address = mmap(NULL, length, rw ? PROT_READ | PROT_WRITE : PROT_READ,
|
||||
MAP_SHARED, fd, 0);
|
||||
return (*address != MAP_FAILED) ? MDB_SUCCESS : errno;
|
||||
return (*address != MAP_FAILED) ? MDBX_SUCCESS : errno;
|
||||
#endif
|
||||
}
|
||||
|
||||
int mdbx_munmap(void *address, size_t length) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
(void)length;
|
||||
return UnmapViewOfFile(address) ? MDB_SUCCESS : mdbx_get_errno_checked();
|
||||
return UnmapViewOfFile(address) ? MDBX_SUCCESS : mdbx_get_errno_checked();
|
||||
#else
|
||||
return (munmap(address, length) == 0) ? MDB_SUCCESS : errno;
|
||||
return (munmap(address, length) == 0) ? MDBX_SUCCESS : errno;
|
||||
#endif
|
||||
}
|
||||
|
||||
int mdbx_mlock(const void *address, size_t length) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
return VirtualLock((void *)address, length) ? MDB_SUCCESS
|
||||
return VirtualLock((void *)address, length) ? MDBX_SUCCESS
|
||||
: mdbx_get_errno_checked();
|
||||
#else
|
||||
return (mlock(address, length) == 0) ? MDB_SUCCESS : errno;
|
||||
return (mlock(address, length) == 0) ? MDBX_SUCCESS : errno;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
24
src/osal.h
24
src/osal.h
@ -315,7 +315,7 @@ static __inline void mdbx_invalidate_cache(void *addr, size_t nbytes) {
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef mdbx_assert_fail
|
||||
void mdbx_assert_fail(MDB_env *env, const char *msg, const char *func,
|
||||
void mdbx_assert_fail(MDBX_env *env, const char *msg, const char *func,
|
||||
int line);
|
||||
#endif /* mdbx_assert_fail */
|
||||
|
||||
@ -453,20 +453,20 @@ void mdbx_osal_jitter(bool tiny);
|
||||
#define MDBX_OSAL_LOCK_SIGN MDBX_TETRAD('P', 'T', 'M', 'X')
|
||||
#endif
|
||||
|
||||
int mdbx_lck_init(MDB_env *env);
|
||||
int mdbx_lck_init(MDBX_env *env);
|
||||
|
||||
int mdbx_lck_seize(MDB_env *env);
|
||||
int mdbx_lck_downgrade(MDB_env *env);
|
||||
void mdbx_lck_destroy(MDB_env *env);
|
||||
int mdbx_lck_seize(MDBX_env *env);
|
||||
int mdbx_lck_downgrade(MDBX_env *env);
|
||||
void mdbx_lck_destroy(MDBX_env *env);
|
||||
|
||||
int mdbx_rdt_lock(MDB_env *env);
|
||||
void mdbx_rdt_unlock(MDB_env *env);
|
||||
int mdbx_rdt_lock(MDBX_env *env);
|
||||
void mdbx_rdt_unlock(MDBX_env *env);
|
||||
|
||||
int mdbx_txn_lock(MDB_env *env);
|
||||
void mdbx_txn_unlock(MDB_env *env);
|
||||
int mdbx_txn_lock(MDBX_env *env);
|
||||
void mdbx_txn_unlock(MDBX_env *env);
|
||||
|
||||
int mdbx_rpid_set(MDB_env *env);
|
||||
int mdbx_rpid_clear(MDB_env *env);
|
||||
int mdbx_rpid_set(MDBX_env *env);
|
||||
int mdbx_rpid_clear(MDBX_env *env);
|
||||
|
||||
/* Checks reader by pid.
|
||||
*
|
||||
@ -474,7 +474,7 @@ int mdbx_rpid_clear(MDB_env *env);
|
||||
* MDBX_RESULT_TRUE, if pid is live (unable to acquire lock)
|
||||
* MDBX_RESULT_FALSE, if pid is dead (lock acquired)
|
||||
* or otherwise the errcode. */
|
||||
int mdbx_rpid_check(MDB_env *env, mdbx_pid_t pid);
|
||||
int mdbx_rpid_check(MDBX_env *env, mdbx_pid_t pid);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
|
@ -34,12 +34,12 @@ typedef struct flagbit {
|
||||
char *name;
|
||||
} flagbit;
|
||||
|
||||
flagbit dbflags[] = {{MDB_DUPSORT, "dupsort"},
|
||||
{MDB_INTEGERKEY, "integerkey"},
|
||||
{MDB_REVERSEKEY, "reversekey"},
|
||||
{MDB_DUPFIXED, "dupfixed"},
|
||||
{MDB_REVERSEDUP, "reversedup"},
|
||||
{MDB_INTEGERDUP, "integerdup"},
|
||||
flagbit dbflags[] = {{MDBX_DUPSORT, "dupsort"},
|
||||
{MDBX_INTEGERKEY, "integerkey"},
|
||||
{MDBX_REVERSEKEY, "reversekey"},
|
||||
{MDBX_DUPFIXED, "dupfixed"},
|
||||
{MDBX_REVERSEDUP, "reversedup"},
|
||||
{MDBX_INTEGERDUP, "integerdup"},
|
||||
{0, NULL}};
|
||||
|
||||
static volatile sig_atomic_t gotsignal;
|
||||
@ -75,7 +75,7 @@ static __attribute__((constructor)) void init_walk(void) {
|
||||
uint64_t total_unused_bytes;
|
||||
int exclusive = 2;
|
||||
|
||||
MDB_env *env;
|
||||
MDBX_env *env;
|
||||
MDBX_txn *txn, *locktxn;
|
||||
MDBX_envinfo envinfo;
|
||||
MDBX_stat envstat;
|
||||
@ -298,19 +298,19 @@ static int pgvisitor(uint64_t pgno, unsigned pgnumber, void *ctx,
|
||||
}
|
||||
}
|
||||
|
||||
return gotsignal ? EINTR : MDB_SUCCESS;
|
||||
return gotsignal ? EINTR : MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
typedef int(visitor)(const uint64_t record_number, const MDBX_val *key,
|
||||
const MDBX_val *data);
|
||||
static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent);
|
||||
static int process_db(MDBX_dbi dbi, char *name, visitor *handler, int silent);
|
||||
|
||||
static int handle_userdb(const uint64_t record_number, const MDBX_val *key,
|
||||
const MDBX_val *data) {
|
||||
(void)record_number;
|
||||
(void)key;
|
||||
(void)data;
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
static int handle_freedb(const uint64_t record_number, const MDBX_val *key,
|
||||
@ -332,7 +332,7 @@ static int handle_freedb(const uint64_t record_number, const MDBX_val *key,
|
||||
data->iov_len);
|
||||
else {
|
||||
number = *iptr++;
|
||||
if (number >= MDB_IDL_UM_MAX)
|
||||
if (number >= MDBX_IDL_UM_MAX)
|
||||
problem_add("entry", record_number, "wrong idl length", "%" PRIiPTR "",
|
||||
number);
|
||||
else if ((number + 1) * sizeof(pgno_t) != data->iov_len)
|
||||
@ -378,7 +378,7 @@ static int handle_freedb(const uint64_t record_number, const MDBX_val *key,
|
||||
}
|
||||
}
|
||||
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
static int handle_maindb(const uint64_t record_number, const MDBX_val *key,
|
||||
@ -400,14 +400,14 @@ static int handle_maindb(const uint64_t record_number, const MDBX_val *key,
|
||||
|
||||
rc = process_db(-1, name, handle_userdb, 0);
|
||||
free(name);
|
||||
if (rc != MDB_INCOMPATIBLE)
|
||||
if (rc != MDBX_INCOMPATIBLE)
|
||||
return rc;
|
||||
|
||||
return handle_userdb(record_number, key, data);
|
||||
}
|
||||
|
||||
static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
||||
MDB_cursor *mc;
|
||||
static int process_db(MDBX_dbi dbi, char *name, visitor *handler, int silent) {
|
||||
MDBX_cursor *mc;
|
||||
MDBX_stat ms;
|
||||
MDBX_val key, data;
|
||||
MDBX_val prev_key, prev_data;
|
||||
@ -424,7 +424,7 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
||||
if (rc) {
|
||||
if (!name ||
|
||||
rc !=
|
||||
MDB_INCOMPATIBLE) /* LY: mainDB's record is not a user's DB. */ {
|
||||
MDBX_INCOMPATIBLE) /* LY: mainDB's record is not a user's DB. */ {
|
||||
error(" - mdbx_open '%s' failed, error %d %s\n", name ? name : "main",
|
||||
rc, mdbx_strerror(rc));
|
||||
}
|
||||
@ -439,7 +439,7 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
||||
fflush(NULL);
|
||||
}
|
||||
skipped_subdb++;
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
if (!silent && verbose) {
|
||||
@ -488,8 +488,8 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
||||
saved_list = problems_push();
|
||||
prev_key.iov_base = NULL;
|
||||
prev_data.iov_len = 0;
|
||||
rc = mdbx_cursor_get(mc, &key, &data, MDB_FIRST);
|
||||
while (rc == MDB_SUCCESS) {
|
||||
rc = mdbx_cursor_get(mc, &key, &data, MDBX_FIRST);
|
||||
while (rc == MDBX_SUCCESS) {
|
||||
if (gotsignal) {
|
||||
print(" - interrupted by signal\n");
|
||||
fflush(NULL);
|
||||
@ -500,20 +500,20 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
||||
if (key.iov_len > maxkeysize) {
|
||||
problem_add("entry", record_count, "key length exceeds max-key-size",
|
||||
"%" PRIuPTR " > %u", key.iov_len, maxkeysize);
|
||||
} else if ((flags & MDB_INTEGERKEY) && key.iov_len != sizeof(uint64_t) &&
|
||||
} else if ((flags & MDBX_INTEGERKEY) && key.iov_len != sizeof(uint64_t) &&
|
||||
key.iov_len != sizeof(uint32_t)) {
|
||||
problem_add("entry", record_count, "wrong key length",
|
||||
"%" PRIuPTR " != 4or8", key.iov_len);
|
||||
}
|
||||
|
||||
if ((flags & MDB_INTEGERDUP) && data.iov_len != sizeof(uint64_t) &&
|
||||
if ((flags & MDBX_INTEGERDUP) && data.iov_len != sizeof(uint64_t) &&
|
||||
data.iov_len != sizeof(uint32_t)) {
|
||||
problem_add("entry", record_count, "wrong data length",
|
||||
"%" PRIuPTR " != 4or8", data.iov_len);
|
||||
}
|
||||
|
||||
if (prev_key.iov_base) {
|
||||
if ((flags & MDB_DUPFIXED) && prev_data.iov_len != data.iov_len) {
|
||||
if ((flags & MDBX_DUPFIXED) && prev_data.iov_len != data.iov_len) {
|
||||
problem_add("entry", record_count, "different data length",
|
||||
"%" PRIuPTR " != %" PRIuPTR "", prev_data.iov_len,
|
||||
data.iov_len);
|
||||
@ -524,9 +524,9 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
||||
problem_add("entry", record_count, "broken ordering of entries", NULL);
|
||||
} else if (cmp == 0) {
|
||||
++dups;
|
||||
if (!(flags & MDB_DUPSORT))
|
||||
if (!(flags & MDBX_DUPSORT))
|
||||
problem_add("entry", record_count, "duplicated entries", NULL);
|
||||
else if (flags & MDB_INTEGERDUP) {
|
||||
else if (flags & MDBX_INTEGERDUP) {
|
||||
cmp = mdbx_dcmp(txn, dbi, &prev_data, &data);
|
||||
if (cmp > 0)
|
||||
problem_add("entry", record_count,
|
||||
@ -534,9 +534,9 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
||||
}
|
||||
}
|
||||
} else if (verbose) {
|
||||
if (flags & MDB_INTEGERKEY)
|
||||
if (flags & MDBX_INTEGERKEY)
|
||||
print(" - fixed key-size %" PRIuPTR "\n", key.iov_len);
|
||||
if (flags & (MDB_INTEGERDUP | MDB_DUPFIXED))
|
||||
if (flags & (MDBX_INTEGERDUP | MDBX_DUPFIXED))
|
||||
print(" - fixed data-size %" PRIuPTR "\n", data.iov_len);
|
||||
}
|
||||
|
||||
@ -552,9 +552,9 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
||||
|
||||
prev_key = key;
|
||||
prev_data = data;
|
||||
rc = mdbx_cursor_get(mc, &key, &data, MDB_NEXT);
|
||||
rc = mdbx_cursor_get(mc, &key, &data, MDBX_NEXT);
|
||||
}
|
||||
if (rc != MDB_NOTFOUND)
|
||||
if (rc != MDBX_NOTFOUND)
|
||||
error(" - mdbx_cursor_get failed, error %d %s\n", rc, mdbx_strerror(rc));
|
||||
else
|
||||
rc = 0;
|
||||
@ -612,7 +612,7 @@ int main(int argc, char *argv[]) {
|
||||
int i, rc;
|
||||
char *prog = argv[0];
|
||||
char *envname;
|
||||
int envflags = MDB_RDONLY;
|
||||
int envflags = MDBX_RDONLY;
|
||||
int problems_maindb = 0, problems_freedb = 0, problems_meta = 0;
|
||||
int dont_traversal = 0;
|
||||
struct timespec timestamp_start, timestamp_finish;
|
||||
@ -644,10 +644,10 @@ int main(int argc, char *argv[]) {
|
||||
quiet = 1;
|
||||
break;
|
||||
case 'n':
|
||||
envflags |= MDB_NOSUBDIR;
|
||||
envflags |= MDBX_NOSUBDIR;
|
||||
break;
|
||||
case 'w':
|
||||
envflags &= ~MDB_RDONLY;
|
||||
envflags &= ~MDBX_RDONLY;
|
||||
break;
|
||||
case 'c':
|
||||
exclusive = 0;
|
||||
@ -679,7 +679,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
envname = argv[optind];
|
||||
print("Running mdbx_chk for '%s' in %s mode...\n", envname,
|
||||
(envflags & MDB_RDONLY) ? "read-only" : "write-lock");
|
||||
(envflags & MDBX_RDONLY) ? "read-only" : "write-lock");
|
||||
fflush(NULL);
|
||||
|
||||
rc = mdbx_env_create(&env);
|
||||
@ -697,14 +697,14 @@ int main(int argc, char *argv[]) {
|
||||
rc = mdbx_env_open_ex(env, envname, envflags, 0664, &exclusive);
|
||||
if (rc) {
|
||||
error("mdbx_env_open failed, error %d %s\n", rc, mdbx_strerror(rc));
|
||||
if (rc == MDBX_WANNA_RECOVERY && (envflags & MDB_RDONLY))
|
||||
if (rc == MDBX_WANNA_RECOVERY && (envflags & MDBX_RDONLY))
|
||||
print("Please run %s in the read-write mode (with '-w' option).\n", prog);
|
||||
goto bailout;
|
||||
}
|
||||
if (verbose)
|
||||
print(" - %s mode\n", exclusive ? "monopolistic" : "cooperative");
|
||||
|
||||
if (!(envflags & MDB_RDONLY)) {
|
||||
if (!(envflags & MDBX_RDONLY)) {
|
||||
rc = mdbx_txn_begin(env, NULL, 0, &locktxn);
|
||||
if (rc) {
|
||||
error("mdbx_txn_begin(lock-write) failed, error %d %s\n", rc,
|
||||
@ -721,7 +721,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
maxkeysize = rc;
|
||||
|
||||
rc = mdbx_txn_begin(env, NULL, MDB_RDONLY, &txn);
|
||||
rc = mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn);
|
||||
if (rc) {
|
||||
error("mdbx_txn_begin(read-only) failed, error %d %s\n", rc,
|
||||
mdbx_strerror(rc));
|
||||
|
@ -2,9 +2,9 @@
|
||||
.\" Copyright 2012-2015 Howard Chu, Symas Corp. All Rights Reserved.
|
||||
.\" Copyright 2015,2016 Peter-Service R&D LLC <http://billing.ru/>.
|
||||
.\" Copying restrictions apply. See COPYRIGHT/LICENSE.
|
||||
.TH MDB_COPY 1 "2014/06/20" "LMDB 0.9.14"
|
||||
.TH MDBX_COPY 1 "2014/06/20" "LMDB 0.9.14"
|
||||
.SH NAME
|
||||
mdbx_copy \- LMDB environment copy tool
|
||||
mdbx_copy \- MDBX environment copy tool
|
||||
.SH SYNOPSIS
|
||||
.B mdbx_copy
|
||||
[\c
|
||||
@ -19,7 +19,7 @@ mdbx_copy \- LMDB environment copy tool
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B mdbx_copy
|
||||
utility copies an LMDB environment. The environment can
|
||||
utility copies an MDBX environment. The environment can
|
||||
be copied regardless of whether it is currently in use.
|
||||
No lockfile is created, since it gets recreated at need.
|
||||
|
||||
|
@ -23,16 +23,16 @@ static void sighandle(int sig) { (void)sig; }
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int rc;
|
||||
MDB_env *env = NULL;
|
||||
MDBX_env *env = NULL;
|
||||
const char *progname = argv[0], *act;
|
||||
unsigned flags = MDB_RDONLY;
|
||||
unsigned flags = MDBX_RDONLY;
|
||||
unsigned cpflags = 0;
|
||||
|
||||
for (; argc > 1 && argv[1][0] == '-'; argc--, argv++) {
|
||||
if (argv[1][1] == 'n' && argv[1][2] == '\0')
|
||||
flags |= MDB_NOSUBDIR;
|
||||
flags |= MDBX_NOSUBDIR;
|
||||
else if (argv[1][1] == 'c' && argv[1][2] == '\0')
|
||||
cpflags |= MDB_CP_COMPACT;
|
||||
cpflags |= MDBX_CP_COMPACT;
|
||||
else if (argv[1][1] == 'V' && argv[1][2] == '\0') {
|
||||
printf("%s (%s, build %s)\n", mdbx_version.git.describe,
|
||||
mdbx_version.git.datetime, mdbx_build.datetime);
|
||||
@ -57,10 +57,10 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
act = "opening environment";
|
||||
rc = mdbx_env_create(&env);
|
||||
if (rc == MDB_SUCCESS) {
|
||||
if (rc == MDBX_SUCCESS) {
|
||||
rc = mdbx_env_open(env, argv[1], flags, 0640);
|
||||
}
|
||||
if (rc == MDB_SUCCESS) {
|
||||
if (rc == MDBX_SUCCESS) {
|
||||
act = "copying";
|
||||
if (argc == 2)
|
||||
rc = mdbx_env_copy2fd(env, STDOUT_FILENO, cpflags);
|
||||
|
@ -2,9 +2,9 @@
|
||||
.\" Copyright 2014-2015 Howard Chu, Symas Corp. All Rights Reserved.
|
||||
.\" Copyright 2015,2016 Peter-Service R&D LLC <http://billing.ru/>.
|
||||
.\" Copying restrictions apply. See COPYRIGHT/LICENSE.
|
||||
.TH MDB_DUMP 1 "2014/06/20" "LMDB 0.9.14"
|
||||
.TH MDBX_DUMP 1 "2014/06/20" "LMDB 0.9.14"
|
||||
.SH NAME
|
||||
mdbx_dump \- LMDB environment export tool
|
||||
mdbx_dump \- MDBX environment export tool
|
||||
.SH SYNOPSIS
|
||||
.B mdbx_dump
|
||||
[\c
|
||||
@ -42,7 +42,7 @@ List the databases stored in the environment. Just the
|
||||
names will be listed, no data will be output.
|
||||
.TP
|
||||
.BR \-n
|
||||
Dump an LMDB database which does not use subdirectories.
|
||||
Dump an MDBX database which does not use subdirectories.
|
||||
.TP
|
||||
.BR \-p
|
||||
If characters in either the key or data items are printing characters (as
|
||||
|
@ -31,12 +31,12 @@ typedef struct flagbit {
|
||||
char *name;
|
||||
} flagbit;
|
||||
|
||||
flagbit dbflags[] = {{MDB_REVERSEKEY, "reversekey"},
|
||||
{MDB_DUPSORT, "dupsort"},
|
||||
{MDB_INTEGERKEY, "integerkey"},
|
||||
{MDB_DUPFIXED, "dupfixed"},
|
||||
{MDB_INTEGERDUP, "integerdup"},
|
||||
{MDB_REVERSEDUP, "reversedup"},
|
||||
flagbit dbflags[] = {{MDBX_REVERSEKEY, "reversekey"},
|
||||
{MDBX_DUPSORT, "dupsort"},
|
||||
{MDBX_INTEGERKEY, "integerkey"},
|
||||
{MDBX_DUPFIXED, "dupfixed"},
|
||||
{MDBX_INTEGERDUP, "integerdup"},
|
||||
{MDBX_REVERSEDUP, "reversedup"},
|
||||
{0, NULL}};
|
||||
|
||||
static volatile sig_atomic_t gotsig;
|
||||
@ -84,8 +84,8 @@ static void byte(MDBX_val *v) {
|
||||
}
|
||||
|
||||
/* Dump in BDB-compatible format */
|
||||
static int dumpit(MDBX_txn *txn, MDB_dbi dbi, char *name) {
|
||||
MDB_cursor *mc;
|
||||
static int dumpit(MDBX_txn *txn, MDBX_dbi dbi, char *name) {
|
||||
MDBX_cursor *mc;
|
||||
MDBX_stat ms;
|
||||
MDBX_val key, data;
|
||||
MDBX_envinfo info;
|
||||
@ -125,7 +125,7 @@ static int dumpit(MDBX_txn *txn, MDB_dbi dbi, char *name) {
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
while ((rc = mdbx_cursor_get(mc, &key, &data, MDB_NEXT)) == MDB_SUCCESS) {
|
||||
while ((rc = mdbx_cursor_get(mc, &key, &data, MDBX_NEXT)) == MDBX_SUCCESS) {
|
||||
if (gotsig) {
|
||||
rc = EINTR;
|
||||
break;
|
||||
@ -139,8 +139,8 @@ static int dumpit(MDBX_txn *txn, MDB_dbi dbi, char *name) {
|
||||
}
|
||||
}
|
||||
printf("DATA=END\n");
|
||||
if (rc == MDB_NOTFOUND)
|
||||
rc = MDB_SUCCESS;
|
||||
if (rc == MDBX_NOTFOUND)
|
||||
rc = MDBX_SUCCESS;
|
||||
|
||||
return rc;
|
||||
}
|
||||
@ -154,9 +154,9 @@ static void usage(char *prog) {
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i, rc;
|
||||
MDB_env *env;
|
||||
MDBX_env *env;
|
||||
MDBX_txn *txn;
|
||||
MDB_dbi dbi;
|
||||
MDBX_dbi dbi;
|
||||
char *prog = argv[0];
|
||||
char *envname;
|
||||
char *subname = NULL;
|
||||
@ -196,7 +196,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
envflags |= MDB_NOSUBDIR;
|
||||
envflags |= MDBX_NOSUBDIR;
|
||||
break;
|
||||
case 'p':
|
||||
mode |= PRINT;
|
||||
@ -235,14 +235,14 @@ int main(int argc, char *argv[]) {
|
||||
mdbx_env_set_maxdbs(env, 2);
|
||||
}
|
||||
|
||||
rc = mdbx_env_open(env, envname, envflags | MDB_RDONLY, 0664);
|
||||
rc = mdbx_env_open(env, envname, envflags | MDBX_RDONLY, 0664);
|
||||
if (rc) {
|
||||
fprintf(stderr, "mdbx_env_open failed, error %d %s\n", rc,
|
||||
mdbx_strerror(rc));
|
||||
goto env_close;
|
||||
}
|
||||
|
||||
rc = mdbx_txn_begin(env, NULL, MDB_RDONLY, &txn);
|
||||
rc = mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn);
|
||||
if (rc) {
|
||||
fprintf(stderr, "mdbx_txn_begin failed, error %d %s\n", rc,
|
||||
mdbx_strerror(rc));
|
||||
@ -256,7 +256,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (alldbs) {
|
||||
MDB_cursor *cursor;
|
||||
MDBX_cursor *cursor;
|
||||
MDBX_val key;
|
||||
int count = 0;
|
||||
|
||||
@ -266,9 +266,9 @@ int main(int argc, char *argv[]) {
|
||||
mdbx_strerror(rc));
|
||||
goto txn_abort;
|
||||
}
|
||||
while ((rc = mdbx_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
|
||||
while ((rc = mdbx_cursor_get(cursor, &key, NULL, MDBX_NEXT_NODUP)) == 0) {
|
||||
char *str;
|
||||
MDB_dbi db2;
|
||||
MDBX_dbi db2;
|
||||
if (memchr(key.iov_base, '\0', key.iov_len))
|
||||
continue;
|
||||
count++;
|
||||
@ -276,7 +276,7 @@ int main(int argc, char *argv[]) {
|
||||
memcpy(str, key.iov_base, key.iov_len);
|
||||
str[key.iov_len] = '\0';
|
||||
rc = mdbx_dbi_open(txn, str, 0, &db2);
|
||||
if (rc == MDB_SUCCESS) {
|
||||
if (rc == MDBX_SUCCESS) {
|
||||
if (list) {
|
||||
printf("%s\n", str);
|
||||
list++;
|
||||
@ -295,15 +295,15 @@ int main(int argc, char *argv[]) {
|
||||
if (!count) {
|
||||
fprintf(stderr, "%s: %s does not contain multiple databases\n", prog,
|
||||
envname);
|
||||
rc = MDB_NOTFOUND;
|
||||
} else if (rc == MDB_INCOMPATIBLE) {
|
||||
rc = MDBX_NOTFOUND;
|
||||
} else if (rc == MDBX_INCOMPATIBLE) {
|
||||
/* LY: the record it not a named sub-db. */
|
||||
rc = MDB_SUCCESS;
|
||||
rc = MDBX_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
rc = dumpit(txn, dbi, subname);
|
||||
}
|
||||
if (rc && rc != MDB_NOTFOUND)
|
||||
if (rc && rc != MDBX_NOTFOUND)
|
||||
fprintf(stderr, "%s: %s: %s\n", prog, envname, mdbx_strerror(rc));
|
||||
|
||||
mdbx_dbi_close(env, dbi);
|
||||
|
@ -2,9 +2,9 @@
|
||||
.\" Copyright 2014-2015 Howard Chu, Symas Corp. All Rights Reserved.
|
||||
.\" Copyright 2015,2016 Peter-Service R&D LLC <http://billing.ru/>.
|
||||
.\" Copying restrictions apply. See COPYRIGHT/LICENSE.
|
||||
.TH MDB_LOAD 1 "2014/06/20" "LMDB 0.9.14"
|
||||
.TH MDBX_LOAD 1 "2014/06/20" "LMDB 0.9.14"
|
||||
.SH NAME
|
||||
mdbx_load \- LMDB environment import tool
|
||||
mdbx_load \- MDBX environment import tool
|
||||
.SH SYNOPSIS
|
||||
.B mdbx_load
|
||||
[\c
|
||||
@ -24,7 +24,7 @@ mdbx_load \- LMDB environment import tool
|
||||
The
|
||||
.B mdbx_load
|
||||
utility reads from the standard input and loads it into the
|
||||
LMDB environment
|
||||
MDBX environment
|
||||
.BR envpath .
|
||||
|
||||
The input to
|
||||
@ -43,7 +43,7 @@ Write the library version number to the standard output, and exit.
|
||||
Read from the specified file instead of from the standard input.
|
||||
.TP
|
||||
.BR \-n
|
||||
Load an LMDB database which does not use subdirectories.
|
||||
Load an MDBX database which does not use subdirectories.
|
||||
.TP
|
||||
.BR \-s \ subdb
|
||||
Load a specific subdatabase. If no database is specified, data is loaded into the main database.
|
||||
|
@ -51,12 +51,12 @@ typedef struct flagbit {
|
||||
|
||||
#define S(s) s, STRLENOF(s)
|
||||
|
||||
flagbit dbflags[] = {{MDB_REVERSEKEY, S("reversekey")},
|
||||
{MDB_DUPSORT, S("dupsort")},
|
||||
{MDB_INTEGERKEY, S("integerkey")},
|
||||
{MDB_DUPFIXED, S("dupfixed")},
|
||||
{MDB_INTEGERDUP, S("integerdup")},
|
||||
{MDB_REVERSEDUP, S("reversedup")},
|
||||
flagbit dbflags[] = {{MDBX_REVERSEKEY, S("reversekey")},
|
||||
{MDBX_DUPSORT, S("dupsort")},
|
||||
{MDBX_INTEGERKEY, S("integerkey")},
|
||||
{MDBX_DUPFIXED, S("dupfixed")},
|
||||
{MDBX_INTEGERDUP, S("integerdup")},
|
||||
{MDBX_REVERSEDUP, S("reversedup")},
|
||||
{0, NULL, 0}};
|
||||
|
||||
static void readhdr(void) {
|
||||
@ -294,10 +294,10 @@ static void usage(void) {
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i, rc;
|
||||
MDB_env *env;
|
||||
MDBX_env *env;
|
||||
MDBX_txn *txn;
|
||||
MDB_cursor *mc;
|
||||
MDB_dbi dbi;
|
||||
MDBX_cursor *mc;
|
||||
MDBX_dbi dbi;
|
||||
char *envname;
|
||||
int envflags = 0, putflags = 0;
|
||||
|
||||
@ -328,13 +328,13 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
envflags |= MDB_NOSUBDIR;
|
||||
envflags |= MDBX_NOSUBDIR;
|
||||
break;
|
||||
case 's':
|
||||
subname = strdup(optarg);
|
||||
break;
|
||||
case 'N':
|
||||
putflags = MDB_NOOVERWRITE | MDB_NODUPDATA;
|
||||
putflags = MDBX_NOOVERWRITE | MDBX_NODUPDATA;
|
||||
break;
|
||||
case 'T':
|
||||
mode |= NOHDR | PRINT;
|
||||
@ -369,9 +369,9 @@ int main(int argc, char *argv[]) {
|
||||
if (envinfo.me_mapsize)
|
||||
mdbx_env_set_mapsize(env, envinfo.me_mapsize);
|
||||
|
||||
#ifdef MDB_FIXEDMAP
|
||||
#ifdef MDBX_FIXEDMAP
|
||||
if (info.me_mapaddr)
|
||||
envflags |= MDB_FIXEDMAP;
|
||||
envflags |= MDBX_FIXEDMAP;
|
||||
#endif
|
||||
|
||||
rc = mdbx_env_open(env, envname, envflags, 0664);
|
||||
@ -395,7 +395,7 @@ int main(int argc, char *argv[]) {
|
||||
goto env_close;
|
||||
}
|
||||
|
||||
rc = mdbx_dbi_open(txn, subname, dbi_flags | MDB_CREATE, &dbi);
|
||||
rc = mdbx_dbi_open(txn, subname, dbi_flags | MDBX_CREATE, &dbi);
|
||||
if (rc) {
|
||||
fprintf(stderr, "mdbx_open failed, error %d %s\n", rc, mdbx_strerror(rc));
|
||||
goto txn_abort;
|
||||
@ -421,7 +421,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
rc = mdbx_cursor_put(mc, &key, &data, putflags);
|
||||
if (rc == MDB_KEYEXIST && putflags)
|
||||
if (rc == MDBX_KEYEXIST && putflags)
|
||||
continue;
|
||||
if (rc) {
|
||||
fprintf(stderr, "mdbx_cursor_put failed, error %d %s\n", rc,
|
||||
|
@ -2,9 +2,9 @@
|
||||
.\" Copyright 2012-2015 Howard Chu, Symas Corp. All Rights Reserved.
|
||||
.\" Copyright 2015,2016 Peter-Service R&D LLC <http://billing.ru/>.
|
||||
.\" Copying restrictions apply. See COPYRIGHT/LICENSE.
|
||||
.TH MDB_STAT 1 "2014/06/20" "LMDB 0.9.14"
|
||||
.TH MDBX_STAT 1 "2014/06/20" "LMDB 0.9.14"
|
||||
.SH NAME
|
||||
mdbx_stat \- LMDB environment status tool
|
||||
mdbx_stat \- MDBX environment status tool
|
||||
.SH SYNOPSIS
|
||||
.B mdbx_stat
|
||||
[\c
|
||||
@ -24,7 +24,7 @@ mdbx_stat \- LMDB environment status tool
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B mdbx_stat
|
||||
utility displays the status of an LMDB environment.
|
||||
utility displays the status of an MDBX environment.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BR \-V
|
||||
@ -39,7 +39,7 @@ If \fB\-ff\fP is given, summarize each freelist entry.
|
||||
If \fB\-fff\fP is given, display the full list of page IDs in the freelist.
|
||||
.TP
|
||||
.BR \-n
|
||||
Display the status of an LMDB database which does not use subdirectories.
|
||||
Display the status of an MDBX database which does not use subdirectories.
|
||||
.TP
|
||||
.BR \-r
|
||||
Display information about the environment reader table.
|
||||
|
@ -38,9 +38,9 @@ static void usage(char *prog) {
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i, rc;
|
||||
MDB_env *env;
|
||||
MDBX_env *env;
|
||||
MDBX_txn *txn;
|
||||
MDB_dbi dbi;
|
||||
MDBX_dbi dbi;
|
||||
MDBX_stat mst;
|
||||
MDBX_envinfo mei;
|
||||
char *prog = argv[0];
|
||||
@ -80,7 +80,7 @@ int main(int argc, char *argv[]) {
|
||||
freinfo++;
|
||||
break;
|
||||
case 'n':
|
||||
envflags |= MDB_NOSUBDIR;
|
||||
envflags |= MDBX_NOSUBDIR;
|
||||
break;
|
||||
case 'r':
|
||||
rdrinfo++;
|
||||
@ -110,7 +110,7 @@ int main(int argc, char *argv[]) {
|
||||
mdbx_env_set_maxdbs(env, 4);
|
||||
}
|
||||
|
||||
rc = mdbx_env_open(env, envname, envflags | MDB_RDONLY, 0664);
|
||||
rc = mdbx_env_open(env, envname, envflags | MDBX_RDONLY, 0664);
|
||||
if (rc) {
|
||||
fprintf(stderr, "mdbx_env_open failed, error %d %s\n", rc,
|
||||
mdbx_strerror(rc));
|
||||
@ -139,18 +139,18 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (rdrinfo) {
|
||||
printf("Reader Table Status\n");
|
||||
rc = mdbx_reader_list(env, (MDB_msg_func *)fputs, stdout);
|
||||
rc = mdbx_reader_list(env, (MDBX_msg_func *)fputs, stdout);
|
||||
if (rdrinfo > 1) {
|
||||
int dead;
|
||||
mdbx_reader_check(env, &dead);
|
||||
printf(" %d stale readers cleared.\n", dead);
|
||||
rc = mdbx_reader_list(env, (MDB_msg_func *)fputs, stdout);
|
||||
rc = mdbx_reader_list(env, (MDBX_msg_func *)fputs, stdout);
|
||||
}
|
||||
if (!(subname || alldbs || freinfo))
|
||||
goto env_close;
|
||||
}
|
||||
|
||||
rc = mdbx_txn_begin(env, NULL, MDB_RDONLY, &txn);
|
||||
rc = mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn);
|
||||
if (rc) {
|
||||
fprintf(stderr, "mdbx_txn_begin failed, error %d %s\n", rc,
|
||||
mdbx_strerror(rc));
|
||||
@ -158,7 +158,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (freinfo) {
|
||||
MDB_cursor *cursor;
|
||||
MDBX_cursor *cursor;
|
||||
MDBX_val key, data;
|
||||
size_t pages = 0, *iptr;
|
||||
size_t reclaimable = 0;
|
||||
@ -178,7 +178,7 @@ int main(int argc, char *argv[]) {
|
||||
goto txn_abort;
|
||||
}
|
||||
prstat(&mst);
|
||||
while ((rc = mdbx_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
|
||||
while ((rc = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) == 0) {
|
||||
iptr = data.iov_base;
|
||||
pages += *iptr;
|
||||
if (envinfo && mei.me_tail_txnid > *(size_t *)key.iov_base)
|
||||
@ -262,7 +262,7 @@ int main(int argc, char *argv[]) {
|
||||
prstat(&mst);
|
||||
|
||||
if (alldbs) {
|
||||
MDB_cursor *cursor;
|
||||
MDBX_cursor *cursor;
|
||||
MDBX_val key;
|
||||
|
||||
rc = mdbx_cursor_open(txn, dbi, &cursor);
|
||||
@ -271,16 +271,16 @@ int main(int argc, char *argv[]) {
|
||||
mdbx_strerror(rc));
|
||||
goto txn_abort;
|
||||
}
|
||||
while ((rc = mdbx_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
|
||||
while ((rc = mdbx_cursor_get(cursor, &key, NULL, MDBX_NEXT_NODUP)) == 0) {
|
||||
char *str;
|
||||
MDB_dbi db2;
|
||||
MDBX_dbi db2;
|
||||
if (memchr(key.iov_base, '\0', key.iov_len))
|
||||
continue;
|
||||
str = malloc(key.iov_len + 1);
|
||||
memcpy(str, key.iov_base, key.iov_len);
|
||||
str[key.iov_len] = '\0';
|
||||
rc = mdbx_dbi_open(txn, str, 0, &db2);
|
||||
if (rc == MDB_SUCCESS)
|
||||
if (rc == MDBX_SUCCESS)
|
||||
printf("Status of %s\n", str);
|
||||
free(str);
|
||||
if (rc)
|
||||
@ -297,8 +297,8 @@ int main(int argc, char *argv[]) {
|
||||
mdbx_cursor_close(cursor);
|
||||
}
|
||||
|
||||
if (rc == MDB_NOTFOUND)
|
||||
rc = MDB_SUCCESS;
|
||||
if (rc == MDBX_NOTFOUND)
|
||||
rc = MDBX_SUCCESS;
|
||||
|
||||
mdbx_dbi_close(env, dbi);
|
||||
txn_abort:
|
||||
|
@ -226,21 +226,21 @@ bool parse_option(int argc, char *const argv[], int &narg, const char *option,
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const struct option_verb mode_bits[] = {
|
||||
{"rdonly", MDB_RDONLY}, {"mapasync", MDB_MAPASYNC},
|
||||
{"utterly", MDBX_UTTERLY_NOSYNC}, {"nosubdir", MDB_NOSUBDIR},
|
||||
{"nosync", MDB_NOSYNC}, {"nometasync", MDB_NOMETASYNC},
|
||||
{"writemap", MDB_WRITEMAP}, {"notls", MDB_NOTLS},
|
||||
{"nordahead", MDB_NORDAHEAD}, {"nomeminit", MDB_NOMEMINIT},
|
||||
{"rdonly", MDBX_RDONLY}, {"mapasync", MDBX_MAPASYNC},
|
||||
{"utterly", MDBX_UTTERLY_NOSYNC}, {"nosubdir", MDBX_NOSUBDIR},
|
||||
{"nosync", MDBX_NOSYNC}, {"nometasync", MDBX_NOMETASYNC},
|
||||
{"writemap", MDBX_WRITEMAP}, {"notls", MDBX_NOTLS},
|
||||
{"nordahead", MDBX_NORDAHEAD}, {"nomeminit", MDBX_NOMEMINIT},
|
||||
{"coasesce", MDBX_COALESCE}, {"lifo", MDBX_LIFORECLAIM},
|
||||
{"parturb", MDBX_PAGEPERTURB}, {nullptr, 0}};
|
||||
|
||||
const struct option_verb table_bits[] = {
|
||||
{"key.reverse", MDB_REVERSEKEY},
|
||||
{"key.integer", MDB_INTEGERKEY},
|
||||
{"data.integer", MDB_INTEGERDUP | MDB_DUPFIXED | MDB_DUPSORT},
|
||||
{"data.fixed", MDB_DUPFIXED | MDB_DUPSORT},
|
||||
{"data.reverse", MDB_REVERSEDUP | MDB_DUPSORT},
|
||||
{"data.dups", MDB_DUPSORT},
|
||||
{"key.reverse", MDBX_REVERSEKEY},
|
||||
{"key.integer", MDBX_INTEGERKEY},
|
||||
{"data.integer", MDBX_INTEGERDUP | MDBX_DUPFIXED | MDBX_DUPSORT},
|
||||
{"data.fixed", MDBX_DUPFIXED | MDBX_DUPSORT},
|
||||
{"data.reverse", MDBX_REVERSEDUP | MDBX_DUPSORT},
|
||||
{"data.dups", MDBX_DUPSORT},
|
||||
{nullptr, 0}};
|
||||
|
||||
static void dump_verbs(const char *caption, size_t bits,
|
||||
|
29
test/hill.cc
29
test/hill.cc
@ -29,7 +29,7 @@ bool testcase_hill::run() {
|
||||
db_open();
|
||||
|
||||
txn_begin(false);
|
||||
MDB_dbi dbi = db_table_open(true);
|
||||
MDBX_dbi dbi = db_table_open(true);
|
||||
txn_end(false);
|
||||
|
||||
/* LY: тест "холмиком":
|
||||
@ -46,7 +46,7 @@ bool testcase_hill::run() {
|
||||
* итерирование ключей интервалами различной ширины, с тем чтобы
|
||||
* проверить различные варианты как разделения, так и слияния страниц
|
||||
* внутри движка.
|
||||
* - при не-уникальных ключах (MDB_DUPSORT с подвариантами), для каждого
|
||||
* - при не-уникальных ключах (MDBX_DUPSORT с подвариантами), для каждого
|
||||
* повтора внутри движка формируется вложенное btree-дерево,
|
||||
* соответственно требуется соблюдение аналогичных принципов
|
||||
* итерирования для значений.
|
||||
@ -61,10 +61,11 @@ bool testcase_hill::run() {
|
||||
keygen::buffer b_key = keygen::alloc(config.params.keylen_max);
|
||||
keygen::buffer b_data = keygen::alloc(config.params.datalen_max);
|
||||
|
||||
const unsigned insert_flags = (config.params.table_flags & MDB_DUPSORT)
|
||||
? MDB_NODUPDATA
|
||||
: MDB_NODUPDATA | MDB_NOOVERWRITE;
|
||||
const unsigned update_flags = MDB_CURRENT | MDB_NODUPDATA | MDB_NOOVERWRITE;
|
||||
const unsigned insert_flags = (config.params.table_flags & MDBX_DUPSORT)
|
||||
? MDBX_NODUPDATA
|
||||
: MDBX_NODUPDATA | MDBX_NOOVERWRITE;
|
||||
const unsigned update_flags =
|
||||
MDBX_CURRENT | MDBX_NODUPDATA | MDBX_NOOVERWRITE;
|
||||
|
||||
uint64_t serial_count = 0;
|
||||
unsigned txn_nops = 0;
|
||||
@ -86,7 +87,7 @@ bool testcase_hill::run() {
|
||||
generate_pair(a_serial, a_key, a_data_1, age_shift);
|
||||
int rc = mdbx_put(txn_guard.get(), dbi, &a_key->value, &a_data_1->value,
|
||||
insert_flags);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_put(insert-a.1)", rc);
|
||||
|
||||
if (++txn_nops >= config.params.batch_write) {
|
||||
@ -99,7 +100,7 @@ bool testcase_hill::run() {
|
||||
generate_pair(b_serial, b_key, b_data, 0);
|
||||
rc = mdbx_put(txn_guard.get(), dbi, &b_key->value, &b_data->value,
|
||||
insert_flags);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_put(insert-b)", rc);
|
||||
|
||||
if (++txn_nops >= config.params.batch_write) {
|
||||
@ -113,7 +114,7 @@ bool testcase_hill::run() {
|
||||
generate_pair(a_serial, a_key, a_data_0, 0);
|
||||
rc = mdbx_replace(txn_guard.get(), dbi, &a_key->value, &a_data_0->value,
|
||||
&a_data_1->value, update_flags);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_put(update-a: 1->0)", rc);
|
||||
|
||||
if (++txn_nops >= config.params.batch_write) {
|
||||
@ -124,7 +125,7 @@ bool testcase_hill::run() {
|
||||
// удаляем вторую запись
|
||||
log_trace("uphill: delete-b %" PRIu64, b_serial);
|
||||
rc = mdbx_del(txn_guard.get(), dbi, &b_key->value, &b_data->value);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_del(b)", rc);
|
||||
|
||||
if (++txn_nops >= config.params.batch_write) {
|
||||
@ -159,7 +160,7 @@ bool testcase_hill::run() {
|
||||
log_trace("!!!");
|
||||
int rc = mdbx_replace(txn_guard.get(), dbi, &a_key->value, &a_data_1->value,
|
||||
&a_data_0->value, update_flags);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_put(update-a: 0->1)", rc);
|
||||
|
||||
if (++txn_nops >= config.params.batch_write) {
|
||||
@ -172,7 +173,7 @@ bool testcase_hill::run() {
|
||||
generate_pair(b_serial, b_key, b_data, 0);
|
||||
rc = mdbx_put(txn_guard.get(), dbi, &b_key->value, &b_data->value,
|
||||
insert_flags);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_put(insert-b)", rc);
|
||||
|
||||
if (++txn_nops >= config.params.batch_write) {
|
||||
@ -184,7 +185,7 @@ bool testcase_hill::run() {
|
||||
log_trace("downhill: delete-a (age %" PRIu64 ") %" PRIu64, age_shift,
|
||||
a_serial);
|
||||
rc = mdbx_del(txn_guard.get(), dbi, &a_key->value, &a_data_1->value);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_del(a)", rc);
|
||||
|
||||
if (++txn_nops >= config.params.batch_write) {
|
||||
@ -195,7 +196,7 @@ bool testcase_hill::run() {
|
||||
// удаляем вторую запись
|
||||
log_trace("downhill: delete-b %" PRIu64, b_serial);
|
||||
rc = mdbx_del(txn_guard.get(), dbi, &b_key->value, &b_data->value);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_del(b)", rc);
|
||||
|
||||
if (++txn_nops >= config.params.batch_write) {
|
||||
|
@ -73,8 +73,8 @@ void __hot maker::pair(serial_t serial, const buffer &key, buffer &value,
|
||||
assert(mapping.mesh <= mapping.width);
|
||||
assert(mapping.rotate <= mapping.width);
|
||||
assert(mapping.offset <= mask(mapping.width));
|
||||
assert(!(key_essentials.flags & (MDB_INTEGERDUP | MDB_REVERSEDUP)));
|
||||
assert(!(value_essentials.flags & (MDB_INTEGERKEY | MDB_REVERSEKEY)));
|
||||
assert(!(key_essentials.flags & (MDBX_INTEGERDUP | MDBX_REVERSEDUP)));
|
||||
assert(!(value_essentials.flags & (MDBX_INTEGERKEY | MDBX_REVERSEKEY)));
|
||||
|
||||
log_trace("keygen-pair: serial %" PRIu64 ", data-age %" PRIu64, serial,
|
||||
value_age);
|
||||
@ -120,12 +120,13 @@ void __hot maker::pair(serial_t serial, const buffer &key, buffer &value,
|
||||
|
||||
void maker::setup(const config::actor_params_pod &actor,
|
||||
unsigned thread_number) {
|
||||
key_essentials.flags = actor.table_flags & (MDB_INTEGERKEY | MDB_REVERSEKEY);
|
||||
key_essentials.flags =
|
||||
actor.table_flags & (MDBX_INTEGERKEY | MDBX_REVERSEKEY);
|
||||
key_essentials.minlen = actor.keylen_min;
|
||||
key_essentials.maxlen = actor.keylen_max;
|
||||
|
||||
value_essentials.flags =
|
||||
actor.table_flags & (MDB_INTEGERDUP | MDB_REVERSEDUP);
|
||||
actor.table_flags & (MDBX_INTEGERDUP | MDBX_REVERSEDUP);
|
||||
value_essentials.minlen = actor.datalen_min;
|
||||
value_essentials.maxlen = actor.datalen_max;
|
||||
|
||||
@ -196,14 +197,14 @@ void __hot maker::mk(const serial_t serial, const essentials ¶ms,
|
||||
out.value.iov_base = out.bytes;
|
||||
out.value.iov_len = params.minlen;
|
||||
|
||||
if (params.flags & (MDB_INTEGERKEY | MDB_INTEGERDUP)) {
|
||||
if (params.flags & (MDBX_INTEGERKEY | MDBX_INTEGERDUP)) {
|
||||
assert(params.maxlen == params.minlen);
|
||||
assert(params.minlen == 4 || params.minlen == 8);
|
||||
if (is_byteorder_le() || params.minlen == 8)
|
||||
out.u64 = serial;
|
||||
else
|
||||
out.u32 = (uint32_t)serial;
|
||||
} else if (params.flags & (MDB_REVERSEKEY | MDB_REVERSEDUP)) {
|
||||
} else if (params.flags & (MDBX_REVERSEKEY | MDBX_REVERSEDUP)) {
|
||||
if (out.value.iov_len > 8) {
|
||||
memset(out.bytes, '\0', out.value.iov_len - 8);
|
||||
unaligned::store(out.bytes + out.value.iov_len - 8, htobe64(serial));
|
||||
|
@ -101,9 +101,9 @@ bool output(const logging::loglevel priority, const char *format, va_list ap) {
|
||||
#ifdef _MSC_VER
|
||||
int rc = _localtime32_s(&tm, (const __time32_t *)&now.utc);
|
||||
#else
|
||||
int rc = localtime_r(&time, &tm) ? MDB_SUCCESS : errno;
|
||||
int rc = localtime_r(&time, &tm) ? MDBX_SUCCESS : errno;
|
||||
#endif
|
||||
if (rc != MDB_SUCCESS)
|
||||
if (rc != MDBX_SUCCESS)
|
||||
failure_perror("localtime_r()", rc);
|
||||
|
||||
last = stdout;
|
||||
|
@ -37,9 +37,9 @@ void actor_params::set_defaults(void) {
|
||||
#else
|
||||
"test_tmpdb.mdbx";
|
||||
#endif
|
||||
mode_flags = MDB_NOSUBDIR | MDB_WRITEMAP | MDB_MAPASYNC | MDB_NORDAHEAD |
|
||||
MDB_NOMEMINIT | MDBX_COALESCE | MDBX_LIFORECLAIM;
|
||||
table_flags = MDB_DUPSORT;
|
||||
mode_flags = MDBX_NOSUBDIR | MDBX_WRITEMAP | MDBX_MAPASYNC | MDBX_NORDAHEAD |
|
||||
MDBX_NOMEMINIT | MDBX_COALESCE | MDBX_LIFORECLAIM;
|
||||
table_flags = MDBX_DUPSORT;
|
||||
size = 1024 * 1024;
|
||||
|
||||
keygen.seed = 1;
|
||||
|
@ -20,7 +20,7 @@ static HANDLE hBarrierSemaphore, hBarrierEvent;
|
||||
static int waitstatus2errcode(DWORD result) {
|
||||
switch (result) {
|
||||
case WAIT_OBJECT_0:
|
||||
return MDB_SUCCESS;
|
||||
return MDBX_SUCCESS;
|
||||
case WAIT_FAILED:
|
||||
return GetLastError();
|
||||
case WAIT_ABANDONED:
|
||||
|
46
test/test.cc
46
test/test.cc
@ -90,7 +90,7 @@ static void mdbx_debug_logger(int type, const char *function, int line,
|
||||
abort();
|
||||
}
|
||||
|
||||
int testcase::oom_callback(MDB_env *env, int pid, mdbx_tid_t tid, uint64_t txn,
|
||||
int testcase::oom_callback(MDBX_env *env, int pid, mdbx_tid_t tid, uint64_t txn,
|
||||
unsigned gap, int retry) {
|
||||
|
||||
testcase *self = (testcase *)mdbx_env_get_userctx(env);
|
||||
@ -121,32 +121,32 @@ void testcase::db_prepare() {
|
||||
int rc = mdbx_setup_debug(mdbx_dbg_opts, mdbx_debug_logger, MDBX_DBG_DNT);
|
||||
log_info("set mdbx debug-opts: 0x%02x", rc);
|
||||
|
||||
MDB_env *env = nullptr;
|
||||
MDBX_env *env = nullptr;
|
||||
rc = mdbx_env_create(&env);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_env_create()", rc);
|
||||
|
||||
assert(env != nullptr);
|
||||
db_guard.reset(env);
|
||||
|
||||
rc = mdbx_env_set_userctx(env, this);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_env_set_userctx()", rc);
|
||||
|
||||
rc = mdbx_env_set_maxreaders(env, config.params.max_readers);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_env_set_maxreaders()", rc);
|
||||
|
||||
rc = mdbx_env_set_maxdbs(env, config.params.max_tables);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_env_set_maxdbs()", rc);
|
||||
|
||||
rc = mdbx_env_set_oomfunc(env, testcase::oom_callback);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_env_set_oomfunc()", rc);
|
||||
|
||||
rc = mdbx_env_set_mapsize(env, (size_t)config.params.size);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_env_set_mapsize()", rc);
|
||||
|
||||
log_trace("<< db_prepare");
|
||||
@ -159,7 +159,7 @@ void testcase::db_open() {
|
||||
db_prepare();
|
||||
int rc = mdbx_env_open(db_guard.get(), config.params.pathname_db.c_str(),
|
||||
(unsigned)config.params.mode_flags, 0640);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_env_open()", rc);
|
||||
|
||||
log_trace("<< db_open");
|
||||
@ -179,8 +179,8 @@ void testcase::txn_begin(bool readonly) {
|
||||
|
||||
MDBX_txn *txn = nullptr;
|
||||
int rc =
|
||||
mdbx_txn_begin(db_guard.get(), nullptr, readonly ? MDB_RDONLY : 0, &txn);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
mdbx_txn_begin(db_guard.get(), nullptr, readonly ? MDBX_RDONLY : 0, &txn);
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_txn_begin()", rc);
|
||||
txn_guard.reset(txn);
|
||||
|
||||
@ -194,11 +194,11 @@ void testcase::txn_end(bool abort) {
|
||||
MDBX_txn *txn = txn_guard.release();
|
||||
if (abort) {
|
||||
int rc = mdbx_txn_abort(txn);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_txn_abort()", rc);
|
||||
} else {
|
||||
int rc = mdbx_txn_commit(txn);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_txn_commit()", rc);
|
||||
}
|
||||
|
||||
@ -303,7 +303,7 @@ void testcase::fetch_canary() {
|
||||
log_trace(">> fetch_canary");
|
||||
|
||||
int rc = mdbx_canary_get(txn_guard.get(), &canary_now);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_canary_get()", rc);
|
||||
|
||||
if (canary_now.v < last.canary.v)
|
||||
@ -329,13 +329,13 @@ void testcase::update_canary(uint64_t increment) {
|
||||
canary_now.y += increment;
|
||||
|
||||
int rc = mdbx_canary_put(txn_guard.get(), &canary_now);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_canary_put()", rc);
|
||||
|
||||
log_trace("<< update_canary: sequence = %" PRIu64, canary_now.y);
|
||||
}
|
||||
|
||||
MDB_dbi testcase::db_table_open(bool create) {
|
||||
MDBX_dbi testcase::db_table_open(bool create) {
|
||||
log_trace(">> testcase::db_table_create");
|
||||
|
||||
char tablename_buf[16];
|
||||
@ -349,23 +349,23 @@ MDB_dbi testcase::db_table_open(bool create) {
|
||||
}
|
||||
log_verbose("use %s table", tablename ? tablename : "MAINDB");
|
||||
|
||||
MDB_dbi handle = 0;
|
||||
MDBX_dbi handle = 0;
|
||||
int rc = mdbx_dbi_open(txn_guard.get(), tablename,
|
||||
(create ? MDB_CREATE : 0) | config.params.table_flags,
|
||||
(create ? MDBX_CREATE : 0) | config.params.table_flags,
|
||||
&handle);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_dbi_open()", rc);
|
||||
|
||||
log_trace("<< testcase::db_table_create, handle %u", handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
void testcase::db_table_drop(MDB_dbi handle) {
|
||||
void testcase::db_table_drop(MDBX_dbi handle) {
|
||||
log_trace(">> testcase::db_table_drop, handle %u", handle);
|
||||
|
||||
if (config.params.drop_table) {
|
||||
int rc = mdbx_drop(txn_guard.get(), handle, true);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_drop()", rc);
|
||||
log_trace("<< testcase::db_table_drop");
|
||||
} else {
|
||||
@ -373,11 +373,11 @@ void testcase::db_table_drop(MDB_dbi handle) {
|
||||
}
|
||||
}
|
||||
|
||||
void testcase::db_table_close(MDB_dbi handle) {
|
||||
void testcase::db_table_close(MDBX_dbi handle) {
|
||||
log_trace(">> testcase::db_table_close, handle %u", handle);
|
||||
assert(!txn_guard);
|
||||
int rc = mdbx_dbi_close(db_guard.get(), handle);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_dbi_close()", rc);
|
||||
log_trace("<< testcase::db_table_close");
|
||||
}
|
||||
|
22
test/test.h
22
test/test.h
@ -54,8 +54,8 @@ extern bool failfast;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct db_deleter : public std::unary_function<void, MDB_env *> {
|
||||
void operator()(MDB_env *env) const { mdbx_env_close(env); }
|
||||
struct db_deleter : public std::unary_function<void, MDBX_env *> {
|
||||
void operator()(MDBX_env *env) const { mdbx_env_close(env); }
|
||||
};
|
||||
|
||||
struct txn_deleter : public std::unary_function<void, MDBX_txn *> {
|
||||
@ -66,13 +66,13 @@ struct txn_deleter : public std::unary_function<void, MDBX_txn *> {
|
||||
}
|
||||
};
|
||||
|
||||
struct cursor_deleter : public std::unary_function<void, MDB_cursor *> {
|
||||
void operator()(MDB_cursor *cursor) const { mdbx_cursor_close(cursor); }
|
||||
struct cursor_deleter : public std::unary_function<void, MDBX_cursor *> {
|
||||
void operator()(MDBX_cursor *cursor) const { mdbx_cursor_close(cursor); }
|
||||
};
|
||||
|
||||
typedef std::unique_ptr<MDB_env, db_deleter> scoped_db_guard;
|
||||
typedef std::unique_ptr<MDBX_env, db_deleter> scoped_db_guard;
|
||||
typedef std::unique_ptr<MDBX_txn, txn_deleter> scoped_txn_guard;
|
||||
typedef std::unique_ptr<MDB_cursor, cursor_deleter> scoped_cursor_guard;
|
||||
typedef std::unique_ptr<MDBX_cursor, cursor_deleter> scoped_cursor_guard;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@ -96,7 +96,7 @@ protected:
|
||||
mdbx_canary canary;
|
||||
} last;
|
||||
|
||||
static int oom_callback(MDB_env *env, int pid, mdbx_tid_t tid, uint64_t txn,
|
||||
static int oom_callback(MDBX_env *env, int pid, mdbx_tid_t tid, uint64_t txn,
|
||||
unsigned gap, int retry);
|
||||
|
||||
void db_prepare();
|
||||
@ -108,9 +108,9 @@ protected:
|
||||
void fetch_canary();
|
||||
void update_canary(uint64_t increment);
|
||||
|
||||
MDB_dbi db_table_open(bool create);
|
||||
void db_table_drop(MDB_dbi handle);
|
||||
void db_table_close(MDB_dbi handle);
|
||||
MDBX_dbi db_table_open(bool create);
|
||||
void db_table_drop(MDBX_dbi handle);
|
||||
void db_table_close(MDBX_dbi handle);
|
||||
|
||||
bool wait4start();
|
||||
void report(size_t nops_done);
|
||||
@ -128,7 +128,7 @@ protected:
|
||||
}
|
||||
|
||||
bool mode_readonly() const {
|
||||
return (config.params.mode_flags & MDB_RDONLY) ? true : false;
|
||||
return (config.params.mode_flags & MDBX_RDONLY) ? true : false;
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -95,7 +95,7 @@
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;MDBX_DEBUG=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PrecompiledHeaderFile>test.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
@ -110,7 +110,7 @@
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;MDBX_DEBUG=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PrecompiledHeaderFile>test.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
|
@ -19,16 +19,16 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lmdb.h"
|
||||
#include "mdbx.h"
|
||||
|
||||
int main(int argc,char * argv[])
|
||||
{
|
||||
int rc;
|
||||
MDB_env *env;
|
||||
MDB_dbi dbi;
|
||||
MDBX_env *env;
|
||||
MDBX_dbi dbi;
|
||||
MDBX_val key, data;
|
||||
MDBX_txn *txn;
|
||||
MDB_cursor *cursor;
|
||||
MDBX_cursor *cursor;
|
||||
char sval[32];
|
||||
|
||||
/* Note: Most error checking omitted for simplicity */
|
||||
@ -50,9 +50,9 @@ int main(int argc,char * argv[])
|
||||
fprintf(stderr, "mdbx_txn_commit: (%d) %s\n", rc, mdbx_strerror(rc));
|
||||
goto leave;
|
||||
}
|
||||
rc = mdbx_txn_begin(env, NULL, MDB_RDONLY, &txn);
|
||||
rc = mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn);
|
||||
rc = mdbx_cursor_open(txn, dbi, &cursor);
|
||||
while ((rc = mdbx_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
|
||||
while ((rc = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) == 0) {
|
||||
printf("key: %p %.*s, data: %p %.*s\n",
|
||||
key.iov_base, (int) key.iov_len, (char *) key.iov_base,
|
||||
data.iov_base, (int) data.iov_len, (char *) data.iov_base);
|
||||
|
Loading…
Reference in New Issue
Block a user