mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-30 22:47:16 +08:00
mdbx-build: minor cleanup after pul-request/merge.
Change-Id: Ia612dbd939be7acd938fca8eb3f93f650560417a
This commit is contained in:
parent
506caee9e5
commit
ab7cb2c39e
40
.gitignore
vendored
40
.gitignore
vendored
@ -1,39 +1,37 @@
|
||||
*[~#]
|
||||
*.[ao]
|
||||
*.bak
|
||||
.le.ini
|
||||
core
|
||||
core.*
|
||||
*.exe
|
||||
*.gcda
|
||||
*.gcno
|
||||
*.gcov
|
||||
libmdbx.creator.user
|
||||
*.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
|
||||
*.rej
|
||||
*.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/tmp.db
|
||||
test/tmp.db-lck
|
||||
tmp.db
|
||||
tmp.db-lck
|
||||
valgrind.*
|
||||
.vs/
|
||||
Win32/
|
||||
x64/
|
||||
x86/
|
||||
test.log
|
||||
|
||||
cmake-build-*
|
||||
build-*
|
||||
.idea
|
||||
|
3
AUTHORS
3
AUTHORS
@ -1,4 +1,4 @@
|
||||
Contributors
|
||||
Contributors
|
||||
============
|
||||
|
||||
Alexey Naumov <alexey.naumov@gmail.com>
|
||||
@ -28,3 +28,4 @@ Philipp Storz <philipp.storz@bareos.com>
|
||||
Quanah Gibson-Mount <quanah@openldap.org>
|
||||
Salvador Ortiz <sog@msg.com.mx>
|
||||
Sebastien Launay <sebastien@slaunay.fr>
|
||||
Vladimir Romanov <vromanov@gmail.com>
|
||||
|
@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8.7)
|
||||
set(TARGET mdbx)
|
||||
project(${TARGET})
|
||||
|
||||
# FIXME/TODO: Same as https://github.com/leo-yuriev/libfpta
|
||||
set(MDBX_VERSION_MAJOR 0)
|
||||
set(MDBX_VERSION_MINOR 0)
|
||||
set(MDBX_VERSION_PATCH 0)
|
||||
@ -71,16 +72,12 @@ else ()
|
||||
endif()
|
||||
|
||||
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()
|
||||
|
||||
if (TRAVIS)
|
||||
add_definitions(-DNO_MLOCK)
|
||||
else ()
|
||||
if (NOT TRAVIS)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fsanitize=leak -fstack-protector-strong -static-libasan")
|
||||
endif()
|
||||
endif()
|
||||
@ -137,6 +134,7 @@ add_subdirectory(test)
|
||||
add_subdirectory(src/tools)
|
||||
add_subdirectory(pcrf_test)
|
||||
|
||||
##############################################################################
|
||||
|
||||
set(CPACK_GENERATOR "RPM")
|
||||
set(CPACK_RPM_COMPONENT_INSTALL ON)
|
||||
|
@ -1,3 +1,8 @@
|
||||
CMakeLists.txt
|
||||
pcrf_test/CMakeLists.txt
|
||||
src/tools/CMakeLists.txt
|
||||
test/CMakeLists.txt
|
||||
tutorial/CMakeLists.txt
|
||||
tutorial/sample-mdbx.c
|
||||
AUTHORS
|
||||
LICENSE
|
||||
|
@ -2,3 +2,5 @@
|
||||
src
|
||||
src/tools
|
||||
test
|
||||
pcrf_test
|
||||
tutorial
|
||||
|
@ -1,11 +1,7 @@
|
||||
set(TARGET pcrf_test)
|
||||
project(${TARGET})
|
||||
|
||||
add_executable(${TARGET}
|
||||
pcrf_test.c
|
||||
)
|
||||
add_executable(${TARGET} pcrf_test.c)
|
||||
|
||||
target_link_libraries(${TARGET}
|
||||
mdbx
|
||||
)
|
||||
target_link_libraries(${TARGET} mdbx)
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
@ -18,20 +19,22 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "mdbx.h"
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "mdbx.h"
|
||||
#include <inttypes.h>
|
||||
#include <string.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";
|
||||
static MDBX_env *env;
|
||||
@ -89,7 +92,8 @@ static int64_t get_id_from_pool() {
|
||||
do { \
|
||||
const int rc = (x); \
|
||||
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, \
|
||||
__FILE__, __LINE__); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} \
|
||||
} while (0)
|
||||
@ -101,9 +105,13 @@ static void db_connect() {
|
||||
MDBX_dbi dbi_ip;
|
||||
|
||||
MDBX_CHECK(mdbx_env_create(&env));
|
||||
MDBX_CHECK(mdbx_env_set_mapsize(env, REC_COUNT * sizeof(session_data_t) * 10));
|
||||
MDBX_CHECK(
|
||||
mdbx_env_set_mapsize(env, REC_COUNT * sizeof(session_data_t) * 10));
|
||||
MDBX_CHECK(mdbx_env_set_maxdbs(env, 30));
|
||||
MDBX_CHECK(mdbx_env_open(env, opt_db_path, MDBX_CREATE | MDBX_WRITEMAP | MDBX_MAPASYNC| MDBX_NOSYNC | MDBX_LIFORECLAIM, 0664));
|
||||
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
|
||||
@ -127,11 +135,14 @@ static void create_record(int64_t record_id) {
|
||||
MDBX_txn *txn;
|
||||
session_data_t data;
|
||||
// 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),
|
||||
"prefix%02ld_%02ld.fill.fill.fill.fill.fill.fill;%ld",
|
||||
record_id % 3 + 1, record_id % 9 + 1, record_id);
|
||||
snprintf(data.session_id2, sizeof(data.session_id2), "dprefix%ld;%ld.fill.fill.;suffix", record_id,
|
||||
snprintf(data.session_id2, sizeof(data.session_id2),
|
||||
"dprefix%ld;%ld.fill.fill.;suffix", record_id,
|
||||
record_id % 1000000000 + 99999);
|
||||
snprintf(data.ip, sizeof(data.ip), "%d.%d.%d.%d", IP_PRINTF_ARG_HOST(record_id & 0xFFFFFFFF));
|
||||
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;
|
||||
|
||||
@ -139,7 +150,8 @@ static void create_record(int64_t record_id) {
|
||||
MDBX_val _session_id2_rec = {data.session_id2, strlen(data.session_id2)};
|
||||
MDBX_val _ip_rec = {data.ip, strlen(data.ip)};
|
||||
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) +
|
||||
(rand() % sizeof(data.fill))};
|
||||
MDBX_val _event_rec = {&event, sizeof(event)};
|
||||
|
||||
uint64_t start = getClockUs();
|
||||
@ -148,16 +160,20 @@ static void create_record(int64_t record_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, "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_id, &_session_id1_rec, &_obj_id_rec, 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, &_obj_id_rec, &_data_rec,
|
||||
MDBX_NOOVERWRITE | MDBX_NODUPDATA));
|
||||
MDBX_CHECK(mdbx_put(txn, dbi_session_id, &_session_id1_rec, &_obj_id_rec,
|
||||
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_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_key_size += (_obj_id_rec.iov_len + _session_id1_rec.iov_len + _session_id2_rec.iov_len + _ip_rec.iov_len +
|
||||
_event_rec.iov_len);
|
||||
mdbx_key_size +=
|
||||
(_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
|
||||
mdbx_add_count++;
|
||||
@ -200,8 +216,9 @@ static void delete_record(int64_t record_id) {
|
||||
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_key_size -= (_obj_id_rec.iov_len + _session_id1_rec.iov_len + _session_id2_rec.iov_len + _ip_rec.iov_len +
|
||||
_event_rec.iov_len);
|
||||
mdbx_key_size -=
|
||||
(_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
|
||||
MDBX_CHECK(mdbx_txn_commit(txn));
|
||||
@ -214,7 +231,8 @@ static void db_disconnect() {
|
||||
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,
|
||||
int64_t *ms_leaf_pages) {
|
||||
MDBX_txn *txn;
|
||||
MDBX_stat stat;
|
||||
MDBX_dbi dbi;
|
||||
@ -223,13 +241,9 @@ static void get_db_stat(const char *db, int64_t *ms_branch_pages, int64_t *ms_le
|
||||
MDBX_CHECK(mdbx_dbi_open(txn, db, MDBX_CREATE, &dbi));
|
||||
MDBX_CHECK(mdbx_dbi_stat(txn, dbi, &stat, sizeof(stat)));
|
||||
mdbx_txn_abort(txn);
|
||||
printf("%15s | %15ld | %5u | %10ld | %10ld | %11ld |\n",
|
||||
db,
|
||||
stat.ms_branch_pages,
|
||||
stat.ms_depth,
|
||||
stat.ms_entries,
|
||||
stat.ms_leaf_pages,
|
||||
stat.ms_overflow_pages);
|
||||
printf("%15s | %15ld | %5u | %10ld | %10ld | %11ld |\n", db,
|
||||
stat.ms_branch_pages, stat.ms_depth, stat.ms_entries,
|
||||
stat.ms_leaf_pages, stat.ms_overflow_pages);
|
||||
(*ms_branch_pages) += stat.ms_branch_pages;
|
||||
(*ms_leaf_pages) += stat.ms_leaf_pages;
|
||||
}
|
||||
@ -267,12 +281,14 @@ static void periodic_stat(void) {
|
||||
printf(" Max readers: %u\n", mei.mi_maxreaders);
|
||||
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 "
|
||||
"| overf_pages |\n");
|
||||
get_db_stat("session", &ms_branch_pages, &ms_leaf_pages);
|
||||
get_db_stat("session_id", &ms_branch_pages, &ms_leaf_pages);
|
||||
get_db_stat("event", &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, "");
|
||||
printf("%15s | %15ld | %5s | %10s | %10ld | %11s |\n", "", ms_branch_pages,
|
||||
"", "", ms_leaf_pages, "");
|
||||
|
||||
static int64_t prev_add_count;
|
||||
static int64_t prev_del_count;
|
||||
@ -281,16 +297,20 @@ static void periodic_stat(void) {
|
||||
static int64_t t = -1;
|
||||
if (t > 0) {
|
||||
int64_t delta = (getClockUs() - t);
|
||||
printf("CPS: add %ld, delete %ld, items processed - %ldK data=%ldK key=%ldK\n",
|
||||
(mdbx_add_count - prev_add_count) * 1000000 / delta, (mdbx_del_count - prev_del_count) * 1000000 / delta,
|
||||
obj_id / 1024, mdbx_data_size / 1024, mdbx_key_size / 1024);
|
||||
printf("usage data=%ld%%",
|
||||
((mdbx_data_size + mdbx_key_size) * 100) / ((ms_leaf_pages + ms_branch_pages) * 4096));
|
||||
printf(
|
||||
"CPS: add %ld, delete %ld, items processed - %ldK data=%ldK key=%ldK\n",
|
||||
(mdbx_add_count - prev_add_count) * 1000000 / delta,
|
||||
(mdbx_del_count - prev_del_count) * 1000000 / delta, obj_id / 1024,
|
||||
mdbx_data_size / 1024, mdbx_key_size / 1024);
|
||||
printf("usage data=%ld%%", ((mdbx_data_size + mdbx_key_size) * 100) /
|
||||
((ms_leaf_pages + ms_branch_pages) * 4096));
|
||||
if (prev_add_time != mdbx_add_time) {
|
||||
printf(" Add : %ld c/s", (mdbx_add_count - prev_add_count) * 1000000 / (mdbx_add_time - prev_add_time));
|
||||
printf(" Add : %ld c/s", (mdbx_add_count - prev_add_count) * 1000000 /
|
||||
(mdbx_add_time - prev_add_time));
|
||||
}
|
||||
if (prev_del_time != mdbx_del_time) {
|
||||
printf(" Del : %ld c/s", (mdbx_del_count - prev_del_count) * 1000000 / (mdbx_del_time - prev_del_time));
|
||||
printf(" Del : %ld c/s", (mdbx_del_count - prev_del_count) * 1000000 /
|
||||
(mdbx_del_time - prev_del_time));
|
||||
}
|
||||
if (mdbx_add_time) {
|
||||
printf(" tAdd : %ld c/s", mdbx_add_count * 1000000 / mdbx_add_time);
|
||||
|
@ -8,16 +8,12 @@ set(MDBX_TOOLS
|
||||
mdbx_stat
|
||||
)
|
||||
|
||||
foreach (D_FILE ${MDBX_TOOLS})
|
||||
add_executable(${D_FILE}
|
||||
${D_FILE}.c
|
||||
)
|
||||
foreach (TOOL ${MDBX_TOOLS})
|
||||
add_executable(${TOOL} ${TOOL}.c)
|
||||
|
||||
target_link_libraries(${D_FILE}
|
||||
mdbx
|
||||
)
|
||||
install(TARGETS ${D_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT mdbx)
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${D_FILE}.1)
|
||||
install(FILES ${D_FILE}.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1 COMPONENT mdbx)
|
||||
target_link_libraries(${TOOL} mdbx)
|
||||
install(TARGETS ${TOOL} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT mdbx)
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${TOOL}.1)
|
||||
install(FILES ${TOOL}.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1 COMPONENT mdbx)
|
||||
endif()
|
||||
endforeach()
|
||||
|
@ -1,11 +1,7 @@
|
||||
set(TARGET mdbx_tutorial)
|
||||
project(${TARGET})
|
||||
|
||||
add_executable(${TARGET}
|
||||
sample-mdbx.c
|
||||
)
|
||||
add_executable(${TARGET} sample-mdbx.c)
|
||||
|
||||
target_link_libraries(${TARGET}
|
||||
mdbx
|
||||
)
|
||||
target_link_libraries(${TARGET} mdbx)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user