mdbx-build: minor cleanup after pul-request/merge.

Change-Id: Ia612dbd939be7acd938fca8eb3f93f650560417a
This commit is contained in:
Leo Yuriev 2018-01-14 22:01:38 +03:00
parent 506caee9e5
commit ab7cb2c39e
9 changed files with 437 additions and 425 deletions

40
.gitignore vendored
View File

@ -1,39 +1,37 @@
*[~#]
*.[ao] *.[ao]
*.bak *.bak
.le.ini
core
core.*
*.exe *.exe
*.gcda *.gcda
*.gcno *.gcno
*.gcov *.gcov
libmdbx.creator.user
*.lo *.lo
mdbx_chk
mdbx_copy
mdbx-dll.VC.db
mdbx-dll.VC.VC.opendb
mdbx-dll.vcxproj.filters
mdbx_dump
mdbx_load
mdbx_stat
*.orig *.orig
*.rej *.rej
*.so *.so
/test/test *[~#]
.idea
.le.ini
.vs/
Win32/
build-*
cmake-build-*
core
libmdbx.creator.user
mdbx-dll.VC.VC.opendb
mdbx-dll.VC.db
mdbx-dll.vcxproj.filters
mdbx_chk
mdbx_copy
mdbx_dump
mdbx_load
mdbx_stat
ootest/test
test.log
test/test.vcxproj.user test/test.vcxproj.user
test/tmp.db test/tmp.db
test/tmp.db-lck test/tmp.db-lck
tmp.db tmp.db
tmp.db-lck tmp.db-lck
valgrind.* valgrind.*
.vs/
Win32/
x64/ x64/
x86/ x86/
test.log
cmake-build-*
build-*
.idea

View File

@ -1,4 +1,4 @@
Contributors Contributors
============ ============
Alexey Naumov <alexey.naumov@gmail.com> Alexey Naumov <alexey.naumov@gmail.com>
@ -28,3 +28,4 @@ Philipp Storz <philipp.storz@bareos.com>
Quanah Gibson-Mount <quanah@openldap.org> Quanah Gibson-Mount <quanah@openldap.org>
Salvador Ortiz <sog@msg.com.mx> Salvador Ortiz <sog@msg.com.mx>
Sebastien Launay <sebastien@slaunay.fr> Sebastien Launay <sebastien@slaunay.fr>
Vladimir Romanov <vromanov@gmail.com>

View File

@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8.7)
set(TARGET mdbx) set(TARGET mdbx)
project(${TARGET}) project(${TARGET})
# FIXME/TODO: Same as https://github.com/leo-yuriev/libfpta
set(MDBX_VERSION_MAJOR 0) set(MDBX_VERSION_MAJOR 0)
set(MDBX_VERSION_MINOR 0) set(MDBX_VERSION_MINOR 0)
set(MDBX_VERSION_PATCH 0) set(MDBX_VERSION_PATCH 0)
@ -21,112 +22,108 @@ set(CMAKE_CXX_STANDARD_REQUIRED on)
add_definitions(-DNDEBUG=1 -DMDBX_DEBUG=0 -DLIBMDBX_EXPORTS=1 -D_GNU_SOURCE=1) add_definitions(-DNDEBUG=1 -DMDBX_DEBUG=0 -DLIBMDBX_EXPORTS=1 -D_GNU_SOURCE=1)
get_directory_property(hasParent PARENT_DIRECTORY) get_directory_property(hasParent PARENT_DIRECTORY)
if (hasParent) if(hasParent)
set(STANDALONE_BUILD 0) set(STANDALONE_BUILD 0)
else () else()
set(STANDALONE_BUILD 1) set(STANDALONE_BUILD 1)
enable_testing() enable_testing()
if (CMAKE_C_COMPILER_ID MATCHES GNU) if (CMAKE_C_COMPILER_ID MATCHES GNU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-constant-logical-operand") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-constant-logical-operand")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
endif () endif()
if (CMAKE_CXX_COMPILER_ID MATCHES GNU) if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpointer-arith") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpointer-arith")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat-security") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat-security")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wwrite-strings") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wwrite-strings")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmax-errors=20") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmax-errors=20")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Wmissing-declarations") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Wmissing-declarations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finline-functions-called-once") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finline-functions-called-once")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-packed-bitfield-compat") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-packed-bitfield-compat")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g3") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g3")
endif () endif()
if (COVERAGE) if (COVERAGE)
if (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") if (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(FATAL_ERROR "Coverage requires -DCMAKE_BUILD_TYPE=Debug Current value=${CMAKE_BUILD_TYPE}") message(FATAL_ERROR "Coverage requires -DCMAKE_BUILD_TYPE=Debug Current value=${CMAKE_BUILD_TYPE}")
endif () endif()
message(STATUS "Setting coverage compiler flags") message(STATUS "Setting coverage compiler flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage")
add_definitions(-DCOVERAGE_TEST)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage") if (NOT TRAVIS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fsanitize=leak -fstack-protector-strong -static-libasan")
endif()
add_definitions(-DCOVERAGE_TEST) endif()
endif ()
if (TRAVIS)
add_definitions(-DNO_MLOCK)
else ()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fsanitize=leak -fstack-protector-strong -static-libasan")
endif ()
endif ()
set(${TARGET}_SRC set(${TARGET}_SRC
mdbx.h mdbx.h
src/bits.h src/bits.h
src/defs.h src/defs.h
src/lck-posix.c src/lck-posix.c
src/mdbx.c src/mdbx.c
src/osal.c src/osal.c
src/osal.h src/osal.h
src/version.c src/version.c
) )
add_library(${TARGET}_STATIC STATIC add_library(${TARGET}_STATIC STATIC
${${TARGET}_SRC} ${${TARGET}_SRC}
) )
add_library(${TARGET} ALIAS ${TARGET}_STATIC) add_library(${TARGET} ALIAS ${TARGET}_STATIC)
add_library(${TARGET}_SHARED SHARED add_library(${TARGET}_SHARED SHARED
${${TARGET}_SRC} ${${TARGET}_SRC}
) )
set_target_properties(${TARGET}_SHARED PROPERTIES set_target_properties(${TARGET}_SHARED PROPERTIES
VERSION ${MDBX_VERSION_STRING} VERSION ${MDBX_VERSION_STRING}
SOVERSION ${MDBX_VERSION_MAJOR} SOVERSION ${MDBX_VERSION_MAJOR}
OUTPUT_NAME ${TARGET} OUTPUT_NAME ${TARGET}
CLEAN_DIRECT_OUTPUT 1 CLEAN_DIRECT_OUTPUT 1
) )
set_target_properties(${TARGET}_STATIC PROPERTIES set_target_properties(${TARGET}_STATIC PROPERTIES
VERSION ${MDBX_VERSION_STRING} VERSION ${MDBX_VERSION_STRING}
SOVERSION ${MDBX_VERSION_MAJOR} SOVERSION ${MDBX_VERSION_MAJOR}
OUTPUT_NAME ${TARGET} OUTPUT_NAME ${TARGET}
CLEAN_DIRECT_OUTPUT 1 CLEAN_DIRECT_OUTPUT 1
) )
target_include_directories(${TARGET}_STATIC PUBLIC target_include_directories(${TARGET}_STATIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
) )
target_include_directories(${TARGET}_SHARED PUBLIC target_include_directories(${TARGET}_SHARED PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
) )
install(TARGETS ${TARGET}_STATIC DESTINATION ${CMAKE_INSTALL_PREFIX}/lib64 COMPONENT mdbx) install(TARGETS ${TARGET}_STATIC DESTINATION ${CMAKE_INSTALL_PREFIX}/lib64 COMPONENT mdbx)
install(TARGETS ${TARGET}_SHARED DESTINATION ${CMAKE_INSTALL_PREFIX}/lib64 COMPONENT mdbx) install(TARGETS ${TARGET}_SHARED DESTINATION ${CMAKE_INSTALL_PREFIX}/lib64 COMPONENT mdbx)
@ -137,20 +134,21 @@ add_subdirectory(test)
add_subdirectory(src/tools) add_subdirectory(src/tools)
add_subdirectory(pcrf_test) add_subdirectory(pcrf_test)
##############################################################################
set(CPACK_GENERATOR "RPM") set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_COMPONENT_INSTALL ON) set(CPACK_RPM_COMPONENT_INSTALL ON)
#Version # Version
if (NOT "$ENV{BUILD_NUMBER}" STREQUAL "") if (NOT "$ENV{BUILD_NUMBER}" STREQUAL "")
set(CPACK_PACKAGE_RELEASE $ENV{BUILD_NUMBER}) set(CPACK_PACKAGE_RELEASE $ENV{BUILD_NUMBER})
else () else()
if (NOT "$ENV{CI_PIPELINE_ID}" STREQUAL "") if (NOT "$ENV{CI_PIPELINE_ID}" STREQUAL "")
set(CPACK_PACKAGE_RELEASE $ENV{CI_PIPELINE_ID}) set(CPACK_PACKAGE_RELEASE $ENV{CI_PIPELINE_ID})
else () else()
set(CPACK_PACKAGE_RELEASE 1) set(CPACK_PACKAGE_RELEASE 1)
endif () endif()
endif () endif()
set(CPACK_RPM_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE}) set(CPACK_RPM_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE})
set(CPACK_PACKAGE_VERSION ${MDBX_VERSION_STRING}) set(CPACK_PACKAGE_VERSION ${MDBX_VERSION_STRING})
@ -174,12 +172,12 @@ set(CPACK_RPM_mdbx_FILE_NAME "${CPACK_RPM_mdbx_PACKAGE_NAME}-${CPACK_PACKAGE_VER
set(CPACK_RPM_mdbx-devel_FILE_NAME "${CPACK_RPM_mdbx-devel_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_FULL}.${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm") set(CPACK_RPM_mdbx-devel_FILE_NAME "${CPACK_RPM_mdbx-devel_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_FULL}.${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
/usr/local /usr/local
/usr/local/bin /usr/local/bin
/usr/local/lib64 /usr/local/lib64
/usr/local/include /usr/local/include
/usr/local/man /usr/local/man
/usr/local/man/man1 /usr/local/man/man1
) )
include(CPack) include(CPack)

