mdbx: rework MDBX_val.

This commit is contained in:
Leo Yuriev 2017-05-23 21:05:54 +03:00
parent ac8e987346
commit 8c18622592
10 changed files with 525 additions and 525 deletions

54
mdbx.h
View File

@ -137,16 +137,14 @@ struct iovec {
#define HAVE_STRUCT_IOVEC
#endif /* HAVE_STRUCT_IOVEC */
typedef struct iovec MDB_val;
#define mv_size iov_len
#define mv_data iov_base
typedef struct iovec MDBX_val;
/* The maximum size of a data item.
* MDBX only store a 32 bit value for node sizes. */
#define MDBX_MAXDATASIZE INT32_MAX
/* 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 */
/* no environment directory */
@ -1079,8 +1077,8 @@ LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDB_dbi dbi, int del);
* possible errors are:
* - MDB_NOTFOUND - the key was not in the database.
* - MDBX_EINVAL - an invalid parameter was specified. */
LIBMDBX_API int mdbx_get(MDBX_txn *txn, MDB_dbi dbi, MDB_val *key,
MDB_val *data);
LIBMDBX_API int mdbx_get(MDBX_txn *txn, MDB_dbi dbi, MDBX_val *key,
MDBX_val *data);
/* 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.
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
* - MDBX_EINVAL - an invalid parameter was specified. */
LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDB_dbi dbi, MDB_val *key,
MDB_val *data, unsigned flags);
LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDB_dbi dbi, MDBX_val *key,
MDBX_val *data, unsigned flags);
/* 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:
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
* - MDBX_EINVAL - an invalid parameter was specified. */
LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDB_dbi dbi, MDB_val *key,
MDB_val *data);
LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDB_dbi dbi, MDBX_val *key,
MDBX_val *data);
/* Create a cursor handle.
*
@ -1238,8 +1236,8 @@ LIBMDBX_API MDB_dbi mdbx_cursor_dbi(MDB_cursor *cursor);
* possible errors are:
* - MDB_NOTFOUND - no matching key found.
* - MDBX_EINVAL - an invalid parameter was specified. */
LIBMDBX_API int mdbx_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
MDB_cursor_op op);
LIBMDBX_API int mdbx_cursor_get(MDB_cursor *cursor, MDBX_val *key,
MDBX_val *data, MDB_cursor_op op);
/* Store by cursor.
*
@ -1292,13 +1290,13 @@ LIBMDBX_API int mdbx_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
* - MDB_MULTIPLE
* Store multiple contiguous data elements in a single request. This flag
* 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
* first MDB_val must be the size of a single data element. The mv_data
* of the first MDB_val must point to the beginning of the array of
* contiguous data elements. The mv_size of the second MDB_val must be
* The data argument must be an array of two MDBX_vals. The iov_len of the
* first MDBX_val must be the size of a single data element. The iov_base
* of the first MDBX_val must point to the beginning of the array of
* 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
* 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
* 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.
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
* - MDBX_EINVAL - an invalid parameter was specified. */
LIBMDBX_API int mdbx_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
unsigned flags);
LIBMDBX_API int mdbx_cursor_put(MDB_cursor *cursor, MDBX_val *key,
MDBX_val *data, unsigned flags);
/* 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
*
* 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,
const MDB_val *b);
LIBMDBX_API int mdbx_cmp(MDBX_txn *txn, MDB_dbi dbi, const MDBX_val *a,
const MDBX_val *b);
/* 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
*
* 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,
const MDB_val *b);
LIBMDBX_API int mdbx_dcmp(MDBX_txn *txn, MDB_dbi dbi, const MDBX_val *a,
const MDBX_val *b);
/* 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. */
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);
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. */
LIBMDBX_API int mdbx_cursor_on_last(MDB_cursor *mc);
LIBMDBX_API int mdbx_replace(MDBX_txn *txn, MDB_dbi dbi, MDB_val *key,
MDB_val *new_data, MDB_val *old_data,
LIBMDBX_API int mdbx_replace(MDBX_txn *txn, MDB_dbi dbi, MDBX_val *key,
MDBX_val *new_data, MDBX_val *old_data,
unsigned flags);
/* Same as mdbx_get(), but:
* 1) if values_count is not NULL, then returns the count
* of multi-values/duplicates for a given key.
* 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,
MDB_val *data, int *values_count);
LIBMDBX_API int mdbx_get_ex(MDBX_txn *txn, MDB_dbi dbi, MDBX_val *key,
MDBX_val *data, int *values_count);
LIBMDBX_API int mdbx_is_dirty(const MDBX_txn *txn, const void *ptr);

View File

@ -349,7 +349,7 @@ typedef struct MDBX_lockinfo {
* The information here is mostly static/read-only. There is
* only a single copy of this record in the environment. */
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_dcmp; /* function for comparing data items */
} MDB_dbx;

