lmdb 0.6 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/lmdb_ext/extconf.rb +7 -3
- data/ext/lmdb_ext/lmdb_ext.c +120 -110
- data/lib/lmdb/version.rb +1 -1
- data/lmdb.gemspec +4 -4
- data/{ext/lmdb_ext → vendor/libraries}/liblmdb/.gitignore +8 -0
- data/{ext/lmdb_ext → vendor/libraries}/liblmdb/COPYRIGHT +1 -1
- data/vendor/libraries/liblmdb/Doxyfile +1631 -0
- data/{ext/lmdb_ext → vendor/libraries}/liblmdb/LICENSE +0 -0
- data/vendor/libraries/liblmdb/Makefile +118 -0
- data/vendor/libraries/liblmdb/intro.doc +192 -0
- data/{ext/lmdb_ext → vendor/libraries}/liblmdb/lmdb.h +161 -61
- data/{ext/lmdb_ext → vendor/libraries}/liblmdb/mdb.c +3244 -1302
- data/vendor/libraries/liblmdb/mdb_copy.1 +61 -0
- data/vendor/libraries/liblmdb/mdb_copy.c +84 -0
- data/vendor/libraries/liblmdb/mdb_drop.1 +40 -0
- data/vendor/libraries/liblmdb/mdb_drop.c +135 -0
- data/vendor/libraries/liblmdb/mdb_dump.1 +81 -0
- data/vendor/libraries/liblmdb/mdb_dump.c +319 -0
- data/vendor/libraries/liblmdb/mdb_load.1 +84 -0
- data/vendor/libraries/liblmdb/mdb_load.c +492 -0
- data/vendor/libraries/liblmdb/mdb_stat.1 +70 -0
- data/vendor/libraries/liblmdb/mdb_stat.c +264 -0
- data/{ext/lmdb_ext → vendor/libraries}/liblmdb/midl.c +66 -5
- data/{ext/lmdb_ext → vendor/libraries}/liblmdb/midl.h +19 -5
- data/vendor/libraries/liblmdb/mtest.c +177 -0
- data/vendor/libraries/liblmdb/mtest2.c +124 -0
- data/vendor/libraries/liblmdb/mtest3.c +133 -0
- data/vendor/libraries/liblmdb/mtest4.c +168 -0
- data/vendor/libraries/liblmdb/mtest5.c +135 -0
- data/vendor/libraries/liblmdb/mtest6.c +141 -0
- data/vendor/libraries/liblmdb/sample-bdb.txt +73 -0
- data/vendor/libraries/liblmdb/sample-mdb.txt +62 -0
- data/vendor/libraries/liblmdb/tooltag +27 -0
- metadata +34 -14
- data/.gitignore +0 -15
- data/.travis.yml +0 -14
- data/ext/lmdb_ext/liblmdb/CHANGES +0 -112
@@ -0,0 +1,61 @@
|
|
1
|
+
.TH MDB_COPY 1 "2017/07/31" "LMDB 0.9.70"
|
2
|
+
.\" Copyright 2012-2021 Howard Chu, Symas Corp. All Rights Reserved.
|
3
|
+
.\" Copying restrictions apply. See COPYRIGHT/LICENSE.
|
4
|
+
.SH NAME
|
5
|
+
mdb_copy \- LMDB environment copy tool
|
6
|
+
.SH SYNOPSIS
|
7
|
+
.B mdb_copy
|
8
|
+
[\c
|
9
|
+
.BR \-V ]
|
10
|
+
[\c
|
11
|
+
.BR \-c ]
|
12
|
+
[\c
|
13
|
+
.BR \-n ]
|
14
|
+
[\c
|
15
|
+
.BR \-v ]
|
16
|
+
.B srcpath
|
17
|
+
[\c
|
18
|
+
.BR dstpath ]
|
19
|
+
.SH DESCRIPTION
|
20
|
+
The
|
21
|
+
.B mdb_copy
|
22
|
+
utility copies an LMDB environment. The environment can
|
23
|
+
be copied regardless of whether it is currently in use.
|
24
|
+
No lockfile is created, since it gets recreated at need.
|
25
|
+
|
26
|
+
If
|
27
|
+
.I dstpath
|
28
|
+
is specified it must be the path of an empty directory
|
29
|
+
for storing the backup. Otherwise, the backup will be
|
30
|
+
written to stdout.
|
31
|
+
|
32
|
+
.SH OPTIONS
|
33
|
+
.TP
|
34
|
+
.BR \-V
|
35
|
+
Write the library version number to the standard output, and exit.
|
36
|
+
.TP
|
37
|
+
.BR \-c
|
38
|
+
Compact while copying. Only current data pages will be copied; freed
|
39
|
+
or unused pages will be omitted from the copy. This option will
|
40
|
+
slow down the backup process as it is more CPU-intensive.
|
41
|
+
Currently it fails if the environment has suffered a page leak.
|
42
|
+
.TP
|
43
|
+
.BR \-n
|
44
|
+
Open LDMB environment(s) which do not use subdirectories.
|
45
|
+
.TP
|
46
|
+
.BR \-v
|
47
|
+
Use the previous environment state instead of the latest state.
|
48
|
+
This may be useful if the latest state has been corrupted.
|
49
|
+
|
50
|
+
.SH DIAGNOSTICS
|
51
|
+
Exit status is zero if no errors occur.
|
52
|
+
Errors result in a non-zero exit status and
|
53
|
+
a diagnostic message being written to standard error.
|
54
|
+
.SH CAVEATS
|
55
|
+
This utility can trigger significant file size growth if run
|
56
|
+
in parallel with write transactions, because pages which they
|
57
|
+
free during copying cannot be reused until the copy is done.
|
58
|
+
.SH "SEE ALSO"
|
59
|
+
.BR mdb_stat (1)
|
60
|
+
.SH AUTHOR
|
61
|
+
Howard Chu of Symas Corporation <http://www.symas.com>
|
@@ -0,0 +1,84 @@
|
|
1
|
+
/* mdb_copy.c - memory-mapped database backup tool */
|
2
|
+
/*
|
3
|
+
* Copyright 2012-2021 Howard Chu, Symas Corp.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted only as authorized by the OpenLDAP
|
8
|
+
* Public License.
|
9
|
+
*
|
10
|
+
* A copy of this license is available in the file LICENSE in the
|
11
|
+
* top-level directory of the distribution or, alternatively, at
|
12
|
+
* <http://www.OpenLDAP.org/license.html>.
|
13
|
+
*/
|
14
|
+
#ifdef _WIN32
|
15
|
+
#include <windows.h>
|
16
|
+
#define MDB_STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
|
17
|
+
#else
|
18
|
+
#define MDB_STDOUT 1
|
19
|
+
#endif
|
20
|
+
#include <stdio.h>
|
21
|
+
#include <stdlib.h>
|
22
|
+
#include <signal.h>
|
23
|
+
#include "lmdb.h"
|
24
|
+
|
25
|
+
static void
|
26
|
+
sighandle(int sig)
|
27
|
+
{
|
28
|
+
}
|
29
|
+
|
30
|
+
int main(int argc,char * argv[])
|
31
|
+
{
|
32
|
+
int rc;
|
33
|
+
MDB_env *env;
|
34
|
+
const char *progname = argv[0], *act;
|
35
|
+
unsigned flags = MDB_RDONLY;
|
36
|
+
unsigned cpflags = 0;
|
37
|
+
|
38
|
+
for (; argc > 1 && argv[1][0] == '-'; argc--, argv++) {
|
39
|
+
if (argv[1][1] == 'n' && argv[1][2] == '\0')
|
40
|
+
flags |= MDB_NOSUBDIR;
|
41
|
+
else if (argv[1][1] == 'v' && argv[1][2] == '\0')
|
42
|
+
flags |= MDB_PREVSNAPSHOT;
|
43
|
+
else if (argv[1][1] == 'c' && argv[1][2] == '\0')
|
44
|
+
cpflags |= MDB_CP_COMPACT;
|
45
|
+
else if (argv[1][1] == 'V' && argv[1][2] == '\0') {
|
46
|
+
printf("%s\n", MDB_VERSION_STRING);
|
47
|
+
exit(0);
|
48
|
+
} else
|
49
|
+
argc = 0;
|
50
|
+
}
|
51
|
+
|
52
|
+
if (argc<2 || argc>3) {
|
53
|
+
fprintf(stderr, "usage: %s [-V] [-c] [-n] [-v] srcpath [dstpath]\n", progname);
|
54
|
+
exit(EXIT_FAILURE);
|
55
|
+
}
|
56
|
+
|
57
|
+
#ifdef SIGPIPE
|
58
|
+
signal(SIGPIPE, sighandle);
|
59
|
+
#endif
|
60
|
+
#ifdef SIGHUP
|
61
|
+
signal(SIGHUP, sighandle);
|
62
|
+
#endif
|
63
|
+
signal(SIGINT, sighandle);
|
64
|
+
signal(SIGTERM, sighandle);
|
65
|
+
|
66
|
+
act = "opening environment";
|
67
|
+
rc = mdb_env_create(&env);
|
68
|
+
if (rc == MDB_SUCCESS) {
|
69
|
+
rc = mdb_env_open(env, argv[1], flags, 0600);
|
70
|
+
}
|
71
|
+
if (rc == MDB_SUCCESS) {
|
72
|
+
act = "copying";
|
73
|
+
if (argc == 2)
|
74
|
+
rc = mdb_env_copyfd2(env, MDB_STDOUT, cpflags);
|
75
|
+
else
|
76
|
+
rc = mdb_env_copy2(env, argv[2], cpflags);
|
77
|
+
}
|
78
|
+
if (rc)
|
79
|
+
fprintf(stderr, "%s: %s failed, error %d (%s)\n",
|
80
|
+
progname, act, rc, mdb_strerror(rc));
|
81
|
+
mdb_env_close(env);
|
82
|
+
|
83
|
+
return rc ? EXIT_FAILURE : EXIT_SUCCESS;
|
84
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
.TH MDB_DROP 1 "2017/11/19" "LMDB 0.9.70"
|
2
|
+
.\" Copyright 2014-2021 Howard Chu, Symas Corp. All Rights Reserved.
|
3
|
+
.\" Copying restrictions apply. See COPYRIGHT/LICENSE.
|
4
|
+
.SH NAME
|
5
|
+
mdb_drop \- LMDB database delete tool
|
6
|
+
.SH SYNOPSIS
|
7
|
+
.B mdb_drop
|
8
|
+
[\c
|
9
|
+
.BR \-V ]
|
10
|
+
[\c
|
11
|
+
.BR \-n ]
|
12
|
+
[\c
|
13
|
+
.BR \-d ]
|
14
|
+
[\c
|
15
|
+
.BI \-s \ subdb\fR]
|
16
|
+
.BR \ envpath
|
17
|
+
.SH DESCRIPTION
|
18
|
+
The
|
19
|
+
.B mdb_drop
|
20
|
+
utility empties or deletes a database in the specified
|
21
|
+
environment.
|
22
|
+
.SH OPTIONS
|
23
|
+
.TP
|
24
|
+
.BR \-V
|
25
|
+
Write the library version number to the standard output, and exit.
|
26
|
+
.TP
|
27
|
+
.BR \-n
|
28
|
+
Operate on an LMDB database which does not use subdirectories.
|
29
|
+
.TP
|
30
|
+
.BR \-d
|
31
|
+
Delete the specified database, don't just empty it.
|
32
|
+
.TP
|
33
|
+
.BR \-s \ subdb
|
34
|
+
Operate on a specific subdatabase. If no database is specified, only the main database is dropped.
|
35
|
+
.SH DIAGNOSTICS
|
36
|
+
Exit status is zero if no errors occur.
|
37
|
+
Errors result in a non-zero exit status and
|
38
|
+
a diagnostic message being written to standard error.
|
39
|
+
.SH AUTHOR
|
40
|
+
Howard Chu of Symas Corporation <http://www.symas.com>
|
@@ -0,0 +1,135 @@
|
|
1
|
+
/* mdb_drop.c - memory-mapped database delete tool */
|
2
|
+
/*
|
3
|
+
* Copyright 2016-2021 Howard Chu, Symas Corp.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted only as authorized by the OpenLDAP
|
8
|
+
* Public License.
|
9
|
+
*
|
10
|
+
* A copy of this license is available in the file LICENSE in the
|
11
|
+
* top-level directory of the distribution or, alternatively, at
|
12
|
+
* <http://www.OpenLDAP.org/license.html>.
|
13
|
+
*/
|
14
|
+
#include <stdio.h>
|
15
|
+
#include <errno.h>
|
16
|
+
#include <stdlib.h>
|
17
|
+
#include <string.h>
|
18
|
+
#include <ctype.h>
|
19
|
+
#include <unistd.h>
|
20
|
+
#include <signal.h>
|
21
|
+
#include "lmdb.h"
|
22
|
+
|
23
|
+
static volatile sig_atomic_t gotsig;
|
24
|
+
|
25
|
+
static void dumpsig( int sig )
|
26
|
+
{
|
27
|
+
gotsig=1;
|
28
|
+
}
|
29
|
+
|
30
|
+
static void usage(char *prog)
|
31
|
+
{
|
32
|
+
fprintf(stderr, "usage: %s [-V] [-n] [-d] [-s subdb] dbpath\n", prog);
|
33
|
+
exit(EXIT_FAILURE);
|
34
|
+
}
|
35
|
+
|
36
|
+
int main(int argc, char *argv[])
|
37
|
+
{
|
38
|
+
int i, rc;
|
39
|
+
MDB_env *env;
|
40
|
+
MDB_txn *txn;
|
41
|
+
MDB_dbi dbi;
|
42
|
+
char *prog = argv[0];
|
43
|
+
char *envname;
|
44
|
+
char *subname = NULL;
|
45
|
+
int envflags = 0, delete = 0;
|
46
|
+
|
47
|
+
if (argc < 2) {
|
48
|
+
usage(prog);
|
49
|
+
}
|
50
|
+
|
51
|
+
/* -d: delete the db, don't just empty it
|
52
|
+
* -s: drop the named subDB
|
53
|
+
* -n: use NOSUBDIR flag on env_open
|
54
|
+
* -V: print version and exit
|
55
|
+
* (default) empty the main DB
|
56
|
+
*/
|
57
|
+
while ((i = getopt(argc, argv, "dns:V")) != EOF) {
|
58
|
+
switch(i) {
|
59
|
+
case 'V':
|
60
|
+
printf("%s\n", MDB_VERSION_STRING);
|
61
|
+
exit(0);
|
62
|
+
break;
|
63
|
+
case 'd':
|
64
|
+
delete = 1;
|
65
|
+
break;
|
66
|
+
case 'n':
|
67
|
+
envflags |= MDB_NOSUBDIR;
|
68
|
+
break;
|
69
|
+
case 's':
|
70
|
+
subname = optarg;
|
71
|
+
break;
|
72
|
+
default:
|
73
|
+
usage(prog);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
if (optind != argc - 1)
|
78
|
+
usage(prog);
|
79
|
+
|
80
|
+
#ifdef SIGPIPE
|
81
|
+
signal(SIGPIPE, dumpsig);
|
82
|
+
#endif
|
83
|
+
#ifdef SIGHUP
|
84
|
+
signal(SIGHUP, dumpsig);
|
85
|
+
#endif
|
86
|
+
signal(SIGINT, dumpsig);
|
87
|
+
signal(SIGTERM, dumpsig);
|
88
|
+
|
89
|
+
envname = argv[optind];
|
90
|
+
rc = mdb_env_create(&env);
|
91
|
+
if (rc) {
|
92
|
+
fprintf(stderr, "mdb_env_create failed, error %d %s\n", rc, mdb_strerror(rc));
|
93
|
+
return EXIT_FAILURE;
|
94
|
+
}
|
95
|
+
|
96
|
+
mdb_env_set_maxdbs(env, 2);
|
97
|
+
|
98
|
+
rc = mdb_env_open(env, envname, envflags, 0664);
|
99
|
+
if (rc) {
|
100
|
+
fprintf(stderr, "mdb_env_open failed, error %d %s\n", rc, mdb_strerror(rc));
|
101
|
+
goto env_close;
|
102
|
+
}
|
103
|
+
|
104
|
+
rc = mdb_txn_begin(env, NULL, 0, &txn);
|
105
|
+
if (rc) {
|
106
|
+
fprintf(stderr, "mdb_txn_begin failed, error %d %s\n", rc, mdb_strerror(rc));
|
107
|
+
goto env_close;
|
108
|
+
}
|
109
|
+
|
110
|
+
rc = mdb_open(txn, subname, 0, &dbi);
|
111
|
+
if (rc) {
|
112
|
+
fprintf(stderr, "mdb_open failed, error %d %s\n", rc, mdb_strerror(rc));
|
113
|
+
goto txn_abort;
|
114
|
+
}
|
115
|
+
|
116
|
+
rc = mdb_drop(txn, dbi, delete);
|
117
|
+
if (rc) {
|
118
|
+
fprintf(stderr, "mdb_drop failed, error %d %s\n", rc, mdb_strerror(rc));
|
119
|
+
goto txn_abort;
|
120
|
+
}
|
121
|
+
rc = mdb_txn_commit(txn);
|
122
|
+
if (rc) {
|
123
|
+
fprintf(stderr, "mdb_txn_commit failed, error %d %s\n", rc, mdb_strerror(rc));
|
124
|
+
goto txn_abort;
|
125
|
+
}
|
126
|
+
txn = NULL;
|
127
|
+
|
128
|
+
txn_abort:
|
129
|
+
if (txn)
|
130
|
+
mdb_txn_abort(txn);
|
131
|
+
env_close:
|
132
|
+
mdb_env_close(env);
|
133
|
+
|
134
|
+
return rc ? EXIT_FAILURE : EXIT_SUCCESS;
|
135
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
.TH MDB_DUMP 1 "2017/07/31" "LMDB 0.9.70"
|
2
|
+
.\" Copyright 2014-2021 Howard Chu, Symas Corp. All Rights Reserved.
|
3
|
+
.\" Copying restrictions apply. See COPYRIGHT/LICENSE.
|
4
|
+
.SH NAME
|
5
|
+
mdb_dump \- LMDB environment export tool
|
6
|
+
.SH SYNOPSIS
|
7
|
+
.B mdb_dump
|
8
|
+
[\c
|
9
|
+
.BR \-V ]
|
10
|
+
[\c
|
11
|
+
.BI \-f \ file\fR]
|
12
|
+
[\c
|
13
|
+
.BR \-l ]
|
14
|
+
[\c
|
15
|
+
.BR \-n ]
|
16
|
+
[\c
|
17
|
+
.BR \-v ]
|
18
|
+
[\c
|
19
|
+
.BR \-p ]
|
20
|
+
[\c
|
21
|
+
.BR \-a \ |
|
22
|
+
.BI \-s \ subdb\fR]
|
23
|
+
.BR \ envpath
|
24
|
+
.SH DESCRIPTION
|
25
|
+
The
|
26
|
+
.B mdb_dump
|
27
|
+
utility reads a database and writes its contents to the
|
28
|
+
standard output using a portable flat-text format
|
29
|
+
understood by the
|
30
|
+
.BR mdb_load (1)
|
31
|
+
utility.
|
32
|
+
.SH OPTIONS
|
33
|
+
.TP
|
34
|
+
.BR \-V
|
35
|
+
Write the library version number to the standard output, and exit.
|
36
|
+
.TP
|
37
|
+
.BR \-f \ file
|
38
|
+
Write to the specified file instead of to the standard output.
|
39
|
+
.TP
|
40
|
+
.BR \-l
|
41
|
+
List the databases stored in the environment. Just the
|
42
|
+
names will be listed, no data will be output.
|
43
|
+
.TP
|
44
|
+
.BR \-n
|
45
|
+
Dump an LMDB database which does not use subdirectories.
|
46
|
+
.TP
|
47
|
+
.BR \-v
|
48
|
+
Use the previous environment state instead of the latest state.
|
49
|
+
This may be useful if the latest state has been corrupted.
|
50
|
+
.TP
|
51
|
+
.BR \-p
|
52
|
+
If characters in either the key or data items are printing characters (as
|
53
|
+
defined by isprint(3)), output them directly. This option permits users to
|
54
|
+
use standard text editors and tools to modify the contents of databases.
|
55
|
+
|
56
|
+
Note: different systems may have different notions about what characters
|
57
|
+
are considered printing characters, and databases dumped in this manner may
|
58
|
+
be less portable to external systems.
|
59
|
+
.TP
|
60
|
+
.BR \-a
|
61
|
+
Dump all of the subdatabases in the environment.
|
62
|
+
.TP
|
63
|
+
.BR \-s \ subdb
|
64
|
+
Dump a specific subdatabase. If no database is specified, only the main database is dumped.
|
65
|
+
.SH DIAGNOSTICS
|
66
|
+
Exit status is zero if no errors occur.
|
67
|
+
Errors result in a non-zero exit status and
|
68
|
+
a diagnostic message being written to standard error.
|
69
|
+
|
70
|
+
Dumping and reloading databases that use user-defined comparison functions
|
71
|
+
will result in new databases that use the default comparison functions.
|
72
|
+
\fBIn this case it is quite likely that the reloaded database will be
|
73
|
+
damaged beyond repair permitting neither record storage nor retrieval.\fP
|
74
|
+
|
75
|
+
The only available workaround is to modify the source for the
|
76
|
+
.BR mdb_load (1)
|
77
|
+
utility to load the database using the correct comparison functions.
|
78
|
+
.SH "SEE ALSO"
|
79
|
+
.BR mdb_load (1)
|
80
|
+
.SH AUTHOR
|
81
|
+
Howard Chu of Symas Corporation <http://www.symas.com>
|
@@ -0,0 +1,319 @@
|
|
1
|
+
/* mdb_dump.c - memory-mapped database dump tool */
|
2
|
+
/*
|
3
|
+
* Copyright 2011-2021 Howard Chu, Symas Corp.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted only as authorized by the OpenLDAP
|
8
|
+
* Public License.
|
9
|
+
*
|
10
|
+
* A copy of this license is available in the file LICENSE in the
|
11
|
+
* top-level directory of the distribution or, alternatively, at
|
12
|
+
* <http://www.OpenLDAP.org/license.html>.
|
13
|
+
*/
|
14
|
+
#include <stdio.h>
|
15
|
+
#include <errno.h>
|
16
|
+
#include <stdlib.h>
|
17
|
+
#include <string.h>
|
18
|
+
#include <ctype.h>
|
19
|
+
#include <unistd.h>
|
20
|
+
#include <signal.h>
|
21
|
+
#include "lmdb.h"
|
22
|
+
|
23
|
+
#define Yu MDB_PRIy(u)
|
24
|
+
|
25
|
+
#define PRINT 1
|
26
|
+
static int mode;
|
27
|
+
|
28
|
+
typedef struct flagbit {
|
29
|
+
int bit;
|
30
|
+
char *name;
|
31
|
+
} flagbit;
|
32
|
+
|
33
|
+
flagbit dbflags[] = {
|
34
|
+
{ MDB_REVERSEKEY, "reversekey" },
|
35
|
+
{ MDB_DUPSORT, "dupsort" },
|
36
|
+
{ MDB_INTEGERKEY, "integerkey" },
|
37
|
+
{ MDB_DUPFIXED, "dupfixed" },
|
38
|
+
{ MDB_INTEGERDUP, "integerdup" },
|
39
|
+
{ MDB_REVERSEDUP, "reversedup" },
|
40
|
+
{ 0, NULL }
|
41
|
+
};
|
42
|
+
|
43
|
+
static volatile sig_atomic_t gotsig;
|
44
|
+
|
45
|
+
static void dumpsig( int sig )
|
46
|
+
{
|
47
|
+
gotsig=1;
|
48
|
+
}
|
49
|
+
|
50
|
+
static const char hexc[] = "0123456789abcdef";
|
51
|
+
|
52
|
+
static void hex(unsigned char c)
|
53
|
+
{
|
54
|
+
putchar(hexc[c >> 4]);
|
55
|
+
putchar(hexc[c & 0xf]);
|
56
|
+
}
|
57
|
+
|
58
|
+
static void text(MDB_val *v)
|
59
|
+
{
|
60
|
+
unsigned char *c, *end;
|
61
|
+
|
62
|
+
putchar(' ');
|
63
|
+
c = v->mv_data;
|
64
|
+
end = c + v->mv_size;
|
65
|
+
while (c < end) {
|
66
|
+
if (isprint(*c)) {
|
67
|
+
if (*c == '\\')
|
68
|
+
putchar('\\');
|
69
|
+
putchar(*c);
|
70
|
+
} else {
|
71
|
+
putchar('\\');
|
72
|
+
hex(*c);
|
73
|
+
}
|
74
|
+
c++;
|
75
|
+
}
|
76
|
+
putchar('\n');
|
77
|
+
}
|
78
|
+
|
79
|
+
static void byte(MDB_val *v)
|
80
|
+
{
|
81
|
+
unsigned char *c, *end;
|
82
|
+
|
83
|
+
putchar(' ');
|
84
|
+
c = v->mv_data;
|
85
|
+
end = c + v->mv_size;
|
86
|
+
while (c < end) {
|
87
|
+
hex(*c++);
|
88
|
+
}
|
89
|
+
putchar('\n');
|
90
|
+
}
|
91
|
+
|
92
|
+
/* Dump in BDB-compatible format */
|
93
|
+
static int dumpit(MDB_txn *txn, MDB_dbi dbi, char *name)
|
94
|
+
{
|
95
|
+
MDB_cursor *mc;
|
96
|
+
MDB_stat ms;
|
97
|
+
MDB_val key, data;
|
98
|
+
MDB_envinfo info;
|
99
|
+
unsigned int flags;
|
100
|
+
int rc, i;
|
101
|
+
|
102
|
+
rc = mdb_dbi_flags(txn, dbi, &flags);
|
103
|
+
if (rc) return rc;
|
104
|
+
|
105
|
+
rc = mdb_stat(txn, dbi, &ms);
|
106
|
+
if (rc) return rc;
|
107
|
+
|
108
|
+
rc = mdb_env_info(mdb_txn_env(txn), &info);
|
109
|
+
if (rc) return rc;
|
110
|
+
|
111
|
+
printf("VERSION=3\n");
|
112
|
+
printf("format=%s\n", mode & PRINT ? "print" : "bytevalue");
|
113
|
+
if (name)
|
114
|
+
printf("database=%s\n", name);
|
115
|
+
printf("type=btree\n");
|
116
|
+
printf("mapsize=%"Yu"\n", info.me_mapsize);
|
117
|
+
if (info.me_mapaddr)
|
118
|
+
printf("mapaddr=%p\n", info.me_mapaddr);
|
119
|
+
printf("maxreaders=%u\n", info.me_maxreaders);
|
120
|
+
|
121
|
+
if (flags & MDB_DUPSORT)
|
122
|
+
printf("duplicates=1\n");
|
123
|
+
|
124
|
+
for (i=0; dbflags[i].bit; i++)
|
125
|
+
if (flags & dbflags[i].bit)
|
126
|
+
printf("%s=1\n", dbflags[i].name);
|
127
|
+
|
128
|
+
printf("db_pagesize=%d\n", ms.ms_psize);
|
129
|
+
printf("HEADER=END\n");
|
130
|
+
|
131
|
+
rc = mdb_cursor_open(txn, dbi, &mc);
|
132
|
+
if (rc) return rc;
|
133
|
+
|
134
|
+
while ((rc = mdb_cursor_get(mc, &key, &data, MDB_NEXT) == MDB_SUCCESS)) {
|
135
|
+
if (gotsig) {
|
136
|
+
rc = EINTR;
|
137
|
+
break;
|
138
|
+
}
|
139
|
+
if (mode & PRINT) {
|
140
|
+
text(&key);
|
141
|
+
text(&data);
|
142
|
+
} else {
|
143
|
+
byte(&key);
|
144
|
+
byte(&data);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
printf("DATA=END\n");
|
148
|
+
if (rc == MDB_NOTFOUND)
|
149
|
+
rc = MDB_SUCCESS;
|
150
|
+
|
151
|
+
return rc;
|
152
|
+
}
|
153
|
+
|
154
|
+
static void usage(char *prog)
|
155
|
+
{
|
156
|
+
fprintf(stderr, "usage: %s [-V] [-f output] [-l] [-n] [-p] [-v] [-a|-s subdb] dbpath\n", prog);
|
157
|
+
exit(EXIT_FAILURE);
|
158
|
+
}
|
159
|
+
|
160
|
+
int main(int argc, char *argv[])
|
161
|
+
{
|
162
|
+
int i, rc;
|
163
|
+
MDB_env *env;
|
164
|
+
MDB_txn *txn;
|
165
|
+
MDB_dbi dbi;
|
166
|
+
char *prog = argv[0];
|
167
|
+
char *envname;
|
168
|
+
char *subname = NULL;
|
169
|
+
int alldbs = 0, envflags = 0, list = 0;
|
170
|
+
|
171
|
+
if (argc < 2) {
|
172
|
+
usage(prog);
|
173
|
+
}
|
174
|
+
|
175
|
+
/* -a: dump main DB and all subDBs
|
176
|
+
* -s: dump only the named subDB
|
177
|
+
* -n: use NOSUBDIR flag on env_open
|
178
|
+
* -p: use printable characters
|
179
|
+
* -f: write to file instead of stdout
|
180
|
+
* -v: use previous snapshot
|
181
|
+
* -V: print version and exit
|
182
|
+
* (default) dump only the main DB
|
183
|
+
*/
|
184
|
+
while ((i = getopt(argc, argv, "af:lnps:vV")) != EOF) {
|
185
|
+
switch(i) {
|
186
|
+
case 'V':
|
187
|
+
printf("%s\n", MDB_VERSION_STRING);
|
188
|
+
exit(0);
|
189
|
+
break;
|
190
|
+
case 'l':
|
191
|
+
list = 1;
|
192
|
+
/*FALLTHROUGH*/;
|
193
|
+
case 'a':
|
194
|
+
if (subname)
|
195
|
+
usage(prog);
|
196
|
+
alldbs++;
|
197
|
+
break;
|
198
|
+
case 'f':
|
199
|
+
if (freopen(optarg, "w", stdout) == NULL) {
|
200
|
+
fprintf(stderr, "%s: %s: reopen: %s\n",
|
201
|
+
prog, optarg, strerror(errno));
|
202
|
+
exit(EXIT_FAILURE);
|
203
|
+
}
|
204
|
+
break;
|
205
|
+
case 'n':
|
206
|
+
envflags |= MDB_NOSUBDIR;
|
207
|
+
break;
|
208
|
+
case 'v':
|
209
|
+
envflags |= MDB_PREVSNAPSHOT;
|
210
|
+
break;
|
211
|
+
case 'p':
|
212
|
+
mode |= PRINT;
|
213
|
+
break;
|
214
|
+
case 's':
|
215
|
+
if (alldbs)
|
216
|
+
usage(prog);
|
217
|
+
subname = optarg;
|
218
|
+
break;
|
219
|
+
default:
|
220
|
+
usage(prog);
|
221
|
+
}
|
222
|
+
}
|
223
|
+
|
224
|
+
if (optind != argc - 1)
|
225
|
+
usage(prog);
|
226
|
+
|
227
|
+
#ifdef SIGPIPE
|
228
|
+
signal(SIGPIPE, dumpsig);
|
229
|
+
#endif
|
230
|
+
#ifdef SIGHUP
|
231
|
+
signal(SIGHUP, dumpsig);
|
232
|
+
#endif
|
233
|
+
signal(SIGINT, dumpsig);
|
234
|
+
signal(SIGTERM, dumpsig);
|
235
|
+
|
236
|
+
envname = argv[optind];
|
237
|
+
rc = mdb_env_create(&env);
|
238
|
+
if (rc) {
|
239
|
+
fprintf(stderr, "mdb_env_create failed, error %d %s\n", rc, mdb_strerror(rc));
|
240
|
+
return EXIT_FAILURE;
|
241
|
+
}
|
242
|
+
|
243
|
+
if (alldbs || subname) {
|
244
|
+
mdb_env_set_maxdbs(env, 2);
|
245
|
+
}
|
246
|
+
|
247
|
+
rc = mdb_env_open(env, envname, envflags | MDB_RDONLY, 0664);
|
248
|
+
if (rc) {
|
249
|
+
fprintf(stderr, "mdb_env_open failed, error %d %s\n", rc, mdb_strerror(rc));
|
250
|
+
goto env_close;
|
251
|
+
}
|
252
|
+
|
253
|
+
rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
|
254
|
+
if (rc) {
|
255
|
+
fprintf(stderr, "mdb_txn_begin failed, error %d %s\n", rc, mdb_strerror(rc));
|
256
|
+
goto env_close;
|
257
|
+
}
|
258
|
+
|
259
|
+
rc = mdb_open(txn, subname, 0, &dbi);
|
260
|
+
if (rc) {
|
261
|
+
fprintf(stderr, "mdb_open failed, error %d %s\n", rc, mdb_strerror(rc));
|
262
|
+
goto txn_abort;
|
263
|
+
}
|
264
|
+
|
265
|
+
if (alldbs) {
|
266
|
+
MDB_cursor *cursor;
|
267
|
+
MDB_val key;
|
268
|
+
int count = 0;
|
269
|
+
|
270
|
+
rc = mdb_cursor_open(txn, dbi, &cursor);
|
271
|
+
if (rc) {
|
272
|
+
fprintf(stderr, "mdb_cursor_open failed, error %d %s\n", rc, mdb_strerror(rc));
|
273
|
+
goto txn_abort;
|
274
|
+
}
|
275
|
+
while ((rc = mdb_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
|
276
|
+
char *str;
|
277
|
+
MDB_dbi db2;
|
278
|
+
if (memchr(key.mv_data, '\0', key.mv_size))
|
279
|
+
continue;
|
280
|
+
count++;
|
281
|
+
str = malloc(key.mv_size+1);
|
282
|
+
memcpy(str, key.mv_data, key.mv_size);
|
283
|
+
str[key.mv_size] = '\0';
|
284
|
+
rc = mdb_open(txn, str, 0, &db2);
|
285
|
+
if (rc == MDB_SUCCESS) {
|
286
|
+
if (list) {
|
287
|
+
printf("%s\n", str);
|
288
|
+
list++;
|
289
|
+
} else {
|
290
|
+
rc = dumpit(txn, db2, str);
|
291
|
+
if (rc)
|
292
|
+
break;
|
293
|
+
}
|
294
|
+
mdb_close(env, db2);
|
295
|
+
}
|
296
|
+
free(str);
|
297
|
+
if (rc) continue;
|
298
|
+
}
|
299
|
+
mdb_cursor_close(cursor);
|
300
|
+
if (!count) {
|
301
|
+
fprintf(stderr, "%s: %s does not contain multiple databases\n", prog, envname);
|
302
|
+
rc = MDB_NOTFOUND;
|
303
|
+
} else if (rc == MDB_NOTFOUND) {
|
304
|
+
rc = MDB_SUCCESS;
|
305
|
+
}
|
306
|
+
} else {
|
307
|
+
rc = dumpit(txn, dbi, subname);
|
308
|
+
}
|
309
|
+
if (rc && rc != MDB_NOTFOUND)
|
310
|
+
fprintf(stderr, "%s: %s: %s\n", prog, envname, mdb_strerror(rc));
|
311
|
+
|
312
|
+
mdb_close(env, dbi);
|
313
|
+
txn_abort:
|
314
|
+
mdb_txn_abort(txn);
|
315
|
+
env_close:
|
316
|
+
mdb_env_close(env);
|
317
|
+
|
318
|
+
return rc ? EXIT_FAILURE : EXIT_SUCCESS;
|
319
|
+
}
|