View File

@ -1,3 +1,8 @@
CMakeLists.txt
pcrf_test/CMakeLists.txt
src/tools/CMakeLists.txt
test/CMakeLists.txt
tutorial/CMakeLists.txt
tutorial/sample-mdbx.c tutorial/sample-mdbx.c
AUTHORS AUTHORS
LICENSE LICENSE

View File

@ -2,3 +2,5 @@
src src
src/tools src/tools
test test
pcrf_test
tutorial

View File

@ -1,11 +1,7 @@
set(TARGET pcrf_test) set(TARGET pcrf_test)
project(${TARGET}) project(${TARGET})
add_executable(${TARGET} add_executable(${TARGET} pcrf_test.c)
pcrf_test.c
)
target_link_libraries(${TARGET} target_link_libraries(${TARGET} mdbx)
mdbx
)

View File

@ -1,6 +1,7 @@
/* /*
* Copyright 2016-2017 Leonid Yuriev <leo@yuriev.ru>. * Copyright 2016-2017 Leonid Yuriev <leo@yuriev.ru>.
* Copyright 2015 Vladimir Romanov <https://www.linkedin.com/in/vladimirromanov>, Yota Lab. * Copyright 2015 Vladimir Romanov
* <https://www.linkedin.com/in/vladimirromanov>, Yota Lab.
* *
* This file is part of libmdbx. * This file is part of libmdbx.
* *
@ -18,20 +19,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <sys/time.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h>
#include "mdbx.h"
#include <assert.h>
#include <inttypes.h>
#include <limits.h> #include <limits.h>
#include <stddef.h> #include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <string.h>
#include "mdbx.h"
#include <inttypes.h>
#define IP_PRINTF_ARG_HOST(addr) (int)((addr) >> 24), (int)((addr) >> 16 & 0xff), (int)((addr) >> 8 & 0xff), (int)((addr) & 0xff) #define IP_PRINTF_ARG_HOST(addr) \
(int)((addr) >> 24), (int)((addr) >> 16 & 0xff), (int)((addr) >> 8 & 0xff), \
(int)((addr)&0xff)
char opt_db_path[PATH_MAX] = "/root/lmdbx_bench2"; char opt_db_path[PATH_MAX] = "/root/lmdbx_bench2";
static MDBX_env *env; static MDBX_env *env;
@ -48,266 +51,283 @@ int64_t mdbx_data_size = 0;
int64_t mdbx_key_size = 0; int64_t mdbx_key_size = 0;
typedef struct { typedef struct {
char session_id1[100]; char session_id1[100];
char session_id2[100]; char session_id2[100];
char ip[20]; char ip[20];
uint8_t fill[100]; uint8_t fill[100];
} session_data_t; } session_data_t;
typedef struct { typedef struct {
int64_t obj_id; int64_t obj_id;
int8_t event_type; int8_t event_type;
} __attribute__((__packed__)) event_data_t; } __attribute__((__packed__)) event_data_t;
static void add_id_to_pool(int64_t id) { static void add_id_to_pool(int64_t id) {
ids[ids_count] = id; ids[ids_count] = id;
ids_count++; ids_count++;
} }
static inline int64_t getClockUs(void) { static inline int64_t getClockUs(void) {
struct timespec val; struct timespec val;
#ifdef CYGWIN #ifdef CYGWIN
clock_gettime(CLOCK_REALTIME, &val); clock_gettime(CLOCK_REALTIME, &val);
#else #else
clock_gettime(CLOCK_MONOTONIC, &val); clock_gettime(CLOCK_MONOTONIC, &val);
#endif #endif
return val.tv_sec * ((int64_t) 1000000) + val.tv_nsec / 1000; return val.tv_sec * ((int64_t)1000000) + val.tv_nsec / 1000;
} }
static int64_t get_id_from_pool() { static int64_t get_id_from_pool() {
if (ids_count == 0) { if (ids_count == 0) {
return -1; return -1;
} }
int32_t index = rand() % ids_count; int32_t index = rand() % ids_count;
int64_t id = ids[index]; int64_t id = ids[index];
ids[index] = ids[ids_count - 1]; ids[index] = ids[ids_count - 1];
ids_count--; ids_count--;
return id; return id;
} }
#define MDBX_CHECK(x) \ #define MDBX_CHECK(x) \
do {\ do { \
const int rc = (x);\ const int rc = (x); \
if ( rc != MDBX_SUCCESS ) {\ if (rc != MDBX_SUCCESS) { \
printf("Error [%d] %s in %s at %s:%d\n", rc, mdbx_strerror(rc), #x, __FILE__, __LINE__); \ printf("Error [%d] %s in %s at %s:%d\n", rc, mdbx_strerror(rc), #x, \
exit(EXIT_FAILURE); \ __FILE__, __LINE__); \
}\ exit(EXIT_FAILURE); \
} while(0) } \
} while (0)
static void db_connect() { static void db_connect() {
MDBX_dbi dbi_session; MDBX_dbi dbi_session;
MDBX_dbi dbi_session_id; MDBX_dbi dbi_session_id;
MDBX_dbi dbi_event; MDBX_dbi dbi_event;
MDBX_dbi dbi_ip; MDBX_dbi dbi_ip;
MDBX_CHECK(mdbx_env_create(&env)); MDBX_CHECK(mdbx_env_create(&env));
MDBX_CHECK(mdbx_env_set_mapsize(env, REC_COUNT * sizeof(session_data_t) * 10)); MDBX_CHECK(
MDBX_CHECK(mdbx_env_set_maxdbs(env, 30)); mdbx_env_set_mapsize(env, REC_COUNT * sizeof(session_data_t) * 10));
MDBX_CHECK(mdbx_env_open(env, opt_db_path, MDBX_CREATE | MDBX_WRITEMAP | MDBX_MAPASYNC| MDBX_NOSYNC | MDBX_LIFORECLAIM, 0664)); MDBX_CHECK(mdbx_env_set_maxdbs(env, 30));
MDBX_txn *txn; MDBX_CHECK(mdbx_env_open(env, opt_db_path,
MDBX_CREATE | MDBX_WRITEMAP | MDBX_MAPASYNC |
MDBX_NOSYNC | MDBX_LIFORECLAIM,
0664));
MDBX_txn *txn;
// transaction init // transaction init
MDBX_CHECK(mdbx_txn_begin(env, NULL, 0, &txn)); MDBX_CHECK(mdbx_txn_begin(env, NULL, 0, &txn));
// open database in read-write mode // open database in read-write mode
MDBX_CHECK(mdbx_dbi_open(txn, "session", MDBX_CREATE, &dbi_session)); MDBX_CHECK(mdbx_dbi_open(txn, "session", MDBX_CREATE, &dbi_session));
MDBX_CHECK(mdbx_dbi_open(txn, "session_id", MDBX_CREATE, &dbi_session_id)); MDBX_CHECK(mdbx_dbi_open(txn, "session_id", MDBX_CREATE, &dbi_session_id));
MDBX_CHECK(mdbx_dbi_open(txn, "event", MDBX_CREATE, &dbi_event)); MDBX_CHECK(mdbx_dbi_open(txn, "event", MDBX_CREATE, &dbi_event));
MDBX_CHECK(mdbx_dbi_open(txn, "ip", MDBX_CREATE, &dbi_ip)); MDBX_CHECK(mdbx_dbi_open(txn, "ip", MDBX_CREATE, &dbi_ip));
// transaction commit // transaction commit
MDBX_CHECK(mdbx_txn_commit(txn)); MDBX_CHECK(mdbx_txn_commit(txn));
printf("Connection open\n"); printf("Connection open\n");
} }
static void create_record(int64_t record_id) { static void create_record(int64_t record_id) {
MDBX_dbi dbi_session; MDBX_dbi dbi_session;
MDBX_dbi dbi_session_id; MDBX_dbi dbi_session_id;
MDBX_dbi dbi_event; MDBX_dbi dbi_event;
MDBX_dbi dbi_ip; MDBX_dbi dbi_ip;
event_data_t event; event_data_t event;
MDBX_txn *txn; MDBX_txn *txn;
session_data_t data; session_data_t data;
// transaction init // transaction init
snprintf(data.session_id1, sizeof(data.session_id1), "prefix%02ld_%02ld.fill.fill.fill.fill.fill.fill;%ld", snprintf(data.session_id1, sizeof(data.session_id1),
record_id % 3 + 1, record_id % 9 + 1, record_id); "prefix%02ld_%02ld.fill.fill.fill.fill.fill.fill;%ld",
snprintf(data.session_id2, sizeof(data.session_id2), "dprefix%ld;%ld.fill.fill.;suffix", record_id, record_id % 3 + 1, record_id % 9 + 1, record_id);
record_id % 1000000000 + 99999); snprintf(data.session_id2, sizeof(data.session_id2),
snprintf(data.ip, sizeof(data.ip), "%d.%d.%d.%d", IP_PRINTF_ARG_HOST(record_id & 0xFFFFFFFF)); "dprefix%ld;%ld.fill.fill.;suffix", record_id,
event.obj_id = record_id; record_id % 1000000000 + 99999);
event.event_type = 1; snprintf(data.ip, sizeof(data.ip), "%d.%d.%d.%d",
IP_PRINTF_ARG_HOST(record_id & 0xFFFFFFFF));
event.obj_id = record_id;
event.event_type = 1;
MDBX_val _session_id1_rec = {data.session_id1, strlen(data.session_id1)}; MDBX_val _session_id1_rec = {data.session_id1, strlen(data.session_id1)};
MDBX_val _session_id2_rec = {data.session_id2, strlen(data.session_id2)}; MDBX_val _session_id2_rec = {data.session_id2, strlen(data.session_id2)};
MDBX_val _ip_rec = {data.ip, strlen(data.ip)}; MDBX_val _ip_rec = {data.ip, strlen(data.ip)};
MDBX_val _obj_id_rec = {&record_id, sizeof(record_id)}; MDBX_val _obj_id_rec = {&record_id, sizeof(record_id)};
MDBX_val _data_rec = {&data, offsetof(session_data_t, fill) + (rand() % sizeof(data.fill))}; MDBX_val _data_rec = {&data, offsetof(session_data_t, fill) +
MDBX_val _event_rec = {&event, sizeof(event)}; (rand() % sizeof(data.fill))};
MDBX_val _event_rec = {&event, sizeof(event)};
uint64_t start = getClockUs(); uint64_t start = getClockUs();
MDBX_CHECK(mdbx_txn_begin(env, NULL, 0, &txn)); MDBX_CHECK(mdbx_txn_begin(env, NULL, 0, &txn));
MDBX_CHECK(mdbx_dbi_open(txn, "session", MDBX_CREATE, &dbi_session)); MDBX_CHECK(mdbx_dbi_open(txn, "session", MDBX_CREATE, &dbi_session));
MDBX_CHECK(mdbx_dbi_open(txn, "session_id", MDBX_CREATE, &dbi_session_id)); MDBX_CHECK(mdbx_dbi_open(txn, "session_id", MDBX_CREATE, &dbi_session_id));
MDBX_CHECK(mdbx_dbi_open(txn, "event", MDBX_CREATE, &dbi_event)); MDBX_CHECK(mdbx_dbi_open(txn, "event", MDBX_CREATE, &dbi_event));
MDBX_CHECK(mdbx_dbi_open(txn, "ip", MDBX_CREATE, &dbi_ip)); MDBX_CHECK(mdbx_dbi_open(txn, "ip", MDBX_CREATE, &dbi_ip));
MDBX_CHECK(mdbx_put(txn, dbi_session, &_obj_id_rec, &_data_rec, MDBX_NOOVERWRITE | MDBX_NODUPDATA)); MDBX_CHECK(mdbx_put(txn, dbi_session, &_obj_id_rec, &_data_rec,
MDBX_CHECK(mdbx_put(txn, dbi_session_id, &_session_id1_rec, &_obj_id_rec, MDBX_NOOVERWRITE | MDBX_NODUPDATA)); MDBX_NOOVERWRITE | MDBX_NODUPDATA));
MDBX_CHECK(mdbx_put(txn, dbi_session_id, &_session_id2_rec, &_obj_id_rec, MDBX_NOOVERWRITE | MDBX_NODUPDATA)); MDBX_CHECK(mdbx_put(txn, dbi_session_id, &_session_id1_rec, &_obj_id_rec,
MDBX_CHECK(mdbx_put(txn, dbi_ip, &_ip_rec, &_obj_id_rec, 0)); MDBX_NOOVERWRITE | MDBX_NODUPDATA));
MDBX_CHECK(mdbx_put(txn, dbi_event, &_event_rec, &_obj_id_rec, 0)); MDBX_CHECK(mdbx_put(txn, dbi_session_id, &_session_id2_rec, &_obj_id_rec,
MDBX_CHECK(mdbx_txn_commit(txn)); MDBX_NOOVERWRITE | MDBX_NODUPDATA));
MDBX_CHECK(mdbx_put(txn, dbi_ip, &_ip_rec, &_obj_id_rec, 0));
MDBX_CHECK(mdbx_put(txn, dbi_event, &_event_rec, &_obj_id_rec, 0));
MDBX_CHECK(mdbx_txn_commit(txn));
mdbx_data_size += (_data_rec.iov_len + _obj_id_rec.iov_len * 4); mdbx_data_size += (_data_rec.iov_len + _obj_id_rec.iov_len * 4);
mdbx_key_size += (_obj_id_rec.iov_len + _session_id1_rec.iov_len + _session_id2_rec.iov_len + _ip_rec.iov_len + mdbx_key_size +=
_event_rec.iov_len); (_obj_id_rec.iov_len + _session_id1_rec.iov_len +
_session_id2_rec.iov_len + _ip_rec.iov_len + _event_rec.iov_len);
// transaction commit // transaction commit
mdbx_add_count++; mdbx_add_count++;
mdbx_add_time += (getClockUs() - start); mdbx_add_time += (getClockUs() - start);
} }
static void delete_record(int64_t record_id) { static void delete_record(int64_t record_id) {
MDBX_dbi dbi_session; MDBX_dbi dbi_session;
MDBX_dbi dbi_session_id; MDBX_dbi dbi_session_id;
MDBX_dbi dbi_event; MDBX_dbi dbi_event;
MDBX_dbi dbi_ip; MDBX_dbi dbi_ip;
event_data_t event; event_data_t event;
MDBX_txn *txn; MDBX_txn *txn;
// transaction init // transaction init
uint64_t start = getClockUs(); uint64_t start = getClockUs();
MDBX_CHECK(mdbx_txn_begin(env, NULL, 0, &txn)); MDBX_CHECK(mdbx_txn_begin(env, NULL, 0, &txn));
// open database in read-write mode // open database in read-write mode
MDBX_CHECK(mdbx_dbi_open(txn, "session", MDBX_CREATE, &dbi_session)); MDBX_CHECK(mdbx_dbi_open(txn, "session", MDBX_CREATE, &dbi_session));
MDBX_CHECK(mdbx_dbi_open(txn, "session_id", MDBX_CREATE, &dbi_session_id)); MDBX_CHECK(mdbx_dbi_open(txn, "session_id", MDBX_CREATE, &dbi_session_id));
MDBX_CHECK(mdbx_dbi_open(txn, "event", MDBX_CREATE, &dbi_event)); MDBX_CHECK(mdbx_dbi_open(txn, "event", MDBX_CREATE, &dbi_event));
MDBX_CHECK(mdbx_dbi_open(txn, "ip", MDBX_CREATE, &dbi_ip)); MDBX_CHECK(mdbx_dbi_open(txn, "ip", MDBX_CREATE, &dbi_ip));
// put data // put data
MDBX_val _obj_id_rec = {&record_id, sizeof(record_id)}; MDBX_val _obj_id_rec = {&record_id, sizeof(record_id)};
MDBX_val _data_rec; MDBX_val _data_rec;
// get data // get data
MDBX_CHECK(mdbx_get(txn, dbi_session, &_obj_id_rec, &_data_rec)); MDBX_CHECK(mdbx_get(txn, dbi_session, &_obj_id_rec, &_data_rec));
session_data_t *data = (session_data_t *) _data_rec.iov_base; session_data_t *data = (session_data_t *)_data_rec.iov_base;
MDBX_val _session_id1_rec = {data->session_id1, strlen(data->session_id1)}; MDBX_val _session_id1_rec = {data->session_id1, strlen(data->session_id1)};
MDBX_val _session_id2_rec = {data->session_id2, strlen(data->session_id2)}; MDBX_val _session_id2_rec = {data->session_id2, strlen(data->session_id2)};
MDBX_val _ip_rec = {data->ip, strlen(data->ip)}; MDBX_val _ip_rec = {data->ip, strlen(data->ip)};
MDBX_CHECK(mdbx_del(txn, dbi_session_id, &_session_id1_rec, NULL)); MDBX_CHECK(mdbx_del(txn, dbi_session_id, &_session_id1_rec, NULL));
MDBX_CHECK(mdbx_del(txn, dbi_session_id, &_session_id2_rec, NULL)); MDBX_CHECK(mdbx_del(txn, dbi_session_id, &_session_id2_rec, NULL));
MDBX_CHECK(mdbx_del(txn, dbi_ip, &_ip_rec, NULL)); MDBX_CHECK(mdbx_del(txn, dbi_ip, &_ip_rec, NULL));
event.obj_id = record_id; event.obj_id = record_id;
event.event_type = 1; event.event_type = 1;
MDBX_val _event_rec = {&event, sizeof(event)}; MDBX_val _event_rec = {&event, sizeof(event)};
MDBX_CHECK(mdbx_del(txn, dbi_event, &_event_rec, NULL)); MDBX_CHECK(mdbx_del(txn, dbi_event, &_event_rec, NULL));
MDBX_CHECK(mdbx_del(txn, dbi_session, &_obj_id_rec, NULL)); MDBX_CHECK(mdbx_del(txn, dbi_session, &_obj_id_rec, NULL));
mdbx_data_size -= (_data_rec.iov_len + _obj_id_rec.iov_len * 4); mdbx_data_size -= (_data_rec.iov_len + _obj_id_rec.iov_len * 4);
mdbx_key_size -= (_obj_id_rec.iov_len + _session_id1_rec.iov_len + _session_id2_rec.iov_len + _ip_rec.iov_len + mdbx_key_size -=
_event_rec.iov_len); (_obj_id_rec.iov_len + _session_id1_rec.iov_len +
_session_id2_rec.iov_len + _ip_rec.iov_len + _event_rec.iov_len);
// transaction commit // transaction commit
MDBX_CHECK(mdbx_txn_commit(txn)); MDBX_CHECK(mdbx_txn_commit(txn));
mdbx_del_count++; mdbx_del_count++;
mdbx_del_time += (getClockUs() - start); mdbx_del_time += (getClockUs() - start);
} }
static void db_disconnect() { static void db_disconnect() {
mdbx_env_close(env); mdbx_env_close(env);
printf("Connection closed\n"); printf("Connection closed\n");
} }
static void get_db_stat(const char *db, int64_t *ms_branch_pages, int64_t *ms_leaf_pages) { static void get_db_stat(const char *db, int64_t *ms_branch_pages,
MDBX_txn *txn; int64_t *ms_leaf_pages) {
MDBX_stat stat; MDBX_txn *txn;
MDBX_dbi dbi; MDBX_stat stat;
MDBX_dbi dbi;
MDBX_CHECK(mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn)); MDBX_CHECK(mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn));
MDBX_CHECK(mdbx_dbi_open(txn, db, MDBX_CREATE, &dbi)); MDBX_CHECK(mdbx_dbi_open(txn, db, MDBX_CREATE, &dbi));
MDBX_CHECK(mdbx_dbi_stat(txn, dbi, &stat, sizeof(stat))); MDBX_CHECK(mdbx_dbi_stat(txn, dbi, &stat, sizeof(stat)));
mdbx_txn_abort(txn); mdbx_txn_abort(txn);
printf("%15s | %15ld | %5u | %10ld | %10ld | %11ld |\n", printf("%15s | %15ld | %5u | %10ld | %10ld | %11ld |\n", db,
db, stat.ms_branch_pages, stat.ms_depth, stat.ms_entries,
stat.ms_branch_pages, stat.ms_leaf_pages, stat.ms_overflow_pages);
stat.ms_depth, (*ms_branch_pages) += stat.ms_branch_pages;
stat.ms_entries, (*ms_leaf_pages) += stat.ms_leaf_pages;
stat.ms_leaf_pages,
stat.ms_overflow_pages);
(*ms_branch_pages) += stat.ms_branch_pages;
(*ms_leaf_pages) += stat.ms_leaf_pages;
} }
static void periodic_stat(void) { static void periodic_stat(void) {
int64_t ms_branch_pages = 0; int64_t ms_branch_pages = 0;
int64_t ms_leaf_pages = 0; int64_t ms_leaf_pages = 0;
MDBX_stat mst; MDBX_stat mst;
MDBX_envinfo mei; MDBX_envinfo mei;
MDBX_CHECK(mdbx_env_stat(env, &mst, sizeof(mst))); MDBX_CHECK(mdbx_env_stat(env, &mst, sizeof(mst)));
MDBX_CHECK(mdbx_env_info(env, &mei, sizeof(mei))); MDBX_CHECK(mdbx_env_info(env, &mei, sizeof(mei)));
printf("Environment Info\n"); printf("Environment Info\n");
printf(" Pagesize: %u\n", mst.ms_psize); printf(" Pagesize: %u\n", mst.ms_psize);
if (mei.mi_geo.lower != mei.mi_geo.upper) { if (mei.mi_geo.lower != mei.mi_geo.upper) {
printf(" Dynamic datafile: %" PRIu64 "..%" PRIu64 " bytes (+%" PRIu64 printf(" Dynamic datafile: %" PRIu64 "..%" PRIu64 " bytes (+%" PRIu64
"/-%" PRIu64 "), %" PRIu64 "..%" PRIu64 " pages (+%" PRIu64 "/-%" PRIu64 "), %" PRIu64 "..%" PRIu64 " pages (+%" PRIu64
"/-%" PRIu64 ")\n", "/-%" PRIu64 ")\n",
mei.mi_geo.lower, mei.mi_geo.upper, mei.mi_geo.grow, mei.mi_geo.lower, mei.mi_geo.upper, mei.mi_geo.grow,
mei.mi_geo.shrink, mei.mi_geo.lower / mst.ms_psize, mei.mi_geo.shrink, mei.mi_geo.lower / mst.ms_psize,
mei.mi_geo.upper / mst.ms_psize, mei.mi_geo.grow / mst.ms_psize, mei.mi_geo.upper / mst.ms_psize, mei.mi_geo.grow / mst.ms_psize,
mei.mi_geo.shrink / mst.ms_psize); mei.mi_geo.shrink / mst.ms_psize);
printf(" Current datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n", printf(" Current datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n",
mei.mi_geo.current, mei.mi_geo.current / mst.ms_psize); mei.mi_geo.current, mei.mi_geo.current / mst.ms_psize);
} else { } else {
printf(" Fixed datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n", printf(" Fixed datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n",
mei.mi_geo.current, mei.mi_geo.current / mst.ms_psize); mei.mi_geo.current, mei.mi_geo.current / mst.ms_psize);
} }
printf(" Current mapsize: %" PRIu64 " bytes, %" PRIu64 " pages \n", printf(" Current mapsize: %" PRIu64 " bytes, %" PRIu64 " pages \n",
mei.mi_mapsize, mei.mi_mapsize / mst.ms_psize); mei.mi_mapsize, mei.mi_mapsize / mst.ms_psize);
printf(" Number of pages used: %" PRIu64 "\n", mei.mi_last_pgno + 1); printf(" Number of pages used: %" PRIu64 "\n", mei.mi_last_pgno + 1);
printf(" Last transaction ID: %" PRIu64 "\n", mei.mi_recent_txnid); printf(" Last transaction ID: %" PRIu64 "\n", mei.mi_recent_txnid);
printf(" Tail transaction ID: %" PRIu64 " (%" PRIi64 ")\n", printf(" Tail transaction ID: %" PRIu64 " (%" PRIi64 ")\n",
mei.mi_latter_reader_txnid, mei.mi_latter_reader_txnid,
mei.mi_latter_reader_txnid - mei.mi_recent_txnid); mei.mi_latter_reader_txnid - mei.mi_recent_txnid);
printf(" Max readers: %u\n", mei.mi_maxreaders); printf(" Max readers: %u\n", mei.mi_maxreaders);
printf(" Number of readers used: %u\n", mei.mi_numreaders); printf(" Number of readers used: %u\n", mei.mi_numreaders);
printf(" Name | ms_branch_pages | depth | entries | leaf_pages | overf_pages |\n"); printf(" Name | ms_branch_pages | depth | entries | leaf_pages "
get_db_stat("session", &ms_branch_pages, &ms_leaf_pages); "| overf_pages |\n");
get_db_stat("session_id", &ms_branch_pages, &ms_leaf_pages); get_db_stat("session", &ms_branch_pages, &ms_leaf_pages);
get_db_stat("event", &ms_branch_pages, &ms_leaf_pages); get_db_stat("session_id", &ms_branch_pages, &ms_leaf_pages);
get_db_stat("ip", &ms_branch_pages, &ms_leaf_pages); get_db_stat("event", &ms_branch_pages, &ms_leaf_pages);
printf("%15s | %15ld | %5s | %10s | %10ld | %11s |\n", "", ms_branch_pages, "", "", ms_leaf_pages, ""); get_db_stat("ip", &ms_branch_pages, &ms_leaf_pages);
printf("%15s | %15ld | %5s | %10s | %10ld | %11s |\n", "", ms_branch_pages,
"", "", ms_leaf_pages, "");
static int64_t prev_add_count; static int64_t prev_add_count;
static int64_t prev_del_count; static int64_t prev_del_count;
static uint64_t prev_add_time; static uint64_t prev_add_time;
static uint64_t prev_del_time; static uint64_t prev_del_time;
static int64_t t = -1; static int64_t t = -1;
if (t > 0) { if (t > 0) {
int64_t delta = (getClockUs() - t); int64_t delta = (getClockUs() - t);
printf("CPS: add %ld, delete %ld, items processed - %ldK data=%ldK key=%ldK\n", printf(
(mdbx_add_count - prev_add_count) * 1000000 / delta, (mdbx_del_count - prev_del_count) * 1000000 / delta, "CPS: add %ld, delete %ld, items processed - %ldK data=%ldK key=%ldK\n",
obj_id / 1024, mdbx_data_size / 1024, mdbx_key_size / 1024); (mdbx_add_count - prev_add_count) * 1000000 / delta,
printf("usage data=%ld%%", (mdbx_del_count - prev_del_count) * 1000000 / delta, obj_id / 1024,
((mdbx_data_size + mdbx_key_size) * 100) / ((ms_leaf_pages + ms_branch_pages) * 4096)); mdbx_data_size / 1024, mdbx_key_size / 1024);
if (prev_add_time != mdbx_add_time) { printf("usage data=%ld%%", ((mdbx_data_size + mdbx_key_size) * 100) /
printf(" Add : %ld c/s", (mdbx_add_count - prev_add_count) * 1000000 / (mdbx_add_time - prev_add_time)); ((ms_leaf_pages + ms_branch_pages) * 4096));
} if (prev_add_time != mdbx_add_time) {
if (prev_del_time != mdbx_del_time) { printf(" Add : %ld c/s", (mdbx_add_count - prev_add_count) * 1000000 /
printf(" Del : %ld c/s", (mdbx_del_count - prev_del_count) * 1000000 / (mdbx_del_time - prev_del_time)); (mdbx_add_time - prev_add_time));
}
if (mdbx_add_time) {
printf(" tAdd : %ld c/s", mdbx_add_count * 1000000 / mdbx_add_time);
}
if (mdbx_del_time) {
printf(" tDel : %ld c/s", mdbx_del_count * 1000000 / mdbx_del_time);
}
puts("");
} }
t = getClockUs(); if (prev_del_time != mdbx_del_time) {
prev_add_count = mdbx_add_count; printf(" Del : %ld c/s", (mdbx_del_count - prev_del_count) * 1000000 /
prev_del_count = mdbx_del_count; (mdbx_del_time - prev_del_time));
prev_add_time = mdbx_add_time; }
prev_del_time = mdbx_del_time; if (mdbx_add_time) {
printf(" tAdd : %ld c/s", mdbx_add_count * 1000000 / mdbx_add_time);
}
if (mdbx_del_time) {
printf(" tDel : %ld c/s", mdbx_del_count * 1000000 / mdbx_del_time);
}
puts("");
}
t = getClockUs();
prev_add_count = mdbx_add_count;
prev_del_count = mdbx_del_count;
prev_add_time = mdbx_add_time;
prev_del_time = mdbx_del_time;
} }
//static void periodic_add_rec() { // static void periodic_add_rec() {
// for (int i = 0; i < 10240; i++) { // for (int i = 0; i < 10240; i++) {
// if (ids_count <= REC_COUNT) { // if (ids_count <= REC_COUNT) {
// int64_t id = obj_id++; // int64_t id = obj_id++;
@ -323,62 +343,62 @@ static void periodic_stat(void) {
//} //}
int main(int argc, char **argv) { int main(int argc, char **argv) {
(void) argc; (void)argc;
(void) argv; (void)argv;
char filename[PATH_MAX]; char filename[PATH_MAX];
int i;
mkdir(opt_db_path, 0775);
strcpy(filename, opt_db_path);
strcat(filename, "/mdbx.dat");
remove(filename);
strcpy(filename, opt_db_path);
strcat(filename, "/mdbx.lck");
remove(filename);
puts("Open DB...");
db_connect();
puts("Create data...");
int64_t t = getClockUs();
for (i = 0; i < REC_COUNT; i++) {
int64_t id = obj_id++;
create_record(id);
add_id_to_pool(id);
if (i % 1000 == 0) {
int64_t now = getClockUs();
if ((now - t) > 1000000L) {
periodic_stat();
t = now;
}
}
}
periodic_stat();
while (1) {
int i; int i;
for (i = 0; i < 1000; i++) {
mkdir(opt_db_path, 0775); int64_t id = obj_id++;
create_record(id);
strcpy(filename, opt_db_path); add_id_to_pool(id);
strcat(filename, "/mdbx.dat"); id = get_id_from_pool();
remove(filename); delete_record(id);
strcpy(filename, opt_db_path);
strcat(filename, "/mdbx.lck");
remove(filename);
puts("Open DB...");
db_connect();
puts("Create data...");
int64_t t = getClockUs();
for (i = 0; i < REC_COUNT; i++) {
int64_t id = obj_id++;
create_record(id);
add_id_to_pool(id);
if (i%1000==0) {
int64_t now = getClockUs();
if ((now - t) > 1000000L) {
periodic_stat();
t = now;
}
}
} }
periodic_stat(); // for (i = 0; i < 50; i++) {
while (1) { // int64_t id = obj_id++;
int i; // create_record(id);
for (i = 0; i < 1000; i++) { // add_id_to_pool(id);
int64_t id = obj_id++; // }
create_record(id); // int64_t id = obj_id++;
add_id_to_pool(id); // create_record(id);
id = get_id_from_pool(); // add_id_to_pool(id);
delete_record(id); int64_t now = getClockUs();
} if ((now - t) > 10000000L) {
// for (i = 0; i < 50; i++) { periodic_stat();
// int64_t id = obj_id++; t = now;
// create_record(id);
// add_id_to_pool(id);
// }
//int64_t id = obj_id++;
//create_record(id);
//add_id_to_pool(id);
int64_t now = getClockUs();
if ((now - t) > 10000000L) {
periodic_stat();
t = now;
}
} }
db_disconnect(); }
return 0; db_disconnect();
return 0;
} }

View File

@ -1,23 +1,19 @@
project(mdbx_tools) project(mdbx_tools)
set(MDBX_TOOLS set(MDBX_TOOLS
mdbx_chk mdbx_chk
mdbx_copy mdbx_copy
mdbx_dump mdbx_dump
mdbx_load mdbx_load
mdbx_stat mdbx_stat
) )
foreach (D_FILE ${MDBX_TOOLS}) foreach (TOOL ${MDBX_TOOLS})
add_executable(${D_FILE} add_executable(${TOOL} ${TOOL}.c)
${D_FILE}.c
)
target_link_libraries(${D_FILE} target_link_libraries(${TOOL} mdbx)
mdbx install(TARGETS ${TOOL} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT mdbx)
) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${TOOL}.1)
install(TARGETS ${D_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT mdbx) install(FILES ${TOOL}.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1 COMPONENT mdbx)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${D_FILE}.1) endif()
install(FILES ${D_FILE}.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1 COMPONENT mdbx) endforeach()
endif()
endforeach ()

View File

@ -1,11 +1,7 @@
set(TARGET mdbx_tutorial) set(TARGET mdbx_tutorial)
project(${TARGET}) project(${TARGET})
add_executable(${TARGET} add_executable(${TARGET} sample-mdbx.c)
sample-mdbx.c
)
target_link_libraries(${TARGET} target_link_libraries(${TARGET} mdbx)
mdbx
)