Resync to upstream mdb.master

This commit is contained in:
Howard Chu 2019-01-17 19:25:31 +00:00
parent 6bc0c7e685
commit efec3ed235
No known key found for this signature in database
GPG Key ID: FD2A70B44AB11BA7
27 changed files with 1081 additions and 843 deletions

View File

@ -5,6 +5,7 @@ mdb_copy
mdb_stat mdb_stat
mdb_dump mdb_dump
mdb_load mdb_load
mdb_drop
*.lo *.lo
*.[ao] *.[ao]
*.so *.so

View File

@ -1,4 +1,4 @@
Copyright 2011-2015 Howard Chu, Symas Corp. Copyright 2011-2019 Howard Chu, Symas Corp.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View File

@ -253,7 +253,7 @@ IDL_PROPERTY_SUPPORT = YES
# member in the group (if any) for the other members of the group. By default # member in the group (if any) for the other members of the group. By default
# all members of a group must be documented explicitly. # all members of a group must be documented explicitly.
DISTRIBUTE_GROUP_DOC = NO DISTRIBUTE_GROUP_DOC = YES
# Set the SUBGROUPING tag to YES (the default) to allow class member groups of # Set the SUBGROUPING tag to YES (the default) to allow class member groups of
# the same type (for instance a group of public functions) to be put as a # the same type (for instance a group of public functions) to be put as a

View File

