mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-31 11:58:21 +08:00
mdbx: rework MDBX_val.
This commit is contained in:
parent
ac8e987346
commit
8c18622592
54
mdbx.h
54
mdbx.h
@ -137,16 +137,14 @@ struct iovec {
|
|||||||
#define HAVE_STRUCT_IOVEC
|
#define HAVE_STRUCT_IOVEC
|
||||||
#endif /* HAVE_STRUCT_IOVEC */
|
#endif /* HAVE_STRUCT_IOVEC */
|
||||||
|
|
||||||
typedef struct iovec MDB_val;
|
typedef struct iovec MDBX_val;
|
||||||
#define mv_size iov_len
|
|
||||||
#define mv_data iov_base
|
|
||||||
|
|
||||||
/* The maximum size of a data item.
|
/* The maximum size of a data item.
|
||||||
* MDBX only store a 32 bit value for node sizes. */
|
* MDBX only store a 32 bit value for node sizes. */
|
||||||
#define MDBX_MAXDATASIZE INT32_MAX
|
#define MDBX_MAXDATASIZE INT32_MAX
|
||||||
|
|
||||||
/* A callback function used to compare two keys in a database */
|
/* A callback function used to compare two keys in a database */
|
||||||
typedef int(MDB_cmp_func)(const MDB_val *a, const MDB_val *b);
|
typedef int(MDB_cmp_func)(const MDBX_val *a, const MDBX_val *b);
|
||||||
|
|
||||||
/* Environment Flags */
|
/* Environment Flags */
|
||||||
/* no environment directory */
|
/* no environment directory */
|
||||||
@ -1079,8 +1077,8 @@ LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDB_dbi dbi, int del);
|
|||||||
* possible errors are:
|
* possible errors are:
|
||||||
* - MDB_NOTFOUND - the key was not in the database.
|
* - MDB_NOTFOUND - the key was not in the database.
|
||||||
* - MDBX_EINVAL - an invalid parameter was specified. */
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
LIBMDBX_API int mdbx_get(MDBX_txn *txn, MDB_dbi dbi, MDB_val *key,
|
LIBMDBX_API int mdbx_get(MDBX_txn *txn, MDB_dbi dbi, MDBX_val *key,
|
||||||
MDB_val *data);
|
MDBX_val *data);
|
||||||
|
|
||||||
/* Store items into a database.
|
/* Store items into a database.
|
||||||
*
|
*
|
||||||
@ -1139,8 +1137,8 @@ LIBMDBX_API int mdbx_get(MDBX_txn *txn, MDB_dbi dbi, MDB_val *key,
|
|||||||
* - MDB_TXN_FULL - the transaction has too many dirty pages.
|
* - MDB_TXN_FULL - the transaction has too many dirty pages.
|
||||||
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
|
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
|
||||||
* - MDBX_EINVAL - an invalid parameter was specified. */
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDB_dbi dbi, MDB_val *key,
|
LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDB_dbi dbi, MDBX_val *key,
|
||||||
MDB_val *data, unsigned flags);
|
MDBX_val *data, unsigned flags);
|
||||||
|
|
||||||
/* Delete items from a database.
|
/* Delete items from a database.
|
||||||
*
|
*
|
||||||
@ -1162,8 +1160,8 @@ LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDB_dbi dbi, MDB_val *key,
|
|||||||
* possible errors are:
|
* possible errors are:
|
||||||
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
|
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
|
||||||
* - MDBX_EINVAL - an invalid parameter was specified. */
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDB_dbi dbi, MDB_val *key,
|
LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDB_dbi dbi, MDBX_val *key,
|
||||||
MDB_val *data);
|
MDBX_val *data);
|
||||||
|
|
||||||
/* Create a cursor handle.
|
/* Create a cursor handle.
|
||||||
*
|
*
|
||||||
@ -1238,8 +1236,8 @@ LIBMDBX_API MDB_dbi mdbx_cursor_dbi(MDB_cursor *cursor);
|
|||||||
* possible errors are:
|
* possible errors are:
|
||||||
* - MDB_NOTFOUND - no matching key found.
|
* - MDB_NOTFOUND - no matching key found.
|
||||||
* - MDBX_EINVAL - an invalid parameter was specified. */
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
LIBMDBX_API int mdbx_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
|
LIBMDBX_API int mdbx_cursor_get(MDB_cursor *cursor, MDBX_val *key,
|
||||||
MDB_cursor_op op);
|
MDBX_val *data, MDB_cursor_op op);
|
||||||
|
|
||||||
/* Store by cursor.
|
/* Store by cursor.
|
||||||
*
|
*
|
||||||
@ -1292,13 +1290,13 @@ LIBMDBX_API int mdbx_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
|
|||||||
* - MDB_MULTIPLE
|
* - MDB_MULTIPLE
|
||||||
* Store multiple contiguous data elements in a single request. This flag
|
* Store multiple contiguous data elements in a single request. This flag
|
||||||
* may only be specified if the database was opened with MDB_DUPFIXED.
|
* may only be specified if the database was opened with MDB_DUPFIXED.
|
||||||
* The data argument must be an array of two MDB_vals. The mv_size of the
|
* The data argument must be an array of two MDBX_vals. The iov_len of the
|
||||||
* first MDB_val must be the size of a single data element. The mv_data
|
* first MDBX_val must be the size of a single data element. The iov_base
|
||||||
* of the first MDB_val must point to the beginning of the array of
|
* of the first MDBX_val must point to the beginning of the array of
|
||||||
* contiguous data elements. The mv_size of the second MDB_val must be
|
* contiguous data elements. The iov_len of the second MDBX_val must be
|
||||||
* the count of the number of data elements to store. On return this
|
* the count of the number of data elements to store. On return this
|
||||||
* field will be set to the count of the number of elements actually
|
* field will be set to the count of the number of elements actually
|
||||||
* written. The mv_data of the second MDB_val is unused.
|
* written. The iov_base of the second MDBX_val is unused.
|
||||||
*
|
*
|
||||||
* Returns A non-zero error value on failure and 0 on success, some
|
* Returns A non-zero error value on failure and 0 on success, some
|
||||||
* possible errors are:
|
* possible errors are:
|
||||||
@ -1307,8 +1305,8 @@ LIBMDBX_API int mdbx_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
|
|||||||
* - MDB_TXN_FULL - the transaction has too many dirty pages.
|
* - MDB_TXN_FULL - the transaction has too many dirty pages.
|
||||||
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
|
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
|
||||||
* - MDBX_EINVAL - an invalid parameter was specified. */
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
LIBMDBX_API int mdbx_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
|
LIBMDBX_API int mdbx_cursor_put(MDB_cursor *cursor, MDBX_val *key,
|
||||||
unsigned flags);
|
MDBX_val *data, unsigned flags);
|
||||||
|
|
||||||
/* Delete current key/data pair
|
/* Delete current key/data pair
|
||||||
*
|
*
|
||||||
@ -1353,8 +1351,8 @@ LIBMDBX_API int mdbx_cursor_count(MDB_cursor *cursor, uint64_t *countp);
|
|||||||
* [in] b The second item to compare
|
* [in] b The second item to compare
|
||||||
*
|
*
|
||||||
* Returns < 0 if a < b, 0 if a == b, > 0 if a > b */
|
* Returns < 0 if a < b, 0 if a == b, > 0 if a > b */
|
||||||
LIBMDBX_API int mdbx_cmp(MDBX_txn *txn, MDB_dbi dbi, const MDB_val *a,
|
LIBMDBX_API int mdbx_cmp(MDBX_txn *txn, MDB_dbi dbi, const MDBX_val *a,
|
||||||
const MDB_val *b);
|
const MDBX_val *b);
|
||||||
|
|
||||||
/* Compare two data items according to a particular database.
|
/* Compare two data items according to a particular database.
|
||||||
*
|
*
|
||||||
@ -1367,8 +1365,8 @@ LIBMDBX_API int mdbx_cmp(MDBX_txn *txn, MDB_dbi dbi, const MDB_val *a,
|
|||||||
* [in] b The second item to compare
|
* [in] b The second item to compare
|
||||||
*
|
*
|
||||||
* Returns < 0 if a < b, 0 if a == b, > 0 if a > b */
|
* Returns < 0 if a < b, 0 if a == b, > 0 if a > b */
|
||||||
LIBMDBX_API int mdbx_dcmp(MDBX_txn *txn, MDB_dbi dbi, const MDB_val *a,
|
LIBMDBX_API int mdbx_dcmp(MDBX_txn *txn, MDB_dbi dbi, const MDBX_val *a,
|
||||||
const MDB_val *b);
|
const MDBX_val *b);
|
||||||
|
|
||||||
/* A callback function used to print a message from the library.
|
/* A callback function used to print a message from the library.
|
||||||
*
|
*
|
||||||
@ -1395,7 +1393,7 @@ LIBMDBX_API int mdbx_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx);
|
|||||||
* Returns 0 on success, non-zero on failure. */
|
* Returns 0 on success, non-zero on failure. */
|
||||||
LIBMDBX_API int mdbx_reader_check(MDB_env *env, int *dead);
|
LIBMDBX_API int mdbx_reader_check(MDB_env *env, int *dead);
|
||||||
|
|
||||||
LIBMDBX_API char *mdbx_dkey(const MDB_val *key, char *const buf,
|
LIBMDBX_API char *mdbx_dkey(const MDBX_val *key, char *const buf,
|
||||||
const size_t bufsize);
|
const size_t bufsize);
|
||||||
|
|
||||||
LIBMDBX_API int mdbx_env_close_ex(MDB_env *env, int dont_sync);
|
LIBMDBX_API int mdbx_env_close_ex(MDB_env *env, int dont_sync);
|
||||||
@ -1509,15 +1507,15 @@ LIBMDBX_API int mdbx_cursor_on_first(MDB_cursor *mc);
|
|||||||
/* Returns: MDBX_RESULT_TRUE, MDBX_RESULT_FALSE or Error code. */
|
/* Returns: MDBX_RESULT_TRUE, MDBX_RESULT_FALSE or Error code. */
|
||||||
LIBMDBX_API int mdbx_cursor_on_last(MDB_cursor *mc);
|
LIBMDBX_API int mdbx_cursor_on_last(MDB_cursor *mc);
|
||||||
|
|
||||||
LIBMDBX_API int mdbx_replace(MDBX_txn *txn, MDB_dbi dbi, MDB_val *key,
|
LIBMDBX_API int mdbx_replace(MDBX_txn *txn, MDB_dbi dbi, MDBX_val *key,
|
||||||
MDB_val *new_data, MDB_val *old_data,
|
MDBX_val *new_data, MDBX_val *old_data,
|
||||||
unsigned flags);
|
unsigned flags);
|
||||||
/* Same as mdbx_get(), but:
|
/* Same as mdbx_get(), but:
|
||||||
* 1) if values_count is not NULL, then returns the count
|
* 1) if values_count is not NULL, then returns the count
|
||||||
* of multi-values/duplicates for a given key.
|
* of multi-values/duplicates for a given key.
|
||||||
* 2) updates the key for pointing to the actual key's data inside DB. */
|
* 2) updates the key for pointing to the actual key's data inside DB. */
|
||||||
LIBMDBX_API int mdbx_get_ex(MDBX_txn *txn, MDB_dbi dbi, MDB_val *key,
|
LIBMDBX_API int mdbx_get_ex(MDBX_txn *txn, MDB_dbi dbi, MDBX_val *key,
|
||||||
MDB_val *data, int *values_count);
|
MDBX_val *data, int *values_count);
|
||||||
|
|
||||||
LIBMDBX_API int mdbx_is_dirty(const MDBX_txn *txn, const void *ptr);
|
LIBMDBX_API int mdbx_is_dirty(const MDBX_txn *txn, const void *ptr);
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ typedef struct MDBX_lockinfo {
|
|||||||
* The information here is mostly static/read-only. There is
|
* The information here is mostly static/read-only. There is
|
||||||
* only a single copy of this record in the environment. */
|
* only a single copy of this record in the environment. */
|
||||||
typedef struct MDB_dbx {
|
typedef struct MDB_dbx {
|
||||||
MDB_val md_name; /* name of the database */
|
MDBX_val md_name; /* name of the database */
|
||||||
MDB_cmp_func *md_cmp; /* function for comparing keys */
|
MDB_cmp_func *md_cmp; /* function for comparing keys */
|
||||||
MDB_cmp_func *md_dcmp; /* function for comparing data items */
|
MDB_cmp_func *md_dcmp; /* function for comparing data items */
|
||||||
} MDB_dbx;
|
} MDB_dbx;
|
||||||
|
715
src/mdbx.c
715
src/mdbx.c
File diff suppressed because it is too large
Load Diff
@ -301,44 +301,44 @@ static int pgvisitor(uint64_t pgno, unsigned pgnumber, void *ctx,
|
|||||||
return gotsignal ? EINTR : MDB_SUCCESS;
|
return gotsignal ? EINTR : MDB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef int(visitor)(const uint64_t record_number, const MDB_val *key,
|
typedef int(visitor)(const uint64_t record_number, const MDBX_val *key,
|
||||||
const MDB_val *data);
|
const MDBX_val *data);
|
||||||
static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent);
|
static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent);
|
||||||
|
|
||||||
static int handle_userdb(const uint64_t record_number, const MDB_val *key,
|
static int handle_userdb(const uint64_t record_number, const MDBX_val *key,
|
||||||
const MDB_val *data) {
|
const MDBX_val *data) {
|
||||||
(void)record_number;
|
(void)record_number;
|
||||||
(void)key;
|
(void)key;
|
||||||
(void)data;
|
(void)data;
|
||||||
return MDB_SUCCESS;
|
return MDB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_freedb(const uint64_t record_number, const MDB_val *key,
|
static int handle_freedb(const uint64_t record_number, const MDBX_val *key,
|
||||||
const MDB_val *data) {
|
const MDBX_val *data) {
|
||||||
char *bad = "";
|
char *bad = "";
|
||||||
pgno_t pg, prev;
|
pgno_t pg, prev;
|
||||||
int i, number, span = 0;
|
int i, number, span = 0;
|
||||||
pgno_t *iptr = data->mv_data;
|
pgno_t *iptr = data->iov_base;
|
||||||
txnid_t txnid = *(txnid_t *)key->mv_data;
|
txnid_t txnid = *(txnid_t *)key->iov_base;
|
||||||
|
|
||||||
if (key->mv_size != sizeof(txnid_t))
|
if (key->iov_len != sizeof(txnid_t))
|
||||||
problem_add("entry", record_number, "wrong txn-id size",
|
problem_add("entry", record_number, "wrong txn-id size",
|
||||||
"key-size %" PRIiPTR "", key->mv_size);
|
"key-size %" PRIiPTR "", key->iov_len);
|
||||||
else if (txnid < 1 || txnid > envinfo.me_last_txnid)
|
else if (txnid < 1 || txnid > envinfo.me_last_txnid)
|
||||||
problem_add("entry", record_number, "wrong txn-id", "%" PRIaTXN "", txnid);
|
problem_add("entry", record_number, "wrong txn-id", "%" PRIaTXN "", txnid);
|
||||||
|
|
||||||
if (data->mv_size < sizeof(pgno_t) || data->mv_size % sizeof(pgno_t))
|
if (data->iov_len < sizeof(pgno_t) || data->iov_len % sizeof(pgno_t))
|
||||||
problem_add("entry", record_number, "wrong idl size", "%" PRIuPTR "",
|
problem_add("entry", record_number, "wrong idl size", "%" PRIuPTR "",
|
||||||
data->mv_size);
|
data->iov_len);
|
||||||
else {
|
else {
|
||||||
number = *iptr++;
|
number = *iptr++;
|
||||||
if (number >= MDB_IDL_UM_MAX)
|
if (number >= MDB_IDL_UM_MAX)
|
||||||
problem_add("entry", record_number, "wrong idl length", "%" PRIiPTR "",
|
problem_add("entry", record_number, "wrong idl length", "%" PRIiPTR "",
|
||||||
number);
|
number);
|
||||||
else if ((number + 1) * sizeof(pgno_t) != data->mv_size)
|
else if ((number + 1) * sizeof(pgno_t) != data->iov_len)
|
||||||
problem_add("entry", record_number, "mismatch idl length",
|
problem_add("entry", record_number, "mismatch idl length",
|
||||||
"%" PRIiPTR " != %" PRIuPTR "", (number + 1) * sizeof(pgno_t),
|
"%" PRIiPTR " != %" PRIuPTR "", (number + 1) * sizeof(pgno_t),
|
||||||
data->mv_size);
|
data->iov_len);
|
||||||
else {
|
else {
|
||||||
freedb_pages += number;
|
freedb_pages += number;
|
||||||
if (envinfo.me_tail_txnid > txnid)
|
if (envinfo.me_tail_txnid > txnid)
|
||||||
@ -381,21 +381,21 @@ static int handle_freedb(const uint64_t record_number, const MDB_val *key,
|
|||||||
return MDB_SUCCESS;
|
return MDB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_maindb(const uint64_t record_number, const MDB_val *key,
|
static int handle_maindb(const uint64_t record_number, const MDBX_val *key,
|
||||||
const MDB_val *data) {
|
const MDBX_val *data) {
|
||||||
char *name;
|
char *name;
|
||||||
int rc;
|
int rc;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
name = key->mv_data;
|
name = key->iov_base;
|
||||||
for (i = 0; i < key->mv_size; ++i) {
|
for (i = 0; i < key->iov_len; ++i) {
|
||||||
if (name[i] < ' ')
|
if (name[i] < ' ')
|
||||||
return handle_userdb(record_number, key, data);
|
return handle_userdb(record_number, key, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
name = malloc(key->mv_size + 1);
|
name = malloc(key->iov_len + 1);
|
||||||
memcpy(name, key->mv_data, key->mv_size);
|
memcpy(name, key->iov_base, key->iov_len);
|
||||||
name[key->mv_size] = '\0';
|
name[key->iov_len] = '\0';
|
||||||
userdb_count++;
|
userdb_count++;
|
||||||
|
|
||||||
rc = process_db(-1, name, handle_userdb, 0);
|
rc = process_db(-1, name, handle_userdb, 0);
|
||||||
@ -409,8 +409,8 @@ static int handle_maindb(const uint64_t record_number, const MDB_val *key,
|
|||||||
static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
||||||
MDB_cursor *mc;
|
MDB_cursor *mc;
|
||||||
MDBX_stat ms;
|
MDBX_stat ms;
|
||||||
MDB_val key, data;
|
MDBX_val key, data;
|
||||||
MDB_val prev_key, prev_data;
|
MDBX_val prev_key, prev_data;
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
int rc, i;
|
int rc, i;
|
||||||
struct problem *saved_list;
|
struct problem *saved_list;
|
||||||
@ -486,8 +486,8 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
saved_list = problems_push();
|
saved_list = problems_push();
|
||||||
prev_key.mv_data = NULL;
|
prev_key.iov_base = NULL;
|
||||||
prev_data.mv_size = 0;
|
prev_data.iov_len = 0;
|
||||||
rc = mdbx_cursor_get(mc, &key, &data, MDB_FIRST);
|
rc = mdbx_cursor_get(mc, &key, &data, MDB_FIRST);
|
||||||
while (rc == MDB_SUCCESS) {
|
while (rc == MDB_SUCCESS) {
|
||||||
if (gotsignal) {
|
if (gotsignal) {
|
||||||
@ -497,26 +497,26 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
|||||||
goto bailout;
|
goto bailout;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.mv_size > maxkeysize) {
|
if (key.iov_len > maxkeysize) {
|
||||||
problem_add("entry", record_count, "key length exceeds max-key-size",
|
problem_add("entry", record_count, "key length exceeds max-key-size",
|
||||||
"%" PRIuPTR " > %u", key.mv_size, maxkeysize);
|
"%" PRIuPTR " > %u", key.iov_len, maxkeysize);
|
||||||
} else if ((flags & MDB_INTEGERKEY) && key.mv_size != sizeof(uint64_t) &&
|
} else if ((flags & MDB_INTEGERKEY) && key.iov_len != sizeof(uint64_t) &&
|
||||||
key.mv_size != sizeof(uint32_t)) {
|
key.iov_len != sizeof(uint32_t)) {
|
||||||
problem_add("entry", record_count, "wrong key length",
|
problem_add("entry", record_count, "wrong key length",
|
||||||
"%" PRIuPTR " != 4or8", key.mv_size);
|
"%" PRIuPTR " != 4or8", key.iov_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & MDB_INTEGERDUP) && data.mv_size != sizeof(uint64_t) &&
|
if ((flags & MDB_INTEGERDUP) && data.iov_len != sizeof(uint64_t) &&
|
||||||
data.mv_size != sizeof(uint32_t)) {
|
data.iov_len != sizeof(uint32_t)) {
|
||||||
problem_add("entry", record_count, "wrong data length",
|
problem_add("entry", record_count, "wrong data length",
|
||||||
"%" PRIuPTR " != 4or8", data.mv_size);
|
"%" PRIuPTR " != 4or8", data.iov_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prev_key.mv_data) {
|
if (prev_key.iov_base) {
|
||||||
if ((flags & MDB_DUPFIXED) && prev_data.mv_size != data.mv_size) {
|
if ((flags & MDB_DUPFIXED) && prev_data.iov_len != data.iov_len) {
|
||||||
problem_add("entry", record_count, "different data length",
|
problem_add("entry", record_count, "different data length",
|
||||||
"%" PRIuPTR " != %" PRIuPTR "", prev_data.mv_size,
|
"%" PRIuPTR " != %" PRIuPTR "", prev_data.iov_len,
|
||||||
data.mv_size);
|
data.iov_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmp = mdbx_cmp(txn, dbi, &prev_key, &key);
|
int cmp = mdbx_cmp(txn, dbi, &prev_key, &key);
|
||||||
@ -535,9 +535,9 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
|||||||
}
|
}
|
||||||
} else if (verbose) {
|
} else if (verbose) {
|
||||||
if (flags & MDB_INTEGERKEY)
|
if (flags & MDB_INTEGERKEY)
|
||||||
print(" - fixed key-size %" PRIuPTR "\n", key.mv_size);
|
print(" - fixed key-size %" PRIuPTR "\n", key.iov_len);
|
||||||
if (flags & (MDB_INTEGERDUP | MDB_DUPFIXED))
|
if (flags & (MDB_INTEGERDUP | MDB_DUPFIXED))
|
||||||
print(" - fixed data-size %" PRIuPTR "\n", data.mv_size);
|
print(" - fixed data-size %" PRIuPTR "\n", data.iov_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handler) {
|
if (handler) {
|
||||||
@ -547,8 +547,8 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
record_count++;
|
record_count++;
|
||||||
key_bytes += key.mv_size;
|
key_bytes += key.iov_len;
|
||||||
data_bytes += data.mv_size;
|
data_bytes += data.iov_len;
|
||||||
|
|
||||||
prev_key = key;
|
prev_key = key;
|
||||||
prev_data = data;
|
prev_data = data;
|
||||||
|
@ -53,12 +53,12 @@ static void hex(unsigned char c) {
|
|||||||
putchar(hexc[c & 0xf]);
|
putchar(hexc[c & 0xf]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void text(MDB_val *v) {
|
static void text(MDBX_val *v) {
|
||||||
unsigned char *c, *end;
|
unsigned char *c, *end;
|
||||||
|
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
c = v->mv_data;
|
c = v->iov_base;
|
||||||
end = c + v->mv_size;
|
end = c + v->iov_len;
|
||||||
while (c < end) {
|
while (c < end) {
|
||||||
if (isprint(*c)) {
|
if (isprint(*c)) {
|
||||||
putchar(*c);
|
putchar(*c);
|
||||||
@ -71,12 +71,12 @@ static void text(MDB_val *v) {
|
|||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
static void byte(MDB_val *v) {
|
static void byte(MDBX_val *v) {
|
||||||
unsigned char *c, *end;
|
unsigned char *c, *end;
|
||||||
|
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
c = v->mv_data;
|
c = v->iov_base;
|
||||||
end = c + v->mv_size;
|
end = c + v->iov_len;
|
||||||
while (c < end) {
|
while (c < end) {
|
||||||
hex(*c++);
|
hex(*c++);
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ static void byte(MDB_val *v) {
|
|||||||
static int dumpit(MDBX_txn *txn, MDB_dbi dbi, char *name) {
|
static int dumpit(MDBX_txn *txn, MDB_dbi dbi, char *name) {
|
||||||
MDB_cursor *mc;
|
MDB_cursor *mc;
|
||||||
MDBX_stat ms;
|
MDBX_stat ms;
|
||||||
MDB_val key, data;
|
MDBX_val key, data;
|
||||||
MDBX_envinfo info;
|
MDBX_envinfo info;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
int rc, i;
|
int rc, i;
|
||||||
@ -256,7 +256,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
if (alldbs) {
|
if (alldbs) {
|
||||||
MDB_cursor *cursor;
|
MDB_cursor *cursor;
|
||||||
MDB_val key;
|
MDBX_val key;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
rc = mdbx_cursor_open(txn, dbi, &cursor);
|
rc = mdbx_cursor_open(txn, dbi, &cursor);
|
||||||
@ -268,12 +268,12 @@ int main(int argc, char *argv[]) {
|
|||||||
while ((rc = mdbx_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
|
while ((rc = mdbx_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
|
||||||
char *str;
|
char *str;
|
||||||
MDB_dbi db2;
|
MDB_dbi db2;
|
||||||
if (memchr(key.mv_data, '\0', key.mv_size))
|
if (memchr(key.iov_base, '\0', key.iov_len))
|
||||||
continue;
|
continue;
|
||||||
count++;
|
count++;
|
||||||
str = malloc(key.mv_size + 1);
|
str = malloc(key.iov_len + 1);
|
||||||
memcpy(str, key.mv_data, key.mv_size);
|
memcpy(str, key.iov_base, key.iov_len);
|
||||||
str[key.mv_size] = '\0';
|
str[key.iov_len] = '\0';
|
||||||
rc = mdbx_dbi_open(txn, str, 0, &db2);
|
rc = mdbx_dbi_open(txn, str, 0, &db2);
|
||||||
if (rc == MDB_SUCCESS) {
|
if (rc == MDB_SUCCESS) {
|
||||||
if (list) {
|
if (list) {
|
||||||
|
@ -39,7 +39,7 @@ static int Eof;
|
|||||||
|
|
||||||
static MDBX_envinfo envinfo;
|
static MDBX_envinfo envinfo;
|
||||||
|
|
||||||
static MDB_val kbuf, dbuf;
|
static MDBX_val kbuf, dbuf;
|
||||||
|
|
||||||
#define STRLENOF(s) (sizeof(s) - 1)
|
#define STRLENOF(s) (sizeof(s) - 1)
|
||||||
|
|
||||||
@ -63,93 +63,94 @@ static void readhdr(void) {
|
|||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
dbi_flags = 0;
|
dbi_flags = 0;
|
||||||
while (fgets(dbuf.mv_data, dbuf.mv_size, stdin) != NULL) {
|
while (fgets(dbuf.iov_base, dbuf.iov_len, stdin) != NULL) {
|
||||||
lineno++;
|
lineno++;
|
||||||
if (!strncmp(dbuf.mv_data, "db_pagesize=", STRLENOF("db_pagesize=")) ||
|
if (!strncmp(dbuf.iov_base, "db_pagesize=", STRLENOF("db_pagesize=")) ||
|
||||||
!strncmp(dbuf.mv_data, "duplicates=", STRLENOF("duplicates="))) {
|
!strncmp(dbuf.iov_base, "duplicates=", STRLENOF("duplicates="))) {
|
||||||
/* LY: silently ignore information fields. */
|
/* LY: silently ignore information fields. */
|
||||||
continue;
|
continue;
|
||||||
} else if (!strncmp(dbuf.mv_data, "VERSION=", STRLENOF("VERSION="))) {
|
} else if (!strncmp(dbuf.iov_base, "VERSION=", STRLENOF("VERSION="))) {
|
||||||
version = atoi((char *)dbuf.mv_data + STRLENOF("VERSION="));
|
version = atoi((char *)dbuf.iov_base + STRLENOF("VERSION="));
|
||||||
if (version > 3) {
|
if (version > 3) {
|
||||||
fprintf(stderr, "%s: line %" PRIiPTR ": unsupported VERSION %d\n", prog,
|
fprintf(stderr, "%s: line %" PRIiPTR ": unsupported VERSION %d\n", prog,
|
||||||
lineno, version);
|
lineno, version);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
} else if (!strncmp(dbuf.mv_data, "HEADER=END", STRLENOF("HEADER=END"))) {
|
} else if (!strncmp(dbuf.iov_base, "HEADER=END", STRLENOF("HEADER=END"))) {
|
||||||
break;
|
break;
|
||||||
} else if (!strncmp(dbuf.mv_data, "format=", STRLENOF("format="))) {
|
} else if (!strncmp(dbuf.iov_base, "format=", STRLENOF("format="))) {
|
||||||
if (!strncmp((char *)dbuf.mv_data + STRLENOF("FORMAT="), "print",
|
if (!strncmp((char *)dbuf.iov_base + STRLENOF("FORMAT="), "print",
|
||||||
STRLENOF("print")))
|
STRLENOF("print")))
|
||||||
mode |= PRINT;
|
mode |= PRINT;
|
||||||
else if (strncmp((char *)dbuf.mv_data + STRLENOF("FORMAT="), "bytevalue",
|
else if (strncmp((char *)dbuf.iov_base + STRLENOF("FORMAT="), "bytevalue",
|
||||||
STRLENOF("bytevalue"))) {
|
STRLENOF("bytevalue"))) {
|
||||||
fprintf(stderr, "%s: line %" PRIiPTR ": unsupported FORMAT %s\n", prog,
|
fprintf(stderr, "%s: line %" PRIiPTR ": unsupported FORMAT %s\n", prog,
|
||||||
lineno, (char *)dbuf.mv_data + STRLENOF("FORMAT="));
|
lineno, (char *)dbuf.iov_base + STRLENOF("FORMAT="));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
} else if (!strncmp(dbuf.mv_data, "database=", STRLENOF("database="))) {
|
} else if (!strncmp(dbuf.iov_base, "database=", STRLENOF("database="))) {
|
||||||
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
|
ptr = memchr(dbuf.iov_base, '\n', dbuf.iov_len);
|
||||||
if (ptr)
|
if (ptr)
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
if (subname)
|
if (subname)
|
||||||
free(subname);
|
free(subname);
|
||||||
subname = strdup((char *)dbuf.mv_data + STRLENOF("database="));
|
subname = strdup((char *)dbuf.iov_base + STRLENOF("database="));
|
||||||
} else if (!strncmp(dbuf.mv_data, "type=", STRLENOF("type="))) {
|
} else if (!strncmp(dbuf.iov_base, "type=", STRLENOF("type="))) {
|
||||||
if (strncmp((char *)dbuf.mv_data + STRLENOF("type="), "btree",
|
if (strncmp((char *)dbuf.iov_base + STRLENOF("type="), "btree",
|
||||||
STRLENOF("btree"))) {
|
STRLENOF("btree"))) {
|
||||||
fprintf(stderr, "%s: line %" PRIiPTR ": unsupported type %s\n", prog,
|
fprintf(stderr, "%s: line %" PRIiPTR ": unsupported type %s\n", prog,
|
||||||
lineno, (char *)dbuf.mv_data + STRLENOF("type="));
|
lineno, (char *)dbuf.iov_base + STRLENOF("type="));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
} else if (!strncmp(dbuf.mv_data, "mapaddr=", STRLENOF("mapaddr="))) {
|
} else if (!strncmp(dbuf.iov_base, "mapaddr=", STRLENOF("mapaddr="))) {
|
||||||
int i;
|
int i;
|
||||||
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
|
ptr = memchr(dbuf.iov_base, '\n', dbuf.iov_len);
|
||||||
if (ptr)
|
if (ptr)
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
i = sscanf((char *)dbuf.mv_data + STRLENOF("mapaddr="), "%p",
|
i = sscanf((char *)dbuf.iov_base + STRLENOF("mapaddr="), "%p",
|
||||||
&envinfo.me_mapaddr);
|
&envinfo.me_mapaddr);
|
||||||
if (i != 1) {
|
if (i != 1) {
|
||||||
fprintf(stderr, "%s: line %" PRIiPTR ": invalid mapaddr %s\n", prog,
|
fprintf(stderr, "%s: line %" PRIiPTR ": invalid mapaddr %s\n", prog,
|
||||||
lineno, (char *)dbuf.mv_data + STRLENOF("mapaddr="));
|
lineno, (char *)dbuf.iov_base + STRLENOF("mapaddr="));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
} else if (!strncmp(dbuf.mv_data, "mapsize=", STRLENOF("mapsize="))) {
|
} else if (!strncmp(dbuf.iov_base, "mapsize=", STRLENOF("mapsize="))) {
|
||||||
int i;
|
int i;
|
||||||
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
|
ptr = memchr(dbuf.iov_base, '\n', dbuf.iov_len);
|
||||||
if (ptr)
|
if (ptr)
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
i = sscanf((char *)dbuf.mv_data + STRLENOF("mapsize="), "%" PRIu64 "",
|
i = sscanf((char *)dbuf.iov_base + STRLENOF("mapsize="), "%" PRIu64 "",
|
||||||
&envinfo.me_mapsize);
|
&envinfo.me_mapsize);
|
||||||
if (i != 1) {
|
if (i != 1) {
|
||||||
fprintf(stderr, "%s: line %" PRIiPTR ": invalid mapsize %s\n", prog,
|
fprintf(stderr, "%s: line %" PRIiPTR ": invalid mapsize %s\n", prog,
|
||||||
lineno, (char *)dbuf.mv_data + STRLENOF("mapsize="));
|
lineno, (char *)dbuf.iov_base + STRLENOF("mapsize="));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
} else if (!strncmp(dbuf.mv_data, "maxreaders=", STRLENOF("maxreaders="))) {
|
} else if (!strncmp(dbuf.iov_base, "maxreaders=",
|
||||||
|
STRLENOF("maxreaders="))) {
|
||||||
int i;
|
int i;
|
||||||
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
|
ptr = memchr(dbuf.iov_base, '\n', dbuf.iov_len);
|
||||||
if (ptr)
|
if (ptr)
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
i = sscanf((char *)dbuf.mv_data + STRLENOF("maxreaders="), "%u",
|
i = sscanf((char *)dbuf.iov_base + STRLENOF("maxreaders="), "%u",
|
||||||
&envinfo.me_maxreaders);
|
&envinfo.me_maxreaders);
|
||||||
if (i != 1) {
|
if (i != 1) {
|
||||||
fprintf(stderr, "%s: line %" PRIiPTR ": invalid maxreaders %s\n", prog,
|
fprintf(stderr, "%s: line %" PRIiPTR ": invalid maxreaders %s\n", prog,
|
||||||
lineno, (char *)dbuf.mv_data + STRLENOF("maxreaders="));
|
lineno, (char *)dbuf.iov_base + STRLENOF("maxreaders="));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; dbflags[i].bit; i++) {
|
for (i = 0; dbflags[i].bit; i++) {
|
||||||
if (!strncmp(dbuf.mv_data, dbflags[i].name, dbflags[i].len) &&
|
if (!strncmp(dbuf.iov_base, dbflags[i].name, dbflags[i].len) &&
|
||||||
((char *)dbuf.mv_data)[dbflags[i].len] == '=') {
|
((char *)dbuf.iov_base)[dbflags[i].len] == '=') {
|
||||||
if (((char *)dbuf.mv_data)[dbflags[i].len + 1] == '1')
|
if (((char *)dbuf.iov_base)[dbflags[i].len + 1] == '1')
|
||||||
dbi_flags |= dbflags[i].bit;
|
dbi_flags |= dbflags[i].bit;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!dbflags[i].bit) {
|
if (!dbflags[i].bit) {
|
||||||
ptr = memchr(dbuf.mv_data, '=', dbuf.mv_size);
|
ptr = memchr(dbuf.iov_base, '=', dbuf.iov_len);
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
fprintf(stderr, "%s: line %" PRIiPTR ": unexpected format\n", prog,
|
fprintf(stderr, "%s: line %" PRIiPTR ": unexpected format\n", prog,
|
||||||
lineno);
|
lineno);
|
||||||
@ -158,7 +159,7 @@ static void readhdr(void) {
|
|||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s: line %" PRIiPTR ": unrecognized keyword ignored: %s\n",
|
"%s: line %" PRIiPTR ": unrecognized keyword ignored: %s\n",
|
||||||
prog, lineno, (char *)dbuf.mv_data);
|
prog, lineno, (char *)dbuf.iov_base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,7 +184,7 @@ static int unhex(unsigned char *c2) {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int readline(MDB_val *out, MDB_val *buf) {
|
static int readline(MDBX_val *out, MDBX_val *buf) {
|
||||||
unsigned char *c1, *c2, *end;
|
unsigned char *c1, *c2, *end;
|
||||||
size_t len, l2;
|
size_t len, l2;
|
||||||
int c;
|
int c;
|
||||||
@ -196,48 +197,48 @@ static int readline(MDB_val *out, MDB_val *buf) {
|
|||||||
}
|
}
|
||||||
if (c != ' ') {
|
if (c != ' ') {
|
||||||
lineno++;
|
lineno++;
|
||||||
if (fgets(buf->mv_data, buf->mv_size, stdin) == NULL) {
|
if (fgets(buf->iov_base, buf->iov_len, stdin) == NULL) {
|
||||||
badend:
|
badend:
|
||||||
Eof = 1;
|
Eof = 1;
|
||||||
badend();
|
badend();
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
if (c == 'D' && !strncmp(buf->mv_data, "ATA=END", STRLENOF("ATA=END")))
|
if (c == 'D' && !strncmp(buf->iov_base, "ATA=END", STRLENOF("ATA=END")))
|
||||||
return EOF;
|
return EOF;
|
||||||
goto badend;
|
goto badend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fgets(buf->mv_data, buf->mv_size, stdin) == NULL) {
|
if (fgets(buf->iov_base, buf->iov_len, stdin) == NULL) {
|
||||||
Eof = 1;
|
Eof = 1;
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
lineno++;
|
lineno++;
|
||||||
|
|
||||||
c1 = buf->mv_data;
|
c1 = buf->iov_base;
|
||||||
len = strlen((char *)c1);
|
len = strlen((char *)c1);
|
||||||
l2 = len;
|
l2 = len;
|
||||||
|
|
||||||
/* Is buffer too short? */
|
/* Is buffer too short? */
|
||||||
while (c1[len - 1] != '\n') {
|
while (c1[len - 1] != '\n') {
|
||||||
buf->mv_data = realloc(buf->mv_data, buf->mv_size * 2);
|
buf->iov_base = realloc(buf->iov_base, buf->iov_len * 2);
|
||||||
if (!buf->mv_data) {
|
if (!buf->iov_base) {
|
||||||
Eof = 1;
|
Eof = 1;
|
||||||
fprintf(stderr, "%s: line %" PRIiPTR ": out of memory, line too long\n",
|
fprintf(stderr, "%s: line %" PRIiPTR ": out of memory, line too long\n",
|
||||||
prog, lineno);
|
prog, lineno);
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
c1 = buf->mv_data;
|
c1 = buf->iov_base;
|
||||||
c1 += l2;
|
c1 += l2;
|
||||||
if (fgets((char *)c1, buf->mv_size + 1, stdin) == NULL) {
|
if (fgets((char *)c1, buf->iov_len + 1, stdin) == NULL) {
|
||||||
Eof = 1;
|
Eof = 1;
|
||||||
badend();
|
badend();
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
buf->mv_size *= 2;
|
buf->iov_len *= 2;
|
||||||
len = strlen((char *)c1);
|
len = strlen((char *)c1);
|
||||||
l2 += len;
|
l2 += len;
|
||||||
}
|
}
|
||||||
c1 = c2 = buf->mv_data;
|
c1 = c2 = buf->iov_base;
|
||||||
len = l2;
|
len = l2;
|
||||||
c1[--len] = '\0';
|
c1[--len] = '\0';
|
||||||
end = c1 + len;
|
end = c1 + len;
|
||||||
@ -279,8 +280,8 @@ static int readline(MDB_val *out, MDB_val *buf) {
|
|||||||
c2 += 2;
|
c2 += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c2 = out->mv_data = buf->mv_data;
|
c2 = out->iov_base = buf->iov_base;
|
||||||
out->mv_size = c1 - c2;
|
out->iov_len = c1 - c2;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -345,8 +346,8 @@ int main(int argc, char *argv[]) {
|
|||||||
if (optind != argc - 1)
|
if (optind != argc - 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
dbuf.mv_size = 4096;
|
dbuf.iov_len = 4096;
|
||||||
dbuf.mv_data = malloc(dbuf.mv_size);
|
dbuf.iov_base = malloc(dbuf.iov_len);
|
||||||
|
|
||||||
if (!(mode & NOHDR))
|
if (!(mode & NOHDR))
|
||||||
readhdr();
|
readhdr();
|
||||||
@ -379,11 +380,11 @@ int main(int argc, char *argv[]) {
|
|||||||
goto env_close;
|
goto env_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
kbuf.mv_size = mdbx_env_get_maxkeysize(env) * 2 + 2;
|
kbuf.iov_len = mdbx_env_get_maxkeysize(env) * 2 + 2;
|
||||||
kbuf.mv_data = malloc(kbuf.mv_size);
|
kbuf.iov_base = malloc(kbuf.iov_len);
|
||||||
|
|
||||||
while (!Eof) {
|
while (!Eof) {
|
||||||
MDB_val key, data;
|
MDBX_val key, data;
|
||||||
int batch = 0;
|
int batch = 0;
|
||||||
|
|
||||||
rc = mdbx_txn_begin(env, NULL, 0, &txn);
|
rc = mdbx_txn_begin(env, NULL, 0, &txn);
|
||||||
|
@ -158,7 +158,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
if (freinfo) {
|
if (freinfo) {
|
||||||
MDB_cursor *cursor;
|
MDB_cursor *cursor;
|
||||||
MDB_val key, data;
|
MDBX_val key, data;
|
||||||
size_t pages = 0, *iptr;
|
size_t pages = 0, *iptr;
|
||||||
size_t reclaimable = 0;
|
size_t reclaimable = 0;
|
||||||
|
|
||||||
@ -178,9 +178,9 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
prstat(&mst);
|
prstat(&mst);
|
||||||
while ((rc = mdbx_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
|
while ((rc = mdbx_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
|
||||||
iptr = data.mv_data;
|
iptr = data.iov_base;
|
||||||
pages += *iptr;
|
pages += *iptr;
|
||||||
if (envinfo && mei.me_tail_txnid > *(size_t *)key.mv_data)
|
if (envinfo && mei.me_tail_txnid > *(size_t *)key.iov_base)
|
||||||
reclaimable += *iptr;
|
reclaimable += *iptr;
|
||||||
if (freinfo > 1) {
|
if (freinfo > 1) {
|
||||||
char *bad = "";
|
char *bad = "";
|
||||||
@ -198,7 +198,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
printf(" Transaction %" PRIuPTR ", %" PRIiPTR
|
printf(" Transaction %" PRIuPTR ", %" PRIiPTR
|
||||||
" pages, maxspan %" PRIiPTR "%s\n",
|
" pages, maxspan %" PRIiPTR "%s\n",
|
||||||
*(size_t *)key.mv_data, j, span, bad);
|
*(size_t *)key.iov_base, j, span, bad);
|
||||||
if (freinfo > 2) {
|
if (freinfo > 2) {
|
||||||
for (--j; j >= 0;) {
|
for (--j; j >= 0;) {
|
||||||
pg = iptr[j];
|
pg = iptr[j];
|
||||||
@ -262,7 +262,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
if (alldbs) {
|
if (alldbs) {
|
||||||
MDB_cursor *cursor;
|
MDB_cursor *cursor;
|
||||||
MDB_val key;
|
MDBX_val key;
|
||||||
|
|
||||||
rc = mdbx_cursor_open(txn, dbi, &cursor);
|
rc = mdbx_cursor_open(txn, dbi, &cursor);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
@ -273,11 +273,11 @@ int main(int argc, char *argv[]) {
|
|||||||
while ((rc = mdbx_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
|
while ((rc = mdbx_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
|
||||||
char *str;
|
char *str;
|
||||||
MDB_dbi db2;
|
MDB_dbi db2;
|
||||||
if (memchr(key.mv_data, '\0', key.mv_size))
|
if (memchr(key.iov_base, '\0', key.iov_len))
|
||||||
continue;
|
continue;
|
||||||
str = malloc(key.mv_size + 1);
|
str = malloc(key.iov_len + 1);
|
||||||
memcpy(str, key.mv_data, key.mv_size);
|
memcpy(str, key.iov_base, key.iov_len);
|
||||||
str[key.mv_size] = '\0';
|
str[key.iov_len] = '\0';
|
||||||
rc = mdbx_dbi_open(txn, str, 0, &db2);
|
rc = mdbx_dbi_open(txn, str, 0, &db2);
|
||||||
if (rc == MDB_SUCCESS)
|
if (rc == MDB_SUCCESS)
|
||||||
printf("Status of %s\n", str);
|
printf("Status of %s\n", str);
|
||||||
|
@ -193,8 +193,8 @@ void __hot maker::mk(const serial_t serial, const essentials ¶ms,
|
|||||||
assert(params.maxlen >= params.minlen);
|
assert(params.maxlen >= params.minlen);
|
||||||
assert(params.maxlen >= length(serial));
|
assert(params.maxlen >= length(serial));
|
||||||
|
|
||||||
out.value.mv_data = out.bytes;
|
out.value.iov_base = out.bytes;
|
||||||
out.value.mv_size = params.minlen;
|
out.value.iov_len = params.minlen;
|
||||||
|
|
||||||
if (params.flags & (MDB_INTEGERKEY | MDB_INTEGERDUP)) {
|
if (params.flags & (MDB_INTEGERKEY | MDB_INTEGERDUP)) {
|
||||||
assert(params.maxlen == params.minlen);
|
assert(params.maxlen == params.minlen);
|
||||||
@ -204,29 +204,29 @@ void __hot maker::mk(const serial_t serial, const essentials ¶ms,
|
|||||||
else
|
else
|
||||||
out.u32 = (uint32_t)serial;
|
out.u32 = (uint32_t)serial;
|
||||||
} else if (params.flags & (MDB_REVERSEKEY | MDB_REVERSEDUP)) {
|
} else if (params.flags & (MDB_REVERSEKEY | MDB_REVERSEDUP)) {
|
||||||
if (out.value.mv_size > 8) {
|
if (out.value.iov_len > 8) {
|
||||||
memset(out.bytes, '\0', out.value.mv_size - 8);
|
memset(out.bytes, '\0', out.value.iov_len - 8);
|
||||||
unaligned::store(out.bytes + out.value.mv_size - 8, htobe64(serial));
|
unaligned::store(out.bytes + out.value.iov_len - 8, htobe64(serial));
|
||||||
} else {
|
} else {
|
||||||
out.u64 = htobe64(serial);
|
out.u64 = htobe64(serial);
|
||||||
if (out.value.mv_size < 8) {
|
if (out.value.iov_len < 8) {
|
||||||
out.value.mv_size = std::max(length(serial), out.value.mv_size);
|
out.value.iov_len = std::max(length(serial), out.value.iov_len);
|
||||||
out.value.mv_data = out.bytes + 8 - out.value.mv_size;
|
out.value.iov_base = out.bytes + 8 - out.value.iov_len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out.u64 = htole64(serial);
|
out.u64 = htole64(serial);
|
||||||
if (out.value.mv_size > 8)
|
if (out.value.iov_len > 8)
|
||||||
memset(out.bytes + 8, '\0', out.value.mv_size - 8);
|
memset(out.bytes + 8, '\0', out.value.iov_len - 8);
|
||||||
else
|
else
|
||||||
out.value.mv_size = std::max(length(serial), out.value.mv_size);
|
out.value.iov_len = std::max(length(serial), out.value.iov_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(out.value.mv_size >= params.minlen);
|
assert(out.value.iov_len >= params.minlen);
|
||||||
assert(out.value.mv_size <= params.maxlen);
|
assert(out.value.iov_len <= params.maxlen);
|
||||||
assert(out.value.mv_size >= length(serial));
|
assert(out.value.iov_len >= length(serial));
|
||||||
assert(out.value.mv_data >= out.bytes);
|
assert(out.value.iov_base >= out.bytes);
|
||||||
assert((uint8_t *)out.value.mv_data + out.value.mv_size <=
|
assert((uint8_t *)out.value.iov_base + out.value.iov_len <=
|
||||||
out.bytes + out.limit);
|
out.bytes + out.limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct result {
|
struct result {
|
||||||
MDB_val value;
|
MDBX_val value;
|
||||||
size_t limit;
|
size_t limit;
|
||||||
union {
|
union {
|
||||||
uint8_t bytes[sizeof(uint64_t)];
|
uint8_t bytes[sizeof(uint64_t)];
|
||||||
|
@ -26,7 +26,7 @@ int main(int argc,char * argv[])
|
|||||||
int rc;
|
int rc;
|
||||||
MDB_env *env;
|
MDB_env *env;
|
||||||
MDB_dbi dbi;
|
MDB_dbi dbi;
|
||||||
MDB_val key, data;
|
MDBX_val key, data;
|
||||||
MDBX_txn *txn;
|
MDBX_txn *txn;
|
||||||
MDB_cursor *cursor;
|
MDB_cursor *cursor;
|
||||||
char sval[32];
|
char sval[32];
|
||||||
@ -38,10 +38,10 @@ int main(int argc,char * argv[])
|
|||||||
rc = mdbx_txn_begin(env, NULL, 0, &txn);
|
rc = mdbx_txn_begin(env, NULL, 0, &txn);
|
||||||
rc = mdbx_dbi_open(txn, NULL, 0, &dbi);
|
rc = mdbx_dbi_open(txn, NULL, 0, &dbi);
|
||||||
|
|
||||||
key.mv_size = sizeof(int);
|
key.iov_len = sizeof(int);
|
||||||
key.mv_data = sval;
|
key.iov_base = sval;
|
||||||
data.mv_size = sizeof(sval);
|
data.iov_len = sizeof(sval);
|
||||||
data.mv_data = sval;
|
data.iov_base = sval;
|
||||||
|
|
||||||
sprintf(sval, "%03x %d foo bar", 32, 3141592);
|
sprintf(sval, "%03x %d foo bar", 32, 3141592);
|
||||||
rc = mdbx_put(txn, dbi, &key, &data, 0);
|
rc = mdbx_put(txn, dbi, &key, &data, 0);
|
||||||
@ -54,8 +54,8 @@ int main(int argc,char * argv[])
|
|||||||
rc = mdbx_cursor_open(txn, dbi, &cursor);
|
rc = mdbx_cursor_open(txn, dbi, &cursor);
|
||||||
while ((rc = mdbx_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
|
while ((rc = mdbx_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
|
||||||
printf("key: %p %.*s, data: %p %.*s\n",
|
printf("key: %p %.*s, data: %p %.*s\n",
|
||||||
key.mv_data, (int) key.mv_size, (char *) key.mv_data,
|
key.iov_base, (int) key.iov_len, (char *) key.iov_base,
|
||||||
data.mv_data, (int) data.mv_size, (char *) data.mv_data);
|
data.iov_base, (int) data.iov_len, (char *) data.iov_base);
|
||||||
}
|
}
|
||||||
mdbx_cursor_close(cursor);
|
mdbx_cursor_close(cursor);
|
||||||
mdbx_txn_abort(txn);
|
mdbx_txn_abort(txn);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user