mdbx: Merge branch 'devel'.

This commit is contained in:
Leo Yuriev 2017-07-26 15:12:51 +03:00
commit 8be2e1b514
7 changed files with 342 additions and 274 deletions

View File

@ -28,6 +28,7 @@ CFLAGS ?= -O2 -g3 -Wall -Wno-constant-logical-operand -Werror -Wextra -ffunction
CFLAGS += -D_GNU_SOURCE=1 -std=gnu11 -pthread $(XCFLAGS)
CXXFLAGS = -std=c++11 $(filter-out -std=gnu11,$(CFLAGS))
TESTDB ?= $(shell [ -d /dev/shm ] && echo /dev/shm || echo /tmp)/mdbx-check.db
TESTLOG ?= $(shell [ -d /dev/shm ] && echo /dev/shm || echo /tmp)/mdbx-check.log
# LY: '--no-as-needed,-lrt' for ability to built with modern glibc, but then run with the old
LDFLAGS ?= -Wl,--gc-sections,-z,relro,-O,--no-as-needed,-lrt
@ -72,7 +73,7 @@ clean:
rm -rf $(TOOLS) test/test @* *.[ao] *.[ls]o *~ tmp.db/* *.gcov *.log *.err src/*.o test/*.o
check: all
rm -f $(TESTDB) test.log && (set -o pipefail; test/test --pathname=$(TESTDB) --dont-cleanup-after basic | tee -a test.log | tail -n 42) && ./mdbx_chk -vn $(TESTDB)
rm -f $(TESTDB) $(TESTLOG) && (set -o pipefail; test/test --pathname=$(TESTDB) --dont-cleanup-after basic | tee -a $(TESTLOG) | tail -n 42) && ./mdbx_chk -vvn $(TESTDB)
define core-rule
$(patsubst %.c,%.o,$(1)): $(1) $(CORE_INC) mdbx.h Makefile

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright 2015-2017 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@ -503,7 +503,7 @@ struct MDBX_txn {
/* The list of reclaimed txns from freeDB */
MDBX_TXL mt_lifo_reclaimed;
/* The list of pages that became unused during this transaction. */
MDBX_IDL mt_free_pages;
MDBX_IDL mt_befree_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;
@ -970,7 +970,7 @@ static __inline unsigned mdbx_log2(size_t value) {
/* The percentage of space used in the page, in tenths of a percent. */
#define PAGEFILL(env, p) \
(1024L * ((env)->me_psize - PAGEHDRSZ - SIZELEFT(p)) / \
(1024UL * ((env)->me_psize - PAGEHDRSZ - SIZELEFT(p)) / \
((env)->me_psize - PAGEHDRSZ))
/* The minimum page fill factor, in tenths of a percent.
* Pages emptier than this are candidates for merging. */
@ -1195,3 +1195,16 @@ static __inline pgno_t bytes2pgno(const MDBX_env *env, size_t bytes) {
mdbx_assert(env, (env->me_psize >> env->me_psize2log) == 1);
return (pgno_t)(bytes >> env->me_psize2log);
}
static __inline pgno_t pgno_add(pgno_t base, pgno_t augend) {
assert(base <= MAX_PAGENO);
return (augend < MAX_PAGENO - base) ? base + augend : MAX_PAGENO;
}
static __inline size_t pgno_align2os_bytes(const MDBX_env *env, pgno_t pgno) {
return mdbx_roundup2(pgno2bytes(env, pgno), env->me_os_psize);
}
static __inline pgno_t pgno_align2os_pgno(const MDBX_env *env, pgno_t pgno) {
return bytes2pgno(env, pgno_align2os_bytes(env, pgno));
}

File diff suppressed because it is too large Load Diff

View File

@ -208,13 +208,13 @@ int mdbx_asprintf(char **strp, const char *fmt, ...) {
va_end(ap);
if (unlikely(needed < 0 || needed >= INT_MAX)) {
*strp = NULL;
*strp = nullptr;
va_end(ones);
return needed;
}
*strp = malloc(needed + 1);
if (unlikely(*strp == NULL)) {
if (unlikely(*strp == nullptr)) {
va_end(ones);
SetLastError(MDBX_ENOMEM);
return -1;
@ -231,7 +231,7 @@ int mdbx_asprintf(char **strp, const char *fmt, ...) {
assert(actual == needed);
if (unlikely(actual < 0)) {
free(*strp);
*strp = NULL;
*strp = nullptr;
}
return actual;
}
@ -246,7 +246,7 @@ int mdbx_memalign_alloc(size_t alignment, size_t bytes, void **result) {
*result = memalign(alignment, bytes);
return *result ? MDBX_SUCCESS : errno;
#elif _POSIX_VERSION >= 200112L
*result = NULL;
*result = nullptr;
return posix_memalign(result, alignment, bytes);
#else
#error FIXME
@ -621,9 +621,9 @@ int mdbx_write(mdbx_filehandle_t fd, const void *buf, size_t bytes) {
}
}
int mdbx_filesync(mdbx_filehandle_t fd, bool fullsync) {
int mdbx_filesync(mdbx_filehandle_t fd, bool filesize_changed) {
#if defined(_WIN32) || defined(_WIN64)
(void)fullsync;
(void)filesize_changed;
return FlushFileBuffers(fd) ? MDBX_SUCCESS : GetLastError();
#elif __GLIBC_PREREQ(2, 16) || _BSD_SOURCE || _XOPEN_SOURCE || \
(__GLIBC_PREREQ(2, 8) && _POSIX_C_SOURCE >= 200112L)
@ -640,10 +640,10 @@ int mdbx_filesync(mdbx_filehandle_t fd, bool fullsync) {
* see http://www.spinics.net/lists/linux-ext4/msg33714.html */
#if _POSIX_C_SOURCE >= 199309L || _XOPEN_SOURCE >= 500 || \
defined(_POSIX_SYNCHRONIZED_IO)
if (!fullsync && fdatasync(fd) == 0)
if (!filesize_changed && fdatasync(fd) == 0)
return MDBX_SUCCESS;
#else
(void)fullsync;
(void)filesize_changed;
#endif
if (fsync(fd) == 0)
return MDBX_SUCCESS;
@ -781,7 +781,7 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t must, size_t limit) {
map->length = 0;
map->current = 0;
map->section = NULL;
map->address = MAP_FAILED;
map->address = nullptr;
if (GetFileType(map->fd) != FILE_TYPE_DISK)
return ERROR_FILE_OFFLINE;
@ -874,7 +874,7 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t must, size_t limit) {
if (!NT_SUCCESS(rc))
return ntstatus2errcode(rc);
map->address = NULL;
map->address = nullptr;
SIZE_T ViewSize = (flags & MDBX_RDONLY) ? must : limit;
rc = NtMapViewOfSection(
map->section, GetCurrentProcess(), &map->address,
@ -889,7 +889,7 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t must, size_t limit) {
if (!NT_SUCCESS(rc)) {
NtClose(map->section);
map->section = 0;
map->address = MAP_FAILED;
map->address = nullptr;
return ntstatus2errcode(rc);
}
@ -907,6 +907,7 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t must, size_t limit) {
return MDBX_SUCCESS;
}
map->length = 0;
map->address = nullptr;
return errno;
#endif
}
@ -930,14 +931,6 @@ int mdbx_munmap(mdbx_mmap_t *map) {
return MDBX_SUCCESS;
}
int mdbx_mlock(mdbx_mmap_t *map, size_t length) {
#if defined(_WIN32) || defined(_WIN64)
return VirtualLock(map->address, length) ? MDBX_SUCCESS : GetLastError();
#else
return (mlock(map->address, length) == 0) ? MDBX_SUCCESS : errno;
#endif
}
int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t must, size_t limit) {
assert(must <= limit);
#if defined(_WIN32) || defined(_WIN64)

View File

@ -1,4 +1,4 @@
/* https://en.wikipedia.org/wiki/Operating_system_abstraction_layer */
/* https://en.wikipedia.org/wiki/Operating_system_abstraction_layer */
/*
* Copyright 2015-2017 Leonid Yuriev <leo@yuriev.ru>
@ -89,6 +89,7 @@ typedef CRITICAL_SECTION mdbx_fastmutex_t;
#include <sys/stat.h>
#include <sys/uio.h>
#include <unistd.h>
#include <signal.h>
typedef pthread_t mdbx_thread_t;
typedef pthread_key_t mdbx_thread_key_t;
#define INVALID_HANDLE_VALUE (-1)
@ -455,7 +456,6 @@ typedef struct mdbx_mmap_param {
int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t must, size_t limit);
int mdbx_munmap(mdbx_mmap_t *map);
int mdbx_mlock(mdbx_mmap_t *map, size_t length);
int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t current, size_t wanna);
int mdbx_msync(mdbx_mmap_t *map, size_t offset, size_t length, int async);

View File

@ -361,7 +361,7 @@ static int handle_freedb(const uint64_t record_number, const MDBX_val *key,
freedb_pages += number;
if (envinfo.mi_latter_reader_txnid > txnid)
reclaimable_pages += number;
for (i = number, prev = 1; --i >= 0;) {
for (i = number, prev = NUM_METAS - 1; --i >= 0;) {
pg = iptr[i];
if (pg < NUM_METAS || pg > envinfo.mi_last_pgno)
problem_add("entry", record_number, "wrong idl entry",

View File

@ -1,4 +1,4 @@
/* mdbx_stat.c - memory-mapped database status tool */
/* mdbx_stat.c - memory-mapped database status tool */
/*
* Copyright 2015-2017 Leonid Yuriev <leo@yuriev.ru>
@ -249,7 +249,7 @@ int main(int argc, char *argv[]) {
pgno_t pg, prev;
ssize_t i, j, span = 0;
j = *iptr++;
for (i = j, prev = 1; --i >= 0;) {
for (i = j, prev = NUM_METAS - 1; --i >= 0;) {
pg = iptr[i];
if (pg <= prev)
bad = " [bad sequence]";