@ -26,6 +26,7 @@ OPT = -O2 -g
CFLAGS = $(THREADS) $(OPT) $(W) $(XCFLAGS) CFLAGS = $(THREADS) $(OPT) $(W) $(XCFLAGS)
LDLIBS = LDLIBS =
SOLIBS = SOLIBS =
SOEXT = .so
prefix = /usr/local prefix = /usr/local
exec_prefix = $(prefix) exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin bindir = $(exec_prefix)/bin
@ -37,7 +38,7 @@ mandir = $(datarootdir)/man
######################################################################## ########################################################################
IHDRS = lmdb.h IHDRS = lmdb.h
ILIBS = liblmdb.a liblmdb.so ILIBS = liblmdb.a liblmdb$(SOEXT)
IPROGS = mdb_stat mdb_copy mdb_dump mdb_load mdb_drop IPROGS = mdb_stat mdb_copy mdb_dump mdb_load mdb_drop
IDOCS = mdb_stat.1 mdb_copy.1 mdb_dump.1 mdb_load.1 mdb_drop.1 IDOCS = mdb_stat.1 mdb_copy.1 mdb_dump.1 mdb_load.1 mdb_drop.1
PROGS = $(IPROGS) mtest mtest2 mtest3 mtest4 mtest5 PROGS = $(IPROGS) mtest mtest2 mtest3 mtest4 mtest5
@ -63,7 +64,7 @@ test: all
liblmdb.a: mdb.o midl.o liblmdb.a: mdb.o midl.o
$(AR) rs $@ mdb.o midl.o $(AR) rs $@ mdb.o midl.o
liblmdb.so: mdb.lo midl.lo liblmdb$(SOEXT): mdb.lo midl.lo
# $(CC) $(LDFLAGS) -pthread -shared -Wl,-Bsymbolic -o $@ mdb.o midl.o $(SOLIBS) # $(CC) $(LDFLAGS) -pthread -shared -Wl,-Bsymbolic -o $@ mdb.o midl.o $(SOLIBS)
$(CC) $(LDFLAGS) -pthread -shared -o $@ mdb.lo midl.lo $(SOLIBS) $(CC) $(LDFLAGS) -pthread -shared -o $@ mdb.lo midl.lo $(SOLIBS)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2015 Howard Chu, Symas Corp. * Copyright 2015-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -97,11 +97,12 @@
* transactions. Each transaction belongs to one thread. See below. * transactions. Each transaction belongs to one thread. See below.
* The #MDB_NOTLS flag changes this for read-only transactions. * The #MDB_NOTLS flag changes this for read-only transactions.
* *
* - Use an MDB_env* in the process which opened it, without fork()ing. * - Use an MDB_env* in the process which opened it, not after fork().
* *
* - Do not have open an LMDB database twice in the same process at * - Do not have open an LMDB database twice in the same process at
* the same time. Not even from a plain open() call - close()ing it * the same time. Not even from a plain open() call - close()ing it
* breaks flock() advisory locking. * breaks fcntl() advisory locking. (It is OK to reopen it after
* fork() - exec*(), since the lockfile has FD_CLOEXEC set.)
* *
* - Avoid long-lived transactions. Read transactions prevent * - Avoid long-lived transactions. Read transactions prevent
* reuse of pages freed by newer write transactions, thus the * reuse of pages freed by newer write transactions, thus the
@ -135,7 +136,7 @@
* *
* @author Howard Chu, Symas Corporation. * @author Howard Chu, Symas Corporation.
* *
* @copyright Copyright 2011-2016 Howard Chu, Symas Corp. All rights reserved. * @copyright Copyright 2011-2019 Howard Chu, Symas Corp. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP * modification, are permitted only as authorized by the OpenLDAP
@ -167,6 +168,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <inttypes.h> #include <inttypes.h>
#include <limits.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -179,11 +181,30 @@ typedef int mdb_mode_t;
typedef mode_t mdb_mode_t; typedef mode_t mdb_mode_t;
#endif #endif
#ifdef MDB_VL32 #ifdef _WIN32
typedef uint64_t mdb_size_t; # define MDB_FMT_Z "I"
#define mdb_env_create mdb_env_create_vl32 /**< Prevent mixing with non-VL32 builds */
#else #else
# define MDB_FMT_Z "z" /**< printf/scanf format modifier for size_t */
#endif
#ifndef MDB_VL32
/** Unsigned type used for mapsize, entry counts and page/transaction IDs.
*
* It is normally size_t, hence the name. Defining MDB_VL32 makes it
* uint64_t, but do not try this unless you know what you are doing.
*/
typedef size_t mdb_size_t; typedef size_t mdb_size_t;
# define MDB_SIZE_MAX SIZE_MAX /**< max #mdb_size_t */
/** #mdb_size_t printf formats, \b t = one of [diouxX] without quotes */
# define MDB_PRIy(t) MDB_FMT_Z #t
/** #mdb_size_t scanf formats, \b t = one of [dioux] without quotes */
# define MDB_SCNy(t) MDB_FMT_Z #t
#else
typedef uint64_t mdb_size_t;
# define MDB_SIZE_MAX UINT64_MAX
# define MDB_PRIy(t) PRI##t##64
# define MDB_SCNy(t) SCN##t##64
# define mdb_env_create mdb_env_create_vl32 /**< Prevent mixing with non-VL32 builds */
#endif #endif
/** An abstraction for a file handle. /** An abstraction for a file handle.
@ -322,7 +343,8 @@ typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *rel
#define MDB_REVERSEKEY 0x02 #define MDB_REVERSEKEY 0x02
/** use sorted duplicates */ /** use sorted duplicates */
#define MDB_DUPSORT 0x04 #define MDB_DUPSORT 0x04
/** numeric keys in native byte order: either unsigned int or size_t. /** numeric keys in native byte order, either unsigned int or #mdb_size_t.
* (lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)
* The keys must all be of the same size. */ * The keys must all be of the same size. */
#define MDB_INTEGERKEY 0x08 #define MDB_INTEGERKEY 0x08
/** with #MDB_DUPSORT, sorted dup items have fixed size */ /** with #MDB_DUPSORT, sorted dup items have fixed size */
@ -380,7 +402,7 @@ typedef enum MDB_cursor_op {
MDB_GET_BOTH, /**< Position at key/data pair. Only for #MDB_DUPSORT */ MDB_GET_BOTH, /**< Position at key/data pair. Only for #MDB_DUPSORT */
MDB_GET_BOTH_RANGE, /**< position at key, nearest data. Only for #MDB_DUPSORT */ MDB_GET_BOTH_RANGE, /**< position at key, nearest data. Only for #MDB_DUPSORT */
MDB_GET_CURRENT, /**< Return key/data at current cursor position */ MDB_GET_CURRENT, /**< Return key/data at current cursor position */
MDB_GET_MULTIPLE, /**< Return key and up to a page of duplicate data items MDB_GET_MULTIPLE, /**< Return up to a page of duplicate data items
from current cursor position. Move cursor to prepare from current cursor position. Move cursor to prepare
for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED */ for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED */
MDB_LAST, /**< Position at last key/data item */ MDB_LAST, /**< Position at last key/data item */
@ -389,7 +411,7 @@ typedef enum MDB_cursor_op {
MDB_NEXT, /**< Position at next data item */ MDB_NEXT, /**< Position at next data item */
MDB_NEXT_DUP, /**< Position at next data item of current key. MDB_NEXT_DUP, /**< Position at next data item of current key.
Only for #MDB_DUPSORT */ Only for #MDB_DUPSORT */
MDB_NEXT_MULTIPLE, /**< Return key and up to a page of duplicate data items MDB_NEXT_MULTIPLE, /**< Return up to a page of duplicate data items
from next cursor position. Move cursor to prepare from next cursor position. Move cursor to prepare
for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED */ for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED */
MDB_NEXT_NODUP, /**< Position at first data item of next key */ MDB_NEXT_NODUP, /**< Position at first data item of next key */
@ -400,7 +422,7 @@ typedef enum MDB_cursor_op {
MDB_SET, /**< Position at specified key */ MDB_SET, /**< Position at specified key */
MDB_SET_KEY, /**< Position at specified key, return key + data */ MDB_SET_KEY, /**< Position at specified key, return key + data */
MDB_SET_RANGE, /**< Position at first key greater than or equal to specified key. */ MDB_SET_RANGE, /**< Position at first key greater than or equal to specified key. */
MDB_PREV_MULTIPLE /**< Position at previous page and return key and up to MDB_PREV_MULTIPLE /**< Position at previous page and return up to
a page of duplicate data items. Only for #MDB_DUPFIXED */ a page of duplicate data items. Only for #MDB_DUPFIXED */
} MDB_cursor_op; } MDB_cursor_op;
@ -458,8 +480,10 @@ typedef enum MDB_cursor_op {
#define MDB_BAD_VALSIZE (-30781) #define MDB_BAD_VALSIZE (-30781)
/** The specified DBI was changed unexpectedly */ /** The specified DBI was changed unexpectedly */
#define MDB_BAD_DBI (-30780) #define MDB_BAD_DBI (-30780)
/** Unexpected problem - txn should abort */
#define MDB_PROBLEM (-30779)
/** The last defined error code */ /** The last defined error code */
#define MDB_LAST_ERRCODE MDB_BAD_DBI #define MDB_LAST_ERRCODE MDB_PROBLEM
/** @} */ /** @} */
/** @brief Statistics for a database in the environment */ /** @brief Statistics for a database in the environment */
@ -696,6 +720,7 @@ int mdb_env_copyfd(MDB_env *env, mdb_filehandle_t fd);
* <li>#MDB_CP_COMPACT - Perform compaction while copying: omit free * <li>#MDB_CP_COMPACT - Perform compaction while copying: omit free
* pages and sequentially renumber all pages in output. This option * pages and sequentially renumber all pages in output. This option
* consumes more CPU and runs more slowly than the default. * consumes more CPU and runs more slowly than the default.
* Currently it fails if the environment has suffered a page leak.
* </ul> * </ul>
* @return A non-zero error value on failure and 0 on success. * @return A non-zero error value on failure and 0 on success.
*/ */
@ -810,6 +835,10 @@ int mdb_env_get_flags(MDB_env *env, unsigned int *flags);
int mdb_env_get_path(MDB_env *env, const char **path); int mdb_env_get_path(MDB_env *env, const char **path);
/** @brief Return the filedescriptor for the given environment. /** @brief Return the filedescriptor for the given environment.
*
* This function may be called after fork(), so the descriptor can be
* closed before exec*(). Other LMDB file descriptors have FD_CLOEXEC.
* (Until LMDB 0.9.18, only the lockfile had that.)
* *
* @param[in] env An environment handle returned by #mdb_env_create() * @param[in] env An environment handle returned by #mdb_env_create()
* @param[out] fd Address of a mdb_filehandle_t to contain the descriptor. * @param[out] fd Address of a mdb_filehandle_t to contain the descriptor.
@ -1112,14 +1141,16 @@ int mdb_txn_renew(MDB_txn *txn);
* keys must be unique and may have only a single data item. * keys must be unique and may have only a single data item.
* <li>#MDB_INTEGERKEY * <li>#MDB_INTEGERKEY
* Keys are binary integers in native byte order, either unsigned int * Keys are binary integers in native byte order, either unsigned int
* or size_t, and will be sorted as such. * or #mdb_size_t, and will be sorted as such.
* (lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)
* The keys must all be of the same size. * The keys must all be of the same size.
* <li>#MDB_DUPFIXED * <li>#MDB_DUPFIXED
* This flag may only be used in combination with #MDB_DUPSORT. This option * This flag may only be used in combination with #MDB_DUPSORT. This option
* tells the library that the data items for this database are all the same * tells the library that the data items for this database are all the same
* size, which allows further optimizations in storage and retrieval. When * size, which allows further optimizations in storage and retrieval. When
* all data items are the same size, the #MDB_GET_MULTIPLE and #MDB_NEXT_MULTIPLE * all data items are the same size, the #MDB_GET_MULTIPLE, #MDB_NEXT_MULTIPLE
* cursor operations may be used to retrieve multiple items at once. * and #MDB_PREV_MULTIPLE cursor operations may be used to retrieve multiple
* items at once.
* <li>#MDB_INTEGERDUP * <li>#MDB_INTEGERDUP
* This option specifies that duplicate data items are binary integers, * This option specifies that duplicate data items are binary integers,
* similar to #MDB_INTEGERKEY keys. * similar to #MDB_INTEGERKEY keys.
@ -1524,6 +1555,10 @@ int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
/** @brief Delete current key/data pair /** @brief Delete current key/data pair
* *
* This function deletes the key/data pair to which the cursor refers. * This function deletes the key/data pair to which the cursor refers.
* This does not invalidate the cursor, so operations such as MDB_NEXT
* can still be used on it.
* Both MDB_NEXT and MDB_GET_CURRENT will return the same record after
* this operation.
* @param[in] cursor A cursor handle returned by #mdb_cursor_open() * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
* @param[in] flags Options for this operation. This parameter * @param[in] flags Options for this operation. This parameter
* must be set to 0 or one of the values described here. * must be set to 0 or one of the values described here.

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
.TH MDB_COPY 1 "2014/06/20" "LMDB 0.9.14" .TH MDB_COPY 1 "2017/07/31" "LMDB 0.9.70"
.\" Copyright 2012-2015 Howard Chu, Symas Corp. All Rights Reserved. .\" Copyright 2012-2019 Howard Chu, Symas Corp. All Rights Reserved.
.\" Copying restrictions apply. See COPYRIGHT/LICENSE. .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
.SH NAME .SH NAME
mdb_copy \- LMDB environment copy tool mdb_copy \- LMDB environment copy tool
@ -38,6 +38,7 @@ Write the library version number to the standard output, and exit.
Compact while copying. Only current data pages will be copied; freed Compact while copying. Only current data pages will be copied; freed
or unused pages will be omitted from the copy. This option will or unused pages will be omitted from the copy. This option will
slow down the backup process as it is more CPU-intensive. slow down the backup process as it is more CPU-intensive.
Currently it fails if the environment has suffered a page leak.
.TP .TP
.BR \-n .BR \-n
Open LDMB environment(s) which do not use subdirectories. Open LDMB environment(s) which do not use subdirectories.

View File

@ -1,6 +1,6 @@
/* mdb_copy.c - memory-mapped database backup tool */ /* mdb_copy.c - memory-mapped database backup tool */
/* /*
* Copyright 2012-2015 Howard Chu, Symas Corp. * Copyright 2012-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
.TH MDB_DROP 1 "2017/11/19" "LMDB 0.9.70" .TH MDB_DROP 1 "2017/11/19" "LMDB 0.9.70"
.\" Copyright 2014-2017 Howard Chu, Symas Corp. All Rights Reserved. .\" Copyright 2014-2018 Howard Chu, Symas Corp. All Rights Reserved.
.\" Copying restrictions apply. See COPYRIGHT/LICENSE. .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
.SH NAME .SH NAME
mdb_drop \- LMDB database delete tool mdb_drop \- LMDB database delete tool

View File

@ -1,6 +1,6 @@
/* mdb_drop.c - memory-mapped database delete tool */ /* mdb_drop.c - memory-mapped database delete tool */
/* /*
* Copyright 2016-2017 Howard Chu, Symas Corp. * Copyright 2016-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
.TH MDB_DUMP 1 "2014/06/20" "LMDB 0.9.14" .TH MDB_DUMP 1 "2017/07/31" "LMDB 0.9.70"
.\" Copyright 2014-2015 Howard Chu, Symas Corp. All Rights Reserved. .\" Copyright 2014-2017 Howard Chu, Symas Corp. All Rights Reserved.
.\" Copying restrictions apply. See COPYRIGHT/LICENSE. .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
.SH NAME .SH NAME
mdb_dump \- LMDB environment export tool mdb_dump \- LMDB environment export tool

View File

@ -1,6 +1,6 @@
/* mdb_dump.c - memory-mapped database dump tool */ /* mdb_dump.c - memory-mapped database dump tool */
/* /*
* Copyright 2011-2015 Howard Chu, Symas Corp. * Copyright 2011-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -20,20 +20,7 @@
#include <signal.h> #include <signal.h>
#include "lmdb.h" #include "lmdb.h"
#ifdef _WIN32 #define Yu MDB_PRIy(u)
#define Z "I"
#else
#define Z "z"
#endif
#ifdef MDB_VL32
#ifdef _WIN32
#define Y "I64"
#else
#define Y "ll"
#endif
#else
#define Y Z
#endif
#define PRINT 1 #define PRINT 1
static int mode; static int mode;
@ -124,7 +111,7 @@ static int dumpit(MDB_txn *txn, MDB_dbi dbi, char *name)
if (name) if (name)
printf("database=%s\n", name); printf("database=%s\n", name);
printf("type=btree\n"); printf("type=btree\n");
printf("mapsize=%" Y "u\n", info.me_mapsize); printf("mapsize=%"Yu"\n", info.me_mapsize);
if (info.me_mapaddr) if (info.me_mapaddr)
printf("mapaddr=%p\n", info.me_mapaddr); printf("mapaddr=%p\n", info.me_mapaddr);
printf("maxreaders=%u\n", info.me_maxreaders); printf("maxreaders=%u\n", info.me_maxreaders);

View File

@ -1,5 +1,5 @@
.TH MDB_LOAD 1 "2014/06/20" "LMDB 0.9.14" .TH MDB_LOAD 1 "2015/09/30" "LMDB 0.9.17"
.\" Copyright 2014-2015 Howard Chu, Symas Corp. All Rights Reserved. .\" Copyright 2014-2018 Howard Chu, Symas Corp. All Rights Reserved.
.\" Copying restrictions apply. See COPYRIGHT/LICENSE. .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
.SH NAME .SH NAME
mdb_load \- LMDB environment import tool mdb_load \- LMDB environment import tool

View File

@ -1,6 +1,6 @@
/* mdb_load.c - memory-mapped database load tool */ /* mdb_load.c - memory-mapped database load tool */
/* /*
* Copyright 2011-2015 Howard Chu, Symas Corp. * Copyright 2011-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -25,7 +25,7 @@ static int mode;
static char *subname = NULL; static char *subname = NULL;
static size_t lineno; static mdb_size_t lineno;
static int version; static int version;
static int flags; static int flags;
@ -39,20 +39,7 @@ static MDB_envinfo info;
static MDB_val kbuf, dbuf; static MDB_val kbuf, dbuf;
static MDB_val k0buf; static MDB_val k0buf;
#ifdef _WIN32 #define Yu MDB_PRIy(u)
#define Z "I"
#else
#define Z "z"
#endif
#ifdef MDB_VL32
#ifdef _WIN32
#define Y "I64"
#else
#define Y "ll"
#endif
#else
#define Y Z
#endif
#define STRLENOF(s) (sizeof(s)-1) #define STRLENOF(s) (sizeof(s)-1)
@ -84,7 +71,7 @@ static void readhdr(void)
if (!strncmp(dbuf.mv_data, "VERSION=", STRLENOF("VERSION="))) { if (!strncmp(dbuf.mv_data, "VERSION=", STRLENOF("VERSION="))) {
version=atoi((char *)dbuf.mv_data+STRLENOF("VERSION=")); version=atoi((char *)dbuf.mv_data+STRLENOF("VERSION="));
if (version > 3) { if (version > 3) {
fprintf(stderr, "%s: line %" Z "d: unsupported VERSION %d\n", fprintf(stderr, "%s: line %"Yu": unsupported VERSION %d\n",
prog, lineno, version); prog, lineno, version);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -94,7 +81,7 @@ static void readhdr(void)
if (!strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "print", STRLENOF("print"))) if (!strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "print", STRLENOF("print")))
mode |= PRINT; mode |= PRINT;
else if (strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "bytevalue", STRLENOF("bytevalue"))) { else if (strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "bytevalue", STRLENOF("bytevalue"))) {
fprintf(stderr, "%s: line %" Z "d: unsupported FORMAT %s\n", fprintf(stderr, "%s: line %"Yu": unsupported FORMAT %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("FORMAT=")); prog, lineno, (char *)dbuf.mv_data+STRLENOF("FORMAT="));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -105,7 +92,7 @@ static void readhdr(void)
subname = strdup((char *)dbuf.mv_data+STRLENOF("database=")); subname = strdup((char *)dbuf.mv_data+STRLENOF("database="));
} else if (!strncmp(dbuf.mv_data, "type=", STRLENOF("type="))) { } else if (!strncmp(dbuf.mv_data, "type=", STRLENOF("type="))) {
if (strncmp((char *)dbuf.mv_data+STRLENOF("type="), "btree", STRLENOF("btree"))) { if (strncmp((char *)dbuf.mv_data+STRLENOF("type="), "btree", STRLENOF("btree"))) {
fprintf(stderr, "%s: line %" Z "d: unsupported type %s\n", fprintf(stderr, "%s: line %"Yu": unsupported type %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("type=")); prog, lineno, (char *)dbuf.mv_data+STRLENOF("type="));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -115,7 +102,7 @@ static void readhdr(void)
if (ptr) *ptr = '\0'; if (ptr) *ptr = '\0';
i = sscanf((char *)dbuf.mv_data+STRLENOF("mapaddr="), "%p", &info.me_mapaddr); i = sscanf((char *)dbuf.mv_data+STRLENOF("mapaddr="), "%p", &info.me_mapaddr);
if (i != 1) { if (i != 1) {
fprintf(stderr, "%s: line %" Z "d: invalid mapaddr %s\n", fprintf(stderr, "%s: line %"Yu": invalid mapaddr %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapaddr=")); prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapaddr="));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -123,9 +110,10 @@ static void readhdr(void)
int i; int i;
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size); ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
if (ptr) *ptr = '\0'; if (ptr) *ptr = '\0';
i = sscanf((char *)dbuf.mv_data+STRLENOF("mapsize="), "%" Y "u", &info.me_mapsize); i = sscanf((char *)dbuf.mv_data+STRLENOF("mapsize="),
"%" MDB_SCNy(u), &info.me_mapsize);
if (i != 1) { if (i != 1) {
fprintf(stderr, "%s: line %" Z "d: invalid mapsize %s\n", fprintf(stderr, "%s: line %"Yu": invalid mapsize %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapsize=")); prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapsize="));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -135,7 +123,7 @@ static void readhdr(void)
if (ptr) *ptr = '\0'; if (ptr) *ptr = '\0';
i = sscanf((char *)dbuf.mv_data+STRLENOF("maxreaders="), "%u", &info.me_maxreaders); i = sscanf((char *)dbuf.mv_data+STRLENOF("maxreaders="), "%u", &info.me_maxreaders);
if (i != 1) { if (i != 1) {
fprintf(stderr, "%s: line %" Z "d: invalid maxreaders %s\n", fprintf(stderr, "%s: line %"Yu": invalid maxreaders %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("maxreaders=")); prog, lineno, (char *)dbuf.mv_data+STRLENOF("maxreaders="));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -151,12 +139,12 @@ static void readhdr(void)
if (!dbflags[i].bit) { if (!dbflags[i].bit) {
ptr = memchr(dbuf.mv_data, '=', dbuf.mv_size); ptr = memchr(dbuf.mv_data, '=', dbuf.mv_size);
if (!ptr) { if (!ptr) {
fprintf(stderr, "%s: line %" Z "d: unexpected format\n", fprintf(stderr, "%s: line %"Yu": unexpected format\n",
prog, lineno); prog, lineno);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} else { } else {
*ptr = '\0'; *ptr = '\0';
fprintf(stderr, "%s: line %" Z "d: unrecognized keyword ignored: %s\n", fprintf(stderr, "%s: line %"Yu": unrecognized keyword ignored: %s\n",
prog, lineno, (char *)dbuf.mv_data); prog, lineno, (char *)dbuf.mv_data);
} }
} }
@ -166,7 +154,7 @@ static void readhdr(void)
static void badend(void) static void badend(void)
{ {
fprintf(stderr, "%s: line %" Z "d: unexpected end of input\n", fprintf(stderr, "%s: line %"Yu": unexpected end of input\n",
prog, lineno); prog, lineno);
} }
@ -224,7 +212,7 @@ badend:
buf->mv_data = realloc(buf->mv_data, buf->mv_size*2); buf->mv_data = realloc(buf->mv_data, buf->mv_size*2);
if (!buf->mv_data) { if (!buf->mv_data) {
Eof = 1; Eof = 1;
fprintf(stderr, "%s: line %" Z "d: out of memory, line too long\n", fprintf(stderr, "%s: line %"Yu": out of memory, line too long\n",
prog, lineno); prog, lineno);
return EOF; return EOF;
} }
@ -259,7 +247,8 @@ badend:
c2 += 2; c2 += 2;
} }
} else { } else {
c1++; c2++; /* copies are redundant when no escapes were used */
*c1++ = *c2++;
} }
} }
} else { } else {
@ -435,7 +424,7 @@ int main(int argc, char *argv[])
rc = readline(&data, &dbuf); rc = readline(&data, &dbuf);
if (rc) { if (rc) {
fprintf(stderr, "%s: line %" Z "d: failed to read key value\n", prog, lineno); fprintf(stderr, "%s: line %"Yu": failed to read key value\n", prog, lineno);
goto txn_abort; goto txn_abort;
} }
@ -463,7 +452,7 @@ int main(int argc, char *argv[])
if (batch == 100) { if (batch == 100) {
rc = mdb_txn_commit(txn); rc = mdb_txn_commit(txn);
if (rc) { if (rc) {
fprintf(stderr, "%s: line %" Z "d: txn_commit: %s\n", fprintf(stderr, "%s: line %"Yu": txn_commit: %s\n",
prog, lineno, mdb_strerror(rc)); prog, lineno, mdb_strerror(rc));
goto env_close; goto env_close;
} }
@ -487,7 +476,7 @@ int main(int argc, char *argv[])
rc = mdb_txn_commit(txn); rc = mdb_txn_commit(txn);
txn = NULL; txn = NULL;
if (rc) { if (rc) {
fprintf(stderr, "%s: line %" Z "d: txn_commit: %s\n", fprintf(stderr, "%s: line %"Yu": txn_commit: %s\n",
prog, lineno, mdb_strerror(rc)); prog, lineno, mdb_strerror(rc));
goto env_close; goto env_close;
} }

View File

@ -1,5 +1,5 @@
.TH MDB_STAT 1 "2014/06/20" "LMDB 0.9.14" .TH MDB_STAT 1 "2017/07/31" "LMDB 0.9.70"
.\" Copyright 2012-2015 Howard Chu, Symas Corp. All Rights Reserved. .\" Copyright 2012-2019 Howard Chu, Symas Corp. All Rights Reserved.
.\" Copying restrictions apply. See COPYRIGHT/LICENSE. .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
.SH NAME .SH NAME
mdb_stat \- LMDB environment status tool mdb_stat \- LMDB environment status tool

View File

@ -1,6 +1,6 @@
/* mdb_stat.c - memory-mapped database status tool */ /* mdb_stat.c - memory-mapped database status tool */
/* /*
* Copyright 2011-2015 Howard Chu, Symas Corp. * Copyright 2011-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -17,20 +17,8 @@
#include <unistd.h> #include <unistd.h>
#include "lmdb.h" #include "lmdb.h"
#ifdef _WIN32 #define Z MDB_FMT_Z
#define Z "I" #define Yu MDB_PRIy(u)
#else
#define Z "z"
#endif
#ifdef MDB_VL32
#ifdef _WIN32
#define Y "I64"
#else
#define Y "ll"
#endif
#else
#define Y Z
#endif
static void prstat(MDB_stat *ms) static void prstat(MDB_stat *ms)
{ {
@ -38,10 +26,10 @@ static void prstat(MDB_stat *ms)
printf(" Page size: %u\n", ms->ms_psize); printf(" Page size: %u\n", ms->ms_psize);
#endif #endif
printf(" Tree depth: %u\n", ms->ms_depth); printf(" Tree depth: %u\n", ms->ms_depth);
printf(" Branch pages: %"Y"u\n", ms->ms_branch_pages); printf(" Branch pages: %"Yu"\n", ms->ms_branch_pages);
printf(" Leaf pages: %"Y"u\n", ms->ms_leaf_pages); printf(" Leaf pages: %"Yu"\n", ms->ms_leaf_pages);
printf(" Overflow pages: %"Y"u\n", ms->ms_overflow_pages); printf(" Overflow pages: %"Yu"\n", ms->ms_overflow_pages);
printf(" Entries: %"Y"u\n", ms->ms_entries); printf(" Entries: %"Yu"\n", ms->ms_entries);
} }
static void usage(char *prog) static void usage(char *prog)
@ -138,11 +126,11 @@ int main(int argc, char *argv[])
(void)mdb_env_info(env, &mei); (void)mdb_env_info(env, &mei);
printf("Environment Info\n"); printf("Environment Info\n");
printf(" Map address: %p\n", mei.me_mapaddr); printf(" Map address: %p\n", mei.me_mapaddr);
printf(" Map size: %"Y"u\n", mei.me_mapsize); printf(" Map size: %"Yu"\n", mei.me_mapsize);
printf(" Page size: %u\n", mst.ms_psize); printf(" Page size: %u\n", mst.ms_psize);
printf(" Max pages: %"Y"u\n", mei.me_mapsize / mst.ms_psize); printf(" Max pages: %"Yu"\n", mei.me_mapsize / mst.ms_psize);
printf(" Number of pages used: %"Y"u\n", mei.me_last_pgno+1); printf(" Number of pages used: %"Yu"\n", mei.me_last_pgno+1);
printf(" Last transaction ID: %"Y"u\n", mei.me_last_txnid); printf(" Last transaction ID: %"Yu"\n", mei.me_last_txnid);
printf(" Max readers: %u\n", mei.me_maxreaders); printf(" Max readers: %u\n", mei.me_maxreaders);
printf(" Number of readers used: %u\n", mei.me_numreaders); printf(" Number of readers used: %u\n", mei.me_numreaders);
} }
@ -169,7 +157,7 @@ int main(int argc, char *argv[])
if (freinfo) { if (freinfo) {
MDB_cursor *cursor; MDB_cursor *cursor;
MDB_val key, data; MDB_val key, data;
size_t pages = 0, *iptr; mdb_size_t pages = 0, *iptr;
printf("Freelist Status\n"); printf("Freelist Status\n");
dbi = 0; dbi = 0;
@ -189,7 +177,7 @@ int main(int argc, char *argv[])
pages += *iptr; pages += *iptr;
if (freinfo > 1) { if (freinfo > 1) {
char *bad = ""; char *bad = "";
size_t pg, prev; mdb_size_t pg, prev;
ssize_t i, j, span = 0; ssize_t i, j, span = 0;
j = *iptr++; j = *iptr++;
for (i = j, prev = 1; --i >= 0; ) { for (i = j, prev = 1; --i >= 0; ) {
@ -200,20 +188,20 @@ int main(int argc, char *argv[])
pg += span; pg += span;
for (; i >= span && iptr[i-span] == pg; span++, pg++) ; for (; i >= span && iptr[i-span] == pg; span++, pg++) ;
} }
printf(" Transaction %"Z"u, %"Z"d pages, maxspan %"Z"d%s\n", printf(" Transaction %"Yu", %"Z"d pages, maxspan %"Z"d%s\n",
*(size_t *)key.mv_data, j, span, bad); *(mdb_size_t *)key.mv_data, j, span, bad);
if (freinfo > 2) { if (freinfo > 2) {
for (--j; j >= 0; ) { for (--j; j >= 0; ) {
pg = iptr[j]; pg = iptr[j];
for (span=1; --j >= 0 && iptr[j] == pg+span; span++) ; for (span=1; --j >= 0 && iptr[j] == pg+span; span++) ;
printf(span>1 ? " %9"Z"u[%"Z"d]\n" : " %9"Z"u\n", printf(span>1 ? " %9"Yu"[%"Z"d]\n" : " %9"Yu"\n",
pg, span); pg, span);
} }
} }
} }
} }
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
printf(" Free pages: %"Z"u\n", pages); printf(" Free pages: %"Yu"\n", pages);
} }
rc = mdb_open(txn, subname, 0, &dbi); rc = mdb_open(txn, subname, 0, &dbi);

View File

@ -3,7 +3,8 @@
/* $OpenLDAP$ */ /* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
* *
* Copyright 2000-2015 The OpenLDAP Foundation. * Copyright 2000-2019 The OpenLDAP Foundation.
* Portions Copyright 2001-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -11,7 +11,8 @@
/* $OpenLDAP$ */ /* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
* *
* Copyright 2000-2015 The OpenLDAP Foundation. * Copyright 2000-2019 The OpenLDAP Foundation.
* Portions Copyright 2001-2019 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -26,8 +27,7 @@
#ifndef _MDB_MIDL_H_ #ifndef _MDB_MIDL_H_
#define _MDB_MIDL_H_ #define _MDB_MIDL_H_
#include <stddef.h> #include "lmdb.h"
#include <inttypes.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -43,11 +43,7 @@ extern "C" {
/** A generic unsigned ID number. These were entryIDs in back-bdb. /** A generic unsigned ID number. These were entryIDs in back-bdb.
* Preferably it should have the same size as a pointer. * Preferably it should have the same size as a pointer.
*/ */
#ifdef MDB_VL32 typedef mdb_size_t MDB_ID;
typedef uint64_t MDB_ID;
#else
typedef size_t MDB_ID;
#endif
/** An IDL is an ID List, a sorted array of IDs. The first /** An IDL is an ID List, a sorted array of IDs. The first
* element of the array is a counter for how many actual * element of the array is a counter for how many actual

View File

@ -1,6 +1,6 @@
/* mtest.c - memory-mapped database tester/toy */ /* mtest.c - memory-mapped database tester/toy */
/* /*
* Copyright 2011-2015 Howard Chu, Symas Corp. * Copyright 2011-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,6 @@
/* mtest2.c - memory-mapped database tester/toy */ /* mtest2.c - memory-mapped database tester/toy */
/* /*
* Copyright 2011-2015 Howard Chu, Symas Corp. * Copyright 2011-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,6 @@
/* mtest3.c - memory-mapped database tester/toy */ /* mtest3.c - memory-mapped database tester/toy */
/* /*
* Copyright 2011-2015 Howard Chu, Symas Corp. * Copyright 2011-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,6 @@
/* mtest4.c - memory-mapped database tester/toy */ /* mtest4.c - memory-mapped database tester/toy */
/* /*
* Copyright 2011-2015 Howard Chu, Symas Corp. * Copyright 2011-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,6 @@
/* mtest5.c - memory-mapped database tester/toy */ /* mtest5.c - memory-mapped database tester/toy */
/* /*
* Copyright 2011-2015 Howard Chu, Symas Corp. * Copyright 2011-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,6 @@
/* mtest6.c - memory-mapped database tester/toy */ /* mtest6.c - memory-mapped database tester/toy */
/* /*
* Copyright 2011-2015 Howard Chu, Symas Corp. * Copyright 2011-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -3,7 +3,7 @@
* Do a line-by-line comparison of this and sample-mdb.txt * Do a line-by-line comparison of this and sample-mdb.txt
*/ */
/* /*
* Copyright 2012-2015 Howard Chu, Symas Corp. * Copyright 2012-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -3,7 +3,7 @@
* Do a line-by-line comparison of this and sample-bdb.txt * Do a line-by-line comparison of this and sample-bdb.txt
*/ */
/* /*
* Copyright 2012-2015 Howard Chu, Symas Corp. * Copyright 2012-2018 Howard Chu, Symas Corp.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without