From f8338770838b4393fd8e7b827872eff28484ae8c Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Sun, 27 Mar 2016 04:25:31 +0300 Subject: [PATCH] mdbx: MDB_val as struct iovec. Change-Id: I08d9dcabaf88564b367bc2752e596ebea0e7cbf9 --- lmdb.h | 10 ++++++++++ yota_test1.c | 22 +++++++++++----------- yota_test2.c | 22 +++++++++++----------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/lmdb.h b/lmdb.h index 41ee45f3..57fb3111 100644 --- a/lmdb.h +++ b/lmdb.h @@ -170,6 +170,10 @@ #include #include #include +#if MDBX_MODE_ENABLED +# include +# include +#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); diff --git a/yota_test1.c b/yota_test1.c index f2ed5a23..e324ba4e 100644 --- a/yota_test1.c +++ b/yota_test1.c @@ -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)); diff --git a/yota_test2.c b/yota_test2.c index 3e9681c6..3672073a 100644 --- a/yota_test2.c +++ b/yota_test2.c @@ -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));