summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx/src/libmdbx/test
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Dbx_mdbx/src/libmdbx/test')
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/CMakeLists.txt34
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/base.h4
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/cases.cc2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/chrono.cc2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/chrono.h2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/config.cc2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/config.h2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/dead.cc4
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/hill.cc4
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/jitter.cc2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/keygen.cc2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/keygen.h2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/log.cc2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/log.h2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/main.cc2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/osal-unix.cc2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/osal-windows.cc2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/osal.h2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/pcrf/CMakeLists.txt7
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/pcrf/README.md2
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/pcrf/pcrf_test.c404
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/test.cc4
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/test.h4
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/utils.cc75
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/utils.h2
25 files changed, 510 insertions, 62 deletions
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/CMakeLists.txt b/plugins/Dbx_mdbx/src/libmdbx/test/CMakeLists.txt
new file mode 100644
index 0000000000..3ed01bddf9
--- /dev/null
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/CMakeLists.txt
@@ -0,0 +1,34 @@
+set(TARGET mdbx_test)
+project(${TARGET})
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-declarations")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-cast-qual")
+
+add_executable(${TARGET}
+ base.h
+ cases.cc
+ chrono.cc
+ chrono.h
+ config.cc
+ config.h
+ dead.cc
+ hill.cc
+ jitter.cc
+ keygen.cc
+ keygen.h
+ log.cc
+ log.h
+ main.cc
+ osal.h
+ osal-unix.cc
+ test.cc
+ test.h
+ try.cc
+ utils.cc
+ utils.h
+)
+
+target_link_libraries(${TARGET}
+ mdbx
+ )
+
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/base.h b/plugins/Dbx_mdbx/src/libmdbx/test/base.h
index ffcf61adf3..63554e730d 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/base.h
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/base.h
@@ -1,5 +1,5 @@
-/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+/*
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/cases.cc b/plugins/Dbx_mdbx/src/libmdbx/test/cases.cc
index a1953f53c1..4f4306d58e 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/cases.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/cases.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/chrono.cc b/plugins/Dbx_mdbx/src/libmdbx/test/chrono.cc
index b6245295e7..f734668628 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/chrono.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/chrono.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/chrono.h b/plugins/Dbx_mdbx/src/libmdbx/test/chrono.h
index d5e9f658d1..c2bd5627a6 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/chrono.h
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/chrono.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/config.cc b/plugins/Dbx_mdbx/src/libmdbx/test/config.cc
index 81b26b8383..2b9c6e5a0c 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/config.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/config.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/config.h b/plugins/Dbx_mdbx/src/libmdbx/test/config.h
index 4c9aa2142b..5efd31100a 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/config.h
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/config.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/dead.cc b/plugins/Dbx_mdbx/src/libmdbx/test/dead.cc
index c7b338ff7a..ee13fbd0ae 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/dead.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/dead.cc
@@ -1,5 +1,5 @@
-/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+/*
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/hill.cc b/plugins/Dbx_mdbx/src/libmdbx/test/hill.cc
index 72a6e95b35..c9115784d4 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/hill.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/hill.cc
@@ -1,5 +1,5 @@
-/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+/*
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/jitter.cc b/plugins/Dbx_mdbx/src/libmdbx/test/jitter.cc
index 92d272e1e5..e7faf2a3f9 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/jitter.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/jitter.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/keygen.cc b/plugins/Dbx_mdbx/src/libmdbx/test/keygen.cc
index 806d4ba80d..99b46f2976 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/keygen.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/keygen.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/keygen.h b/plugins/Dbx_mdbx/src/libmdbx/test/keygen.h
index 911ea6d89b..c1e907bc0b 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/keygen.h
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/keygen.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/log.cc b/plugins/Dbx_mdbx/src/libmdbx/test/log.cc
index 5ab9951338..8697effd8f 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/log.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/log.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/log.h b/plugins/Dbx_mdbx/src/libmdbx/test/log.h
index 3ffc21d2e8..c321f3ce91 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/log.h
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/log.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/main.cc b/plugins/Dbx_mdbx/src/libmdbx/test/main.cc
index 2c4f9b09fd..adf60aae62 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/main.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/main.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/osal-unix.cc b/plugins/Dbx_mdbx/src/libmdbx/test/osal-unix.cc
index 88a10f1175..7625e0f419 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/osal-unix.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/osal-unix.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/osal-windows.cc b/plugins/Dbx_mdbx/src/libmdbx/test/osal-windows.cc
index 57f7f547f2..b1a8928cbb 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/osal-windows.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/osal-windows.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/osal.h b/plugins/Dbx_mdbx/src/libmdbx/test/osal.h
index 8f1626350c..f75aae3831 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/osal.h
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/osal.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/pcrf/CMakeLists.txt b/plugins/Dbx_mdbx/src/libmdbx/test/pcrf/CMakeLists.txt
new file mode 100644
index 0000000000..399c33f88f
--- /dev/null
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/pcrf/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(TARGET pcrf_test)
+project(${TARGET})
+
+add_executable(${TARGET} pcrf_test.c)
+
+target_link_libraries(${TARGET} mdbx)
+
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/pcrf/README.md b/plugins/Dbx_mdbx/src/libmdbx/test/pcrf/README.md
new file mode 100644
index 0000000000..b2c9b5ce95
--- /dev/null
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/pcrf/README.md
@@ -0,0 +1,2 @@
+PCRF Session DB emulation test
+
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/pcrf/pcrf_test.c b/plugins/Dbx_mdbx/src/libmdbx/test/pcrf/pcrf_test.c
new file mode 100644
index 0000000000..213c8b1d80
--- /dev/null
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/pcrf/pcrf_test.c
@@ -0,0 +1,404 @@
+/*
+ * Copyright 2016-2017 Leonid Yuriev <leo@yuriev.ru>.
+ * Copyright 2015 Vladimir Romanov
+ * <https://www.linkedin.com/in/vladimirromanov>, Yota Lab.
+ *
+ * This file is part of libmdbx.
+ *
+ * ReOpenMDBX is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * ReOpenMDBX is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/stat.h>
+#include <sys/time.h>
+
+#include "mdbx.h"
+#include <assert.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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;
+#define REC_COUNT 10240000
+int64_t ids[REC_COUNT * 10];
+int32_t ids_count = 0;
+
+int64_t mdbx_add_count = 0;
+int64_t mdbx_del_count = 0;
+uint64_t mdbx_add_time = 0;
+uint64_t mdbx_del_time = 0;
+int64_t obj_id = 0;
+int64_t mdbx_data_size = 0;
+int64_t mdbx_key_size = 0;
+
+typedef struct {
+ char session_id1[100];
+ char session_id2[100];
+ char ip[20];
+ uint8_t fill[100];
+} session_data_t;
+
+typedef struct {
+ int64_t obj_id;
+ int8_t event_type;
+} __attribute__((__packed__)) event_data_t;
+
+static void add_id_to_pool(int64_t id) {
+ ids[ids_count] = id;
+ ids_count++;
+}
+
+static inline int64_t getClockUs(void) {
+ struct timespec val;
+#ifdef CYGWIN
+ clock_gettime(CLOCK_REALTIME, &val);
+#else
+ clock_gettime(CLOCK_MONOTONIC, &val);
+#endif
+ return val.tv_sec * ((int64_t)1000000) + val.tv_nsec / 1000;
+}
+
+static int64_t get_id_from_pool() {
+ if (ids_count == 0) {
+ return -1;
+ }
+ int32_t index = rand() % ids_count;
+ int64_t id = ids[index];
+ ids[index] = ids[ids_count - 1];
+ ids_count--;
+ return id;
+}
+
+#define MDBX_CHECK(x) \
+ 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__); \
+ exit(EXIT_FAILURE); \
+ } \
+ } while (0)
+
+static void db_connect() {
+ MDBX_dbi dbi_session;
+ MDBX_dbi dbi_session_id;
+ MDBX_dbi dbi_event;
+ 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_maxdbs(env, 30));
+ 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
+ MDBX_CHECK(mdbx_txn_begin(env, NULL, 0, &txn));
+ // open database in read-write mode
+ 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, "event", MDBX_CREATE, &dbi_event));
+ MDBX_CHECK(mdbx_dbi_open(txn, "ip", MDBX_CREATE, &dbi_ip));
+ // transaction commit
+ MDBX_CHECK(mdbx_txn_commit(txn));
+ printf("Connection open\n");
+}
+
+static void create_record(int64_t record_id) {
+ MDBX_dbi dbi_session;
+ MDBX_dbi dbi_session_id;
+ MDBX_dbi dbi_event;
+ MDBX_dbi dbi_ip;
+ event_data_t event;
+ 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",
+ 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,
+ record_id % 1000000000 + 99999);
+ 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_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 _event_rec = {&event, sizeof(event)};
+
+ uint64_t start = getClockUs();
+ 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_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_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);
+
+ // transaction commit
+ mdbx_add_count++;
+ mdbx_add_time += (getClockUs() - start);
+}
+
+static void delete_record(int64_t record_id) {
+ MDBX_dbi dbi_session;
+ MDBX_dbi dbi_session_id;
+ MDBX_dbi dbi_event;
+ MDBX_dbi dbi_ip;
+ event_data_t event;
+ MDBX_txn *txn;
+
+ // transaction init
+ uint64_t start = getClockUs();
+ MDBX_CHECK(mdbx_txn_begin(env, NULL, 0, &txn));
+ // open database in read-write mode
+ 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, "event", MDBX_CREATE, &dbi_event));
+ MDBX_CHECK(mdbx_dbi_open(txn, "ip", MDBX_CREATE, &dbi_ip));
+ // put data
+ MDBX_val _obj_id_rec = {&record_id, sizeof(record_id)};
+ MDBX_val _data_rec;
+ // get data
+ MDBX_CHECK(mdbx_get(txn, dbi_session, &_obj_id_rec, &_data_rec));
+ 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_id2_rec = {data->session_id2, strlen(data->session_id2)};
+ 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_id2_rec, NULL));
+ MDBX_CHECK(mdbx_del(txn, dbi_ip, &_ip_rec, NULL));
+ event.obj_id = record_id;
+ event.event_type = 1;
+ MDBX_val _event_rec = {&event, sizeof(event)};
+ MDBX_CHECK(mdbx_del(txn, dbi_event, &_event_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_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));
+ mdbx_del_count++;
+ mdbx_del_time += (getClockUs() - start);
+}
+
+static void db_disconnect() {
+ mdbx_env_close(env);
+ printf("Connection closed\n");
+}
+
+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;
+
+ MDBX_CHECK(mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn));
+ 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);
+ (*ms_branch_pages) += stat.ms_branch_pages;
+ (*ms_leaf_pages) += stat.ms_leaf_pages;
+}
+
+static void periodic_stat(void) {
+ int64_t ms_branch_pages = 0;
+ int64_t ms_leaf_pages = 0;
+ MDBX_stat mst;
+ MDBX_envinfo mei;
+ MDBX_CHECK(mdbx_env_stat(env, &mst, sizeof(mst)));
+ MDBX_CHECK(mdbx_env_info(env, &mei, sizeof(mei)));
+ printf("Environment Info\n");
+ printf(" Pagesize: %u\n", mst.ms_psize);
+ if (mei.mi_geo.lower != mei.mi_geo.upper) {
+ printf(" Dynamic datafile: %" PRIu64 "..%" PRIu64 " bytes (+%" PRIu64
+ "/-%" PRIu64 "), %" PRIu64 "..%" PRIu64 " pages (+%" PRIu64
+ "/-%" PRIu64 ")\n",
+ 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.upper / mst.ms_psize, mei.mi_geo.grow / mst.ms_psize,
+ mei.mi_geo.shrink / mst.ms_psize);
+ printf(" Current datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n",
+ mei.mi_geo.current, mei.mi_geo.current / mst.ms_psize);
+ } else {
+ printf(" Fixed datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n",
+ mei.mi_geo.current, mei.mi_geo.current / mst.ms_psize);
+ }
+ printf(" Current mapsize: %" PRIu64 " bytes, %" PRIu64 " pages \n",
+ mei.mi_mapsize, mei.mi_mapsize / mst.ms_psize);
+ printf(" Number of pages used: %" PRIu64 "\n", mei.mi_last_pgno + 1);
+ printf(" Last transaction ID: %" PRIu64 "\n", mei.mi_recent_txnid);
+ printf(" Tail transaction ID: %" PRIu64 " (%" PRIi64 ")\n",
+ mei.mi_latter_reader_txnid,
+ mei.mi_latter_reader_txnid - mei.mi_recent_txnid);
+ 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");
+ 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, "");
+
+ static int64_t prev_add_count;
+ static int64_t prev_del_count;
+ static uint64_t prev_add_time;
+ static uint64_t prev_del_time;
+ 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));
+ 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));
+ }
+ 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));
+ }
+ 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() {
+// for (int i = 0; i < 10240; i++) {
+// if (ids_count <= REC_COUNT) {
+// int64_t id = obj_id++;
+// create_record(id);
+// add_id_to_pool(id);
+// }
+// if (ids_count > REC_COUNT) {
+// int64_t id = get_id_from_pool();
+// delete_record(id);
+// }
+// }
+// periodic_stat();
+//}
+
+int main(int argc, char **argv) {
+ (void)argc;
+ (void)argv;
+
+ 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;
+ for (i = 0; i < 1000; i++) {
+ int64_t id = obj_id++;
+ create_record(id);
+ add_id_to_pool(id);
+ id = get_id_from_pool();
+ delete_record(id);
+ }
+ // for (i = 0; i < 50; i++) {
+ // int64_t id = obj_id++;
+ // 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;
+}
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/test.cc b/plugins/Dbx_mdbx/src/libmdbx/test/test.cc
index f1dc226465..8700d74add 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/test.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/test.cc
@@ -1,5 +1,5 @@
-/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+/*
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/test.h b/plugins/Dbx_mdbx/src/libmdbx/test/test.h
index 67fadebf07..4158aba457 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/test.h
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/test.h
@@ -1,5 +1,5 @@
-/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+/*
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/utils.cc b/plugins/Dbx_mdbx/src/libmdbx/test/utils.cc
index 9a6338cc31..96866f61b7 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/utils.cc
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/utils.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
@@ -18,6 +18,40 @@
#include <ieee754.h>
#endif
+/* Compiler's includes for builtins/intrinsics */
+#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
+#include <intrin.h>
+#elif __GNUC_PREREQ(4, 4) || defined(__clang__)
+#if defined(__ia32__) || defined(__e2k__)
+#include <x86intrin.h>
+#endif /* __ia32__ */
+#if defined(__ia32__)
+#include <cpuid.h>
+#endif /* __ia32__ */
+#elif defined(__SUNPRO_C) || defined(__sun) || defined(sun)
+#include <mbarrier.h>
+#elif (defined(_HPUX_SOURCE) || defined(__hpux) || defined(__HP_aCC)) && \
+ (defined(HP_IA64) || defined(__ia64))
+#include <machine/sys/inline.h>
+#elif defined(__IBMC__) && defined(__powerpc)
+#include <atomic.h>
+#elif defined(_AIX)
+#include <builtins.h>
+#include <sys/atomic_op.h>
+#elif (defined(__osf__) && defined(__DECC)) || defined(__alpha)
+#include <c_asm.h>
+#include <machine/builtins.h>
+#elif defined(__MWERKS__)
+/* CodeWarrior - troubles ? */
+#pragma gcc_extensions
+#elif defined(__SNC__)
+/* Sony PS3 - troubles ? */
+#elif defined(__hppa__) || defined(__hppa)
+#include <machine/inline.h>
+#else
+#error Unsupported C compiler, please use GNU C 4.4 or newer
+#endif /* Compiler */
+
std::string format(const char *fmt, ...) {
va_list ap, ones;
va_start(ap, fmt);
@@ -93,19 +127,6 @@ bool hex2data(const char *hex_begin, const char *hex_end, void *ptr,
//-----------------------------------------------------------------------------
-#ifdef __mips__
-static uint64_t *mips_tsc_addr;
-
-__cold static void mips_rdtsc_init() {
- int mem_fd = open("/dev/mem", O_RDONLY | O_SYNC, 0);
- HIPPEUS_ENSURE(mem_fd >= 0);
-
- mips_tsc_addr = mmap(nullptr, pagesize, PROT_READ, MAP_SHARED, mem_fd,
- 0x10030000 /* MIPS_ZBUS_TIMER */);
- close(mem_fd);
-}
-#endif /* __mips__ */
-
uint64_t entropy_ticks(void) {
#if defined(__GNUC__) || defined(__clang__)
#if defined(__ia64__)
@@ -141,31 +162,11 @@ uint64_t entropy_ticks(void) {
__asm __volatile("mftbu %0" : "=r"(tbu));
return (((uin64_t)tbu0) << 32) | tbl;
-#elif defined(__mips__)
- if (mips_tsc_addr != MAP_FAILED) {
- if (unlikely(!mips_tsc_addr)) {
- static pthread_once_t is_initialized = PTHREAD_ONCE_INIT;
- int rc = pthread_once(&is_initialized, mips_rdtsc_init);
- if (unlikely(rc))
- failure_perror("pthread_once()", rc);
- }
- if (mips_tsc_addr != MAP_FAILED)
- return *mips_tsc_addr;
- }
-#elif defined(__x86_64__) || defined(__i386__)
-#if __GNUC_PREREQ(4, 7) || __has_builtin(__builtin_ia32_rdtsc)
- return __builtin_ia32_rdtsc();
-#else
- unsigned lo, hi;
-
- /* LY: Using the "a" and "d" constraints is important for correct code. */
- __asm __volatile("rdtsc" : "=a"(lo), "=d"(hi));
-
- return (((uint64_t)hi) << 32) + lo;
-#endif
#endif /* arch selector */
+#endif /* __GNUC__ || __clang__ */
-#elif defined(_M_IX86) || defined(_M_X64)
+#if defined(__e2k__) || defined(__elbrus__) || defined(_M_IX86) || \
+ defined(_M_X64) || defined(__x86_64__) || defined(__i386__)
return __rdtsc();
#elif defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS)
LARGE_INTEGER PerformanceCount;
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/utils.h b/plugins/Dbx_mdbx/src/libmdbx/test/utils.h
index b7fd62eb09..176823c60b 100644
--- a/plugins/Dbx_mdbx/src/libmdbx/test/utils.h
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*