File diff suppressed because it is too large Load Diff

View File

@ -301,44 +301,44 @@ static int pgvisitor(uint64_t pgno, unsigned pgnumber, void *ctx,
return gotsignal ? EINTR : MDB_SUCCESS;
}
typedef int(visitor)(const uint64_t record_number, const MDB_val *key,
const MDB_val *data);
typedef int(visitor)(const uint64_t record_number, const MDBX_val *key,
const MDBX_val *data);
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,
const MDB_val *data) {
static int handle_userdb(const uint64_t record_number, const MDBX_val *key,
const MDBX_val *data) {
(void)record_number;
(void)key;
(void)data;
return MDB_SUCCESS;
}
static int handle_freedb(const uint64_t record_number, const MDB_val *key,
const MDB_val *data) {
static int handle_freedb(const uint64_t record_number, const MDBX_val *key,
const MDBX_val *data) {
char *bad = "";
pgno_t pg, prev;
int i, number, span = 0;
pgno_t *iptr = data->mv_data;
txnid_t txnid = *(txnid_t *)key->mv_data;
pgno_t *iptr = data->iov_base;
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",
"key-size %" PRIiPTR "", key->mv_size);
"key-size %" PRIiPTR "", key->iov_len);
else if (txnid < 1 || txnid > envinfo.me_last_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 "",
data->mv_size);
data->iov_len);
else {
number = *iptr++;
if (number >= MDB_IDL_UM_MAX)
problem_add("entry", record_number, "wrong idl length", "%" PRIiPTR "",
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",
"%" PRIiPTR " != %" PRIuPTR "", (number + 1) * sizeof(pgno_t),
data->mv_size);
data->iov_len);
else {
freedb_pages += number;
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;
}
static int handle_maindb(const uint64_t record_number, const MDB_val *key,
const MDB_val *data) {
static int handle_maindb(const uint64_t record_number, const MDBX_val *key,
const MDBX_val *data) {
char *name;
int rc;
size_t i;
name = key->mv_data;
for (i = 0; i < key->mv_size; ++i) {
name = key->iov_base;
for (i = 0; i < key->iov_len; ++i) {
if (name[i] < ' ')
return handle_userdb(record_number, key, data);
}
name = malloc(key->mv_size + 1);
memcpy(name, key->mv_data, key->mv_size);
name[key->mv_size] = '\0';
name = malloc(key->iov_len + 1);
memcpy(name, key->iov_base, key->iov_len);
name[key->iov_len] = '\0';
userdb_count++;
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) {
MDB_cursor *mc;
MDBX_stat ms;
MDB_val key, data;
MDB_val prev_key, prev_data;
MDBX_val key, data;
MDBX_val prev_key, prev_data;
unsigned flags;
int rc, i;
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();
prev_key.mv_data = NULL;
prev_data.mv_size = 0;
prev_key.iov_base = NULL;
prev_data.iov_len = 0;
rc = mdbx_cursor_get(mc, &key, &data, MDB_FIRST);
while (rc == MDB_SUCCESS) {
if (gotsignal) {
@ -497,26 +497,26 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
goto bailout;
}
if (key.mv_size > maxkeysize) {
if (key.iov_len > maxkeysize) {
problem_add("entry", record_count, "key length exceeds max-key-size",
"%" PRIuPTR " > %u", key.mv_size, maxkeysize);
} else if ((flags & MDB_INTEGERKEY) && key.mv_size != sizeof(uint64_t) &&
key.mv_size != sizeof(uint32_t)) {
"%" PRIuPTR " > %u", key.iov_len, maxkeysize);
} else if ((flags & MDB_INTEGERKEY) && key.iov_len != sizeof(uint64_t) &&
key.iov_len != sizeof(uint32_t)) {
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) &&
data.mv_size != sizeof(uint32_t)) {
if ((flags & MDB_INTEGERDUP) && data.iov_len != sizeof(uint64_t) &&
data.iov_len != sizeof(uint32_t)) {
problem_add("entry", record_count, "wrong data length",
"%" PRIuPTR " != 4or8", data.mv_size);
"%" PRIuPTR " != 4or8", data.iov_len);
}
if (prev_key.mv_data) {
if ((flags & MDB_DUPFIXED) && prev_data.mv_size != data.mv_size) {
if (prev_key.iov_base) {
if ((flags & MDB_DUPFIXED) && prev_data.iov_len != data.iov_len) {
problem_add("entry", record_count, "different data length",
"%" PRIuPTR " != %" PRIuPTR "", prev_data.mv_size,
data.mv_size);
"%" PRIuPTR " != %" PRIuPTR "", prev_data.iov_len,
data.iov_len);
}
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) {
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))
print(" - fixed data-size %" PRIuPTR "\n", data.mv_size);
print(" - fixed data-size %" PRIuPTR "\n", data.iov_len);
}
if (handler) {
@ -547,8 +547,8 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
}
record_count++;
key_bytes += key.mv_size;
data_bytes += data.mv_size;
key_bytes += key.iov_len;
data_bytes += data.iov_len;
prev_key = key;
prev_data = data;

View File

@ -53,12 +53,12 @@ static void hex(unsigned char c) {
putchar(hexc[c & 0xf]);
}
static void text(MDB_val *v) {
static void text(MDBX_val *v) {
unsigned char *c, *end;
putchar(' ');
c = v->mv_data;
end = c + v->mv_size;
c = v->iov_base;
end = c + v->iov_len;
while (c < end) {
if (isprint(*c)) {
putchar(*c);
@ -71,12 +71,12 @@ static void text(MDB_val *v) {
putchar('\n');
}
static void byte(MDB_val *v) {
static void byte(MDBX_val *v) {
unsigned char *c, *end;
putchar(' ');
c = v->mv_data;
end = c + v->mv_size;
c = v->iov_base;
end = c + v->iov_len;
while (c < end) {
hex(*c++);
}
@ -87,7 +87,7 @@ static void byte(MDB_val *v) {
static int dumpit(MDBX_txn *txn, MDB_dbi dbi, char *name) {
MDB_cursor *mc;
MDBX_stat ms;
MDB_val key, data;
MDBX_val key, data;
MDBX_envinfo info;
unsigned int flags;
int rc, i;
@ -256,7 +256,7 @@ int main(int argc, char *argv[]) {
if (alldbs) {
MDB_cursor *cursor;
MDB_val key;
MDBX_val key;
int count = 0;
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) {
char *str;
MDB_dbi db2;
if (memchr(key.mv_data, '\0', key.mv_size))
if (memchr(key.iov_base, '\0', key.iov_len))
continue;
count++;
str = malloc(key.mv_size + 1);
memcpy(str, key.mv_data, key.mv_size);
str[key.mv_size] = '\0';
str = malloc(key.iov_len + 1);
memcpy(str, key.iov_base, key.iov_len);
str[key.iov_len] = '\0';
rc = mdbx_dbi_open(txn, str, 0, &db2);
if (rc == MDB_SUCCESS) {
if (list) {

View File

@ -39,7 +39,7 @@ static int Eof;
static MDBX_envinfo envinfo;
static MDB_val kbuf, dbuf;
static MDBX_val kbuf, dbuf;
#define STRLENOF(s) (sizeof(s) - 1)
@ -63,93 +63,94 @@ static void readhdr(void) {
char *ptr;
dbi_flags = 0;
while (fgets(dbuf.mv_data, dbuf.mv_size, stdin) != NULL) {
while (fgets(dbuf.iov_base, dbuf.iov_len, stdin) != NULL) {
lineno++;
if (!strncmp(dbuf.mv_data, "db_pagesize=", STRLENOF("db_pagesize=")) ||
!strncmp(dbuf.mv_data, "duplicates=", STRLENOF("duplicates="))) {
if (!strncmp(dbuf.iov_base, "db_pagesize=", STRLENOF("db_pagesize=")) ||
!strncmp(dbuf.iov_base, "duplicates=", STRLENOF("duplicates="))) {
/* LY: silently ignore information fields. */
continue;
} else if (!strncmp(dbuf.mv_data, "VERSION=", STRLENOF("VERSION="))) {
version = atoi((char *)dbuf.mv_data + STRLENOF("VERSION="));
} else if (!strncmp(dbuf.iov_base, "VERSION=", STRLENOF("VERSION="))) {
version = atoi((char *)dbuf.iov_base + STRLENOF("VERSION="));
if (version > 3) {
fprintf(stderr, "%s: line %" PRIiPTR ": unsupported VERSION %d\n", prog,
lineno, version);
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;
} else if (!strncmp(dbuf.mv_data, "format=", STRLENOF("format="))) {
if (!strncmp((char *)dbuf.mv_data + STRLENOF("FORMAT="), "print",
} else if (!strncmp(dbuf.iov_base, "format=", STRLENOF("format="))) {
if (!strncmp((char *)dbuf.iov_base + STRLENOF("FORMAT="), "print",
STRLENOF("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"))) {
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);
}
} else if (!strncmp(dbuf.mv_data, "database=", STRLENOF("database="))) {
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
} else if (!strncmp(dbuf.iov_base, "database=", STRLENOF("database="))) {
ptr = memchr(dbuf.iov_base, '\n', dbuf.iov_len);
if (ptr)
*ptr = '\0';
if (subname)
free(subname);
subname = strdup((char *)dbuf.mv_data + STRLENOF("database="));
} else if (!strncmp(dbuf.mv_data, "type=", STRLENOF("type="))) {
if (strncmp((char *)dbuf.mv_data + STRLENOF("type="), "btree",
subname = strdup((char *)dbuf.iov_base + STRLENOF("database="));
} else if (!strncmp(dbuf.iov_base, "type=", STRLENOF("type="))) {
if (strncmp((char *)dbuf.iov_base + STRLENOF("type="), "btree",
STRLENOF("btree"))) {
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);
}
} else if (!strncmp(dbuf.mv_data, "mapaddr=", STRLENOF("mapaddr="))) {
} else if (!strncmp(dbuf.iov_base, "mapaddr=", STRLENOF("mapaddr="))) {
int i;
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
ptr = memchr(dbuf.iov_base, '\n', dbuf.iov_len);
if (ptr)
*ptr = '\0';
i = sscanf((char *)dbuf.mv_data + STRLENOF("mapaddr="), "%p",
i = sscanf((char *)dbuf.iov_base + STRLENOF("mapaddr="), "%p",
&envinfo.me_mapaddr);
if (i != 1) {
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);
}
} else if (!strncmp(dbuf.mv_data, "mapsize=", STRLENOF("mapsize="))) {
} else if (!strncmp(dbuf.iov_base, "mapsize=", STRLENOF("mapsize="))) {
int i;
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
ptr = memchr(dbuf.iov_base, '\n', dbuf.iov_len);
if (ptr)
*ptr = '\0';
i = sscanf((char *)dbuf.mv_data + STRLENOF("mapsize="), "%" PRIu64 "",
i = sscanf((char *)dbuf.iov_base + STRLENOF("mapsize="), "%" PRIu64 "",
&envinfo.me_mapsize);
if (i != 1) {
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);
}
} else if (!strncmp(dbuf.mv_data, "maxreaders=", STRLENOF("maxreaders="))) {
} else if (!strncmp(dbuf.iov_base, "maxreaders=",
STRLENOF("maxreaders="))) {
int i;
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
ptr = memchr(dbuf.iov_base, '\n', dbuf.iov_len);
if (ptr)
*ptr = '\0';
i = sscanf((char *)dbuf.mv_data + STRLENOF("maxreaders="), "%u",
i = sscanf((char *)dbuf.iov_base + STRLENOF("maxreaders="), "%u",
&envinfo.me_maxreaders);
if (i != 1) {
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);
}
} else {
int i;
for (i = 0; dbflags[i].bit; i++) {
if (!strncmp(dbuf.mv_data, dbflags[i].name, dbflags[i].len) &&
((char *)dbuf.mv_data)[dbflags[i].len] == '=') {
if (((char *)dbuf.mv_data)[dbflags[i].len + 1] == '1')
if (!strncmp(dbuf.iov_base, dbflags[i].name, dbflags[i].len) &&
((char *)dbuf.iov_base)[dbflags[i].len] == '=') {
if (((char *)dbuf.iov_base)[dbflags[i].len + 1] == '1')
dbi_flags |= dbflags[i].bit;
break;
}
}
if (!dbflags[i].bit) {
ptr = memchr(dbuf.mv_data, '=', dbuf.mv_size);
ptr = memchr(dbuf.iov_base, '=', dbuf.iov_len);
if (!ptr) {
fprintf(stderr, "%s: line %" PRIiPTR ": unexpected format\n", prog,
lineno);
@ -158,7 +159,7 @@ static void readhdr(void) {
*ptr = '\0';
fprintf(stderr,
"%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;
}
static int readline(MDB_val *out, MDB_val *buf) {
static int readline(MDBX_val *out, MDBX_val *buf) {
unsigned char *c1, *c2, *end;
size_t len, l2;
int c;
@ -196,48 +197,48 @@ static int readline(MDB_val *out, MDB_val *buf) {
}
if (c != ' ') {
lineno++;
if (fgets(buf->mv_data, buf->mv_size, stdin) == NULL) {
if (fgets(buf->iov_base, buf->iov_len, stdin) == NULL) {
badend:
Eof = 1;
badend();
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;
goto badend;
}
}
if (fgets(buf->mv_data, buf->mv_size, stdin) == NULL) {
if (fgets(buf->iov_base, buf->iov_len, stdin) == NULL) {
Eof = 1;
return EOF;
}
lineno++;
c1 = buf->mv_data;
c1 = buf->iov_base;
len = strlen((char *)c1);
l2 = len;
/* Is buffer too short? */
while (c1[len - 1] != '\n') {
buf->mv_data = realloc(buf->mv_data, buf->mv_size * 2);
if (!buf->mv_data) {
buf->iov_base = realloc(buf->iov_base, buf->iov_len * 2);
if (!buf->iov_base) {
Eof = 1;
fprintf(stderr, "%s: line %" PRIiPTR ": out of memory, line too long\n",
prog, lineno);
return EOF;
}
c1 = buf->mv_data;
c1 = buf->iov_base;
c1 += l2;
if (fgets((char *)c1, buf->mv_size + 1, stdin) == NULL) {
if (fgets((char *)c1, buf->iov_len + 1, stdin) == NULL) {
Eof = 1;
badend();
return EOF;
}
buf->mv_size *= 2;
buf->iov_len *= 2;
len = strlen((char *)c1);
l2 += len;
}
c1 = c2 = buf->mv_data;
c1 = c2 = buf->iov_base;
len = l2;
c1[--len] = '\0';
end = c1 + len;
@ -279,8 +280,8 @@ static int readline(MDB_val *out, MDB_val *buf) {
c2 += 2;
}
}
c2 = out->mv_data = buf->mv_data;
out->mv_size = c1 - c2;
c2 = out->iov_base = buf->iov_base;
out->iov_len = c1 - c2;
return 0;
}
@ -345,8 +346,8 @@ int main(int argc, char *argv[]) {
if (optind != argc - 1)
usage();
dbuf.mv_size = 4096;
dbuf.mv_data = malloc(dbuf.mv_size);
dbuf.iov_len = 4096;
dbuf.iov_base = malloc(dbuf.iov_len);
if (!(mode & NOHDR))
readhdr();
@ -379,11 +380,11 @@ int main(int argc, char *argv[]) {
goto env_close;
}
kbuf.mv_size = mdbx_env_get_maxkeysize(env) * 2 + 2;
kbuf.mv_data = malloc(kbuf.mv_size);
kbuf.iov_len = mdbx_env_get_maxkeysize(env) * 2 + 2;
kbuf.iov_base = malloc(kbuf.iov_len);
while (!Eof) {
MDB_val key, data;
MDBX_val key, data;
int batch = 0;
rc = mdbx_txn_begin(env, NULL, 0, &txn);

View File

@ -158,7 +158,7 @@ int main(int argc, char *argv[]) {
if (freinfo) {
MDB_cursor *cursor;
MDB_val key, data;
MDBX_val key, data;
size_t pages = 0, *iptr;
size_t reclaimable = 0;
@ -178,9 +178,9 @@ int main(int argc, char *argv[]) {
}
prstat(&mst);
while ((rc = mdbx_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
iptr = data.mv_data;
iptr = data.iov_base;
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;
if (freinfo > 1) {
char *bad = "";
@ -198,7 +198,7 @@ int main(int argc, char *argv[]) {
}
printf(" Transaction %" PRIuPTR ", %" PRIiPTR
" pages, maxspan %" PRIiPTR "%s\n",
*(size_t *)key.mv_data, j, span, bad);
*(size_t *)key.iov_base, j, span, bad);
if (freinfo > 2) {
for (--j; j >= 0;) {
pg = iptr[j];
@ -262,7 +262,7 @@ int main(int argc, char *argv[]) {
if (alldbs) {
MDB_cursor *cursor;
MDB_val key;
MDBX_val key;
rc = mdbx_cursor_open(txn, dbi, &cursor);
if (rc) {
@ -273,11 +273,11 @@ int main(int argc, char *argv[]) {
while ((rc = mdbx_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
char *str;
MDB_dbi db2;
if (memchr(key.mv_data, '\0', key.mv_size))
if (memchr(key.iov_base, '\0', key.iov_len))
continue;
str = malloc(key.mv_size + 1);
memcpy(str, key.mv_data, key.mv_size);
str[key.mv_size] = '\0';
str = malloc(key.iov_len + 1);
memcpy(str, key.iov_base, key.iov_len);
str[key.iov_len] = '\0';
rc = mdbx_dbi_open(txn, str, 0, &db2);
if (rc == MDB_SUCCESS)
printf("Status of %s\n", str);

View File

@ -193,8 +193,8 @@ void __hot maker::mk(const serial_t serial, const essentials &params,
assert(params.maxlen >= params.minlen);
assert(params.maxlen >= length(serial));
out.value.mv_data = out.bytes;
out.value.mv_size = params.minlen;
out.value.iov_base = out.bytes;
out.value.iov_len = params.minlen;
if (params.flags & (MDB_INTEGERKEY | MDB_INTEGERDUP)) {
assert(params.maxlen == params.minlen);
@ -204,29 +204,29 @@ void __hot maker::mk(const serial_t serial, const essentials &params,
else
out.u32 = (uint32_t)serial;
} else if (params.flags & (MDB_REVERSEKEY | MDB_REVERSEDUP)) {
if (out.value.mv_size > 8) {
memset(out.bytes, '\0', out.value.mv_size - 8);
unaligned::store(out.bytes + out.value.mv_size - 8, htobe64(serial));
if (out.value.iov_len > 8) {
memset(out.bytes, '\0', out.value.iov_len - 8);
unaligned::store(out.bytes + out.value.iov_len - 8, htobe64(serial));
} else {
out.u64 = htobe64(serial);
if (out.value.mv_size < 8) {
out.value.mv_size = std::max(length(serial), out.value.mv_size);
out.value.mv_data = out.bytes + 8 - out.value.mv_size;
if (out.value.iov_len < 8) {
out.value.iov_len = std::max(length(serial), out.value.iov_len);
out.value.iov_base = out.bytes + 8 - out.value.iov_len;
}
}
} else {
out.u64 = htole64(serial);
if (out.value.mv_size > 8)
memset(out.bytes + 8, '\0', out.value.mv_size - 8);
if (out.value.iov_len > 8)
memset(out.bytes + 8, '\0', out.value.iov_len - 8);
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.mv_size <= params.maxlen);
assert(out.value.mv_size >= length(serial));
assert(out.value.mv_data >= out.bytes);
assert((uint8_t *)out.value.mv_data + out.value.mv_size <=
assert(out.value.iov_len >= params.minlen);
assert(out.value.iov_len <= params.maxlen);
assert(out.value.iov_len >= length(serial));
assert(out.value.iov_base >= out.bytes);
assert((uint8_t *)out.value.iov_base + out.value.iov_len <=
out.bytes + out.limit);
}

View File

@ -78,7 +78,7 @@ enum {
};
struct result {
MDB_val value;
MDBX_val value;
size_t limit;
union {
uint8_t bytes[sizeof(uint64_t)];

View File

@ -26,7 +26,7 @@ int main(int argc,char * argv[])
int rc;
MDB_env *env;
MDB_dbi dbi;
MDB_val key, data;
MDBX_val key, data;
MDBX_txn *txn;
MDB_cursor *cursor;
char sval[32];
@ -38,10 +38,10 @@ int main(int argc,char * argv[])
rc = mdbx_txn_begin(env, NULL, 0, &txn);
rc = mdbx_dbi_open(txn, NULL, 0, &dbi);
key.mv_size = sizeof(int);
key.mv_data = sval;
data.mv_size = sizeof(sval);
data.mv_data = sval;
key.iov_len = sizeof(int);
key.iov_base = sval;
data.iov_len = sizeof(sval);
data.iov_base = sval;
sprintf(sval, "%03x %d foo bar", 32, 3141592);
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);
while ((rc = mdbx_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data);
key.iov_base, (int) key.iov_len, (char *) key.iov_base,
data.iov_base, (int) data.iov_len, (char *) data.iov_base);
}
mdbx_cursor_close(cursor);
mdbx_txn_abort(txn);