Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
mdbx: Merge branch 'master' into stable/0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
erthink committed Jun 14, 2018
2 parents 17d3e71 + b6e605b commit e1e17fd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 0.1.4.{build}
version: 0.1.5.{build}

environment:
matrix:
Expand Down
13 changes: 3 additions & 10 deletions src/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
# undef NDEBUG
#endif

/* Features under development */
#ifndef MDBX_DEVEL
# define MDBX_DEVEL 0
#endif

/*----------------------------------------------------------------------------*/

/* Should be defined before any includes */
Expand Down Expand Up @@ -144,9 +139,9 @@
#define MDBX_MAGIC UINT64_C(/* 56-bit prime */ 0x59659DBDEF4C11)

/* The version number for a database's datafile format. */
#define MDBX_DATA_VERSION ((MDBX_DEVEL) ? 255 : 2)
#define MDBX_DATA_VERSION 2
/* The version number for a database's lockfile format. */
#define MDBX_LOCK_VERSION ((MDBX_DEVEL) ? 255 : 2)
#define MDBX_LOCK_VERSION 2

/* handle for the DB used to track free pages. */
#define FREE_DBI 0
Expand All @@ -171,9 +166,7 @@ typedef uint32_t pgno_t;
/* A transaction ID. */
typedef uint64_t txnid_t;
#define PRIaTXN PRIi64
#if MDBX_DEVEL
#define MIN_TXNID (UINT64_MAX - UINT32_MAX)
#elif MDBX_DEBUG
#if MDBX_DEBUG
#define MIN_TXNID UINT64_C(0x100000000)
#else
#define MIN_TXNID UINT64_C(1)
Expand Down
35 changes: 26 additions & 9 deletions src/mdbx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2711,7 +2711,7 @@ static int mdbx_page_touch(MDBX_cursor *mc) {
return rc;
}

int mdbx_env_sync(MDBX_env *env, int force) {
static int mdbx_env_sync_ex(MDBX_env *env, int force, int nonblock) {
if (unlikely(!env))
return MDBX_EINVAL;

Expand All @@ -2729,7 +2729,7 @@ int mdbx_env_sync(MDBX_env *env, int force) {
(!env->me_txn0 || env->me_txn0->mt_owner != mdbx_thread_self());

if (outside_txn) {
int rc = mdbx_txn_lock(env, false);
int rc = mdbx_txn_lock(env, nonblock);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
}
Expand Down Expand Up @@ -2758,7 +2758,7 @@ int mdbx_env_sync(MDBX_env *env, int force) {
if (unlikely(rc != MDBX_SUCCESS))
return rc;

rc = mdbx_txn_lock(env, false);
rc = mdbx_txn_lock(env, nonblock);
if (unlikely(rc != MDBX_SUCCESS))
return rc;

Expand All @@ -2785,6 +2785,10 @@ int mdbx_env_sync(MDBX_env *env, int force) {
return MDBX_SUCCESS;
}

int mdbx_env_sync(MDBX_env *env, int force) {
return mdbx_env_sync_ex(env, force, false);
}

/* Back up parent txn's cursors, then grab the originals for tracking */
static int mdbx_cursor_shadow(MDBX_txn *src, MDBX_txn *dst) {
MDBX_cursor *mc, *bk;
Expand Down Expand Up @@ -4338,8 +4342,8 @@ static int __cold mdbx_read_header(MDBX_env *env, MDBX_meta *meta,
}

if (page.mp_meta.mm_magic_and_version != MDBX_DATA_MAGIC) {
mdbx_error("meta[%u] has invalid magic/version MDBX_DEVEL=%d",
meta_number, MDBX_DEVEL);
mdbx_error("meta[%u] has invalid magic/version %" PRIx64, meta_number,
page.mp_meta.mm_magic_and_version);
return ((page.mp_meta.mm_magic_and_version >> 8) != MDBX_MAGIC)
? MDBX_INVALID
: MDBX_VERSION_MISMATCH;
Expand Down Expand Up @@ -5940,8 +5944,21 @@ int __cold mdbx_env_close_ex(MDBX_env *env, int dont_sync) {
if (env->me_txn0 && env->me_txn0->mt_owner &&
env->me_txn0->mt_owner != mdbx_thread_self())
return MDBX_BUSY;
if (!dont_sync)
rc = mdbx_env_sync(env, true);
if (!dont_sync) {
#if defined(_WIN32) || defined(_WIN64)
/* On windows, without blocking is impossible to determine whether another
* process is running a writing transaction or not.
* Because in the "owner died" condition kernel don't release
* file lock immediately. */
rc = mdbx_env_sync_ex(env, true, false);
#else
rc = mdbx_env_sync_ex(env, true, true);
rc = (rc == MDBX_BUSY || rc == EAGAIN || rc == EACCES || rc == EBUSY ||
rc == EWOULDBLOCK)
? MDBX_SUCCESS
: rc;
#endif
}
}

VALGRIND_DESTROY_MEMPOOL(env);
Expand All @@ -5968,7 +5985,7 @@ int __cold mdbx_env_close_ex(MDBX_env *env, int dont_sync) {
return rc;
}

int mdbx_env_close(MDBX_env *env) { return mdbx_env_close_ex(env, 0); }
int mdbx_env_close(MDBX_env *env) { return mdbx_env_close_ex(env, false); }

/* Compare two items pointing at aligned unsigned int's. */
static int __hot mdbx_cmp_int_ai(const MDBX_val *a, const MDBX_val *b) {
Expand Down Expand Up @@ -11473,7 +11490,7 @@ int __cold mdbx_env_set_syncbytes(MDBX_env *env, size_t bytes) {
return MDBX_EBADSIGN;

env->me_sync_threshold = bytes;
return env->me_map ? mdbx_env_sync(env, 0) : MDBX_SUCCESS;
return env->me_map ? mdbx_env_sync(env, false) : MDBX_SUCCESS;
}

int __cold mdbx_env_set_oomfunc(MDBX_env *env, MDBX_oom_func *oomfunc) {
Expand Down
2 changes: 1 addition & 1 deletion src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#error "API version mismatch!"
#endif

#define MDBX_VERSION_RELEASE 4
#define MDBX_VERSION_RELEASE 5
#define MDBX_VERSION_REVISION 1

/*LIBMDBX_EXPORTS*/ const mdbx_version_info mdbx_version = {
Expand Down

0 comments on commit e1e17fd

Please sign in to comment.