mdbx: MDB_val as struct iovec.

Change-Id: I08d9dcabaf88564b367bc2752e596ebea0e7cbf9
This commit is contained in:
Leo Yuriev 2016-03-27 04:25:31 +03:00
parent 321bc2b901
commit f833877083
3 changed files with 32 additions and 22 deletions

10
lmdb.h
View File

@ -170,6 +170,10 @@
#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#if MDBX_MODE_ENABLED
# include <sys/uio.h>
# include <unistd.h>
#endif /* MDBX_MODE_ENABLED */
#ifdef __cplusplus
extern "C" {
@ -246,10 +250,16 @@ typedef struct MDB_cursor MDB_cursor;
* The same applies to data sizes in databases with the #MDB_DUPSORT flag.
* Other data items can in theory be from 0 to 0xffffffff bytes long.
*/
#if MDBX_MODE_ENABLED
typedef struct iovec MDB_val;
# define mv_size iov_len
# define mv_data iov_base
#else
typedef struct MDB_val {
size_t mv_size; /**< size of the data item */
void *mv_data; /**< address of the data item */
} MDB_val;
#endif /* MDBX_MODE_ENABLED */
/** @brief A callback function used to compare two keys in a database */
typedef long (MDB_cmp_func)(const MDB_val *a, const MDB_val *b);

View File

@ -92,12 +92,12 @@ static void create_record(int64_t record_id) {
event.obj_id = record_id;
event.event_type = 1;
MDB_val _session_id1_rec = {strlen(data.session_id1), data.session_id1};
MDB_val _session_id2_rec = {strlen(data.session_id2), data.session_id2};
MDB_val _ip_rec = {strlen(data.ip), data.ip};
MDB_val _obj_id_rec = {sizeof (record_id), &record_id};
MDB_val _data_rec = {offsetof(session_data_t, fill) + (rand() % sizeof (data.fill)), &data};
MDB_val _event_rec = {sizeof (event), &event};
MDB_val _session_id1_rec = {data.session_id1, strlen(data.session_id1)};
MDB_val _session_id2_rec = {data.session_id2, strlen(data.session_id2)};
MDB_val _ip_rec = {data.ip, strlen(data.ip)};
MDB_val _obj_id_rec = {&record_id, sizeof (record_id)};
MDB_val _data_rec = {&data, offsetof(session_data_t, fill) + (rand() % sizeof (data.fill))};
MDB_val _event_rec = {&event, sizeof (event)};
LMDB_CHECK(mdb_txn_begin(env, NULL, 0, &txn));
LMDB_CHECK(mdb_dbi_open(txn, "session", MDB_CREATE, &dbi_session));
@ -131,21 +131,21 @@ static void delete_record(int64_t record_id) {
LMDB_CHECK(mdb_dbi_open(txn, "event", MDB_CREATE, &dbi_event));
LMDB_CHECK(mdb_dbi_open(txn, "ip", MDB_CREATE, &dbi_ip));
// put data
MDB_val _obj_id_rec = {sizeof (record_id), &record_id};
MDB_val _obj_id_rec = {&record_id, sizeof(record_id)};
MDB_val v_rec;
// get data
LMDB_CHECK(mdb_get(txn, dbi_session, &_obj_id_rec, &v_rec));
session_data_t* data = (session_data_t*) v_rec.mv_data;
MDB_val _session_id1_rec = {strlen(data->session_id1), data->session_id1};
MDB_val _session_id2_rec = {strlen(data->session_id2), data->session_id2};
MDB_val _ip_rec = {strlen(data->ip), data->ip};
MDB_val _session_id1_rec = {data->session_id1, strlen(data->session_id1)};
MDB_val _session_id2_rec = {data->session_id2, strlen(data->session_id2)};
MDB_val _ip_rec = {data->ip, strlen(data->ip)};
LMDB_CHECK(mdb_del(txn, dbi_session_id, &_session_id1_rec, NULL));
LMDB_CHECK(mdb_del(txn, dbi_session_id, &_session_id2_rec, NULL));
LMDB_CHECK(mdb_del(txn, dbi_ip, &_ip_rec, NULL));
event.obj_id = record_id;
event.event_type = 1;
MDB_val _event_rec = {sizeof (event), &event};
MDB_val _event_rec = {&event, sizeof(event)};
LMDB_CHECK(mdb_del(txn, dbi_event, &_event_rec, NULL));
LMDB_CHECK(mdb_del(txn, dbi_session, &_obj_id_rec, NULL));

View File

@ -110,12 +110,12 @@ static void create_record(int64_t record_id) {
event.obj_id = record_id;
event.event_type = 1;
MDB_val _session_id1_rec = {strlen(data.session_id1), data.session_id1};
MDB_val _session_id2_rec = {strlen(data.session_id2), data.session_id2};
MDB_val _ip_rec = {strlen(data.ip), data.ip};
MDB_val _obj_id_rec = {sizeof (record_id), &record_id};
MDB_val _data_rec = {offsetof(session_data_t, fill) + (rand() % sizeof (data.fill)), &data};
MDB_val _event_rec = {sizeof (event), &event};
MDB_val _session_id1_rec = {data.session_id1, strlen(data.session_id1)};
MDB_val _session_id2_rec = {data.session_id2, strlen(data.session_id2)};
MDB_val _ip_rec = {data.ip, strlen(data.ip)};
MDB_val _obj_id_rec = {&record_id, sizeof(record_id)};
MDB_val _data_rec = {&data, offsetof(session_data_t, fill) + (rand() % sizeof (data.fill))};
MDB_val _event_rec = {&event, sizeof(event)};
LMDB_CHECK(mdb_txn_begin(env, NULL, 0, &txn));
LMDB_CHECK(mdb_dbi_open(txn, "session", MDB_CREATE, &dbi_session));
@ -151,21 +151,21 @@ static void delete_record(int64_t record_id) {
LMDB_CHECK(mdb_dbi_open(txn, "event", MDB_CREATE, &dbi_event));
LMDB_CHECK(mdb_dbi_open(txn, "ip", MDB_CREATE, &dbi_ip));
// put data
MDB_val _obj_id_rec = {sizeof (record_id), &record_id};
MDB_val _obj_id_rec = {&record_id, sizeof(record_id)};
MDB_val _data_rec;
// get data
LMDB_CHECK(mdb_get(txn, dbi_session, &_obj_id_rec, &_data_rec));
session_data_t* data = (session_data_t*) _data_rec.mv_data;
MDB_val _session_id1_rec = {strlen(data->session_id1), data->session_id1};
MDB_val _session_id2_rec = {strlen(data->session_id2), data->session_id2};
MDB_val _ip_rec = {strlen(data->ip), data->ip};
MDB_val _session_id1_rec = {data->session_id1, strlen(data->session_id1)};
MDB_val _session_id2_rec = {data->session_id2, strlen(data->session_id2)};
MDB_val _ip_rec = {data->ip, strlen(data->ip)};
LMDB_CHECK(mdb_del(txn, dbi_session_id, &_session_id1_rec, NULL));
LMDB_CHECK(mdb_del(txn, dbi_session_id, &_session_id2_rec, NULL));
LMDB_CHECK(mdb_del(txn, dbi_ip, &_ip_rec, NULL));
event.obj_id = record_id;
event.event_type = 1;
MDB_val _event_rec = {sizeof (event), &event};
MDB_val _event_rec = {&event, sizeof(event)};
LMDB_CHECK(mdb_del(txn, dbi_event, &_event_rec, NULL));
LMDB_CHECK(mdb_del(txn, dbi_session, &_obj_id_rec, NULL));