lmdb 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -4
- data/Rakefile +48 -0
- data/ext/lmdb_ext/extconf.rb +27 -10
- data/ext/lmdb_ext/lmdb_ext.c +22 -8
- data/lib/lmdb/database.rb +2 -1
- data/lib/lmdb/version.rb +1 -1
- data/lmdb.gemspec +4 -1
- data/spec/lmdb_spec.rb +9 -0
- data/vendor/liblmdb/VERSION +1 -0
- data/vendor/{libraries/liblmdb → liblmdb}/lmdb.h +18 -63
- data/vendor/{libraries/liblmdb → liblmdb}/mdb.c +583 -1480
- data/vendor/{libraries/liblmdb → liblmdb}/midl.c +0 -62
- data/vendor/{libraries/liblmdb → liblmdb}/midl.h +4 -16
- metadata +7 -34
- data/CONTRIBUTORS +0 -8
- data/behaviour.org +0 -35
- data/ext/lmdb_ext/prototypes.sh +0 -4
- data/vendor/libraries/liblmdb/.gitignore +0 -24
- data/vendor/libraries/liblmdb/COPYRIGHT +0 -20
- data/vendor/libraries/liblmdb/Doxyfile +0 -1631
- data/vendor/libraries/liblmdb/LICENSE +0 -47
- data/vendor/libraries/liblmdb/Makefile +0 -118
- data/vendor/libraries/liblmdb/intro.doc +0 -192
- data/vendor/libraries/liblmdb/mdb_copy.1 +0 -61
- data/vendor/libraries/liblmdb/mdb_copy.c +0 -84
- data/vendor/libraries/liblmdb/mdb_drop.1 +0 -40
- data/vendor/libraries/liblmdb/mdb_drop.c +0 -135
- data/vendor/libraries/liblmdb/mdb_dump.1 +0 -81
- data/vendor/libraries/liblmdb/mdb_dump.c +0 -319
- data/vendor/libraries/liblmdb/mdb_load.1 +0 -84
- data/vendor/libraries/liblmdb/mdb_load.c +0 -492
- data/vendor/libraries/liblmdb/mdb_stat.1 +0 -70
- data/vendor/libraries/liblmdb/mdb_stat.c +0 -264
- data/vendor/libraries/liblmdb/mtest.c +0 -177
- data/vendor/libraries/liblmdb/mtest2.c +0 -124
- data/vendor/libraries/liblmdb/mtest3.c +0 -133
- data/vendor/libraries/liblmdb/mtest4.c +0 -168
- data/vendor/libraries/liblmdb/mtest5.c +0 -135
- data/vendor/libraries/liblmdb/mtest6.c +0 -141
- data/vendor/libraries/liblmdb/sample-bdb.txt +0 -73
- data/vendor/libraries/liblmdb/sample-mdb.txt +0 -62
- data/vendor/libraries/liblmdb/tooltag +0 -27
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
The OpenLDAP Public License
|
|
2
|
-
Version 2.8, 17 August 2003
|
|
3
|
-
|
|
4
|
-
Redistribution and use of this software and associated documentation
|
|
5
|
-
("Software"), with or without modification, are permitted provided
|
|
6
|
-
that the following conditions are met:
|
|
7
|
-
|
|
8
|
-
1. Redistributions in source form must retain copyright statements
|
|
9
|
-
and notices,
|
|
10
|
-
|
|
11
|
-
2. Redistributions in binary form must reproduce applicable copyright
|
|
12
|
-
statements and notices, this list of conditions, and the following
|
|
13
|
-
disclaimer in the documentation and/or other materials provided
|
|
14
|
-
with the distribution, and
|
|
15
|
-
|
|
16
|
-
3. Redistributions must contain a verbatim copy of this document.
|
|
17
|
-
|
|
18
|
-
The OpenLDAP Foundation may revise this license from time to time.
|
|
19
|
-
Each revision is distinguished by a version number. You may use
|
|
20
|
-
this Software under terms of this license revision or under the
|
|
21
|
-
terms of any subsequent revision of the license.
|
|
22
|
-
|
|
23
|
-
THIS SOFTWARE IS PROVIDED BY THE OPENLDAP FOUNDATION AND ITS
|
|
24
|
-
CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
25
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
26
|
-
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
27
|
-
SHALL THE OPENLDAP FOUNDATION, ITS CONTRIBUTORS, OR THE AUTHOR(S)
|
|
28
|
-
OR OWNER(S) OF THE SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
29
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
30
|
-
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
31
|
-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
32
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
33
|
-
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
34
|
-
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
35
|
-
POSSIBILITY OF SUCH DAMAGE.
|
|
36
|
-
|
|
37
|
-
The names of the authors and copyright holders must not be used in
|
|
38
|
-
advertising or otherwise to promote the sale, use or other dealing
|
|
39
|
-
in this Software without specific, written prior permission. Title
|
|
40
|
-
to copyright in this Software shall at all times remain with copyright
|
|
41
|
-
holders.
|
|
42
|
-
|
|
43
|
-
OpenLDAP is a registered trademark of the OpenLDAP Foundation.
|
|
44
|
-
|
|
45
|
-
Copyright 1999-2003 The OpenLDAP Foundation, Redwood City,
|
|
46
|
-
California, USA. All Rights Reserved. Permission to copy and
|
|
47
|
-
distribute verbatim copies of this document is granted.
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# Makefile for liblmdb (Lightning memory-mapped database library).
|
|
2
|
-
|
|
3
|
-
########################################################################
|
|
4
|
-
# Configuration. The compiler options must enable threaded compilation.
|
|
5
|
-
#
|
|
6
|
-
# Preprocessor macros (for CPPFLAGS) of interest...
|
|
7
|
-
# Note that the defaults should already be correct for most
|
|
8
|
-
# platforms; you should not need to change any of these.
|
|
9
|
-
# Read their descriptions in mdb.c if you do:
|
|
10
|
-
#
|
|
11
|
-
# - MDB_USE_POSIX_MUTEX, MDB_USE_POSIX_SEM, MDB_USE_SYSV_SEM
|
|
12
|
-
# - MDB_DSYNC
|
|
13
|
-
# - MDB_FDATASYNC
|
|
14
|
-
# - MDB_FDATASYNC_WORKS
|
|
15
|
-
# - MDB_USE_PWRITEV
|
|
16
|
-
# - MDB_USE_ROBUST
|
|
17
|
-
#
|
|
18
|
-
# There may be other macros in mdb.c of interest. You should
|
|
19
|
-
# read mdb.c before changing any of them.
|
|
20
|
-
#
|
|
21
|
-
CC = gcc
|
|
22
|
-
AR = ar
|
|
23
|
-
W = -W -Wall -Wno-unused-parameter -Wbad-function-cast -Wuninitialized
|
|
24
|
-
THREADS = -pthread
|
|
25
|
-
OPT = -O2 -g
|
|
26
|
-
CFLAGS = $(THREADS) $(OPT) $(W) $(XCFLAGS)
|
|
27
|
-
LDLIBS =
|
|
28
|
-
SOLIBS =
|
|
29
|
-
SOEXT = .so
|
|
30
|
-
prefix = /usr/local
|
|
31
|
-
exec_prefix = $(prefix)
|
|
32
|
-
bindir = $(exec_prefix)/bin
|
|
33
|
-
libdir = $(exec_prefix)/lib
|
|
34
|
-
includedir = $(prefix)/include
|
|
35
|
-
datarootdir = $(prefix)/share
|
|
36
|
-
mandir = $(datarootdir)/man
|
|
37
|
-
|
|
38
|
-
########################################################################
|
|
39
|
-
|
|
40
|
-
IHDRS = lmdb.h
|
|
41
|
-
ILIBS = liblmdb.a liblmdb$(SOEXT)
|
|
42
|
-
IPROGS = mdb_stat mdb_copy mdb_dump mdb_load mdb_drop
|
|
43
|
-
IDOCS = mdb_stat.1 mdb_copy.1 mdb_dump.1 mdb_load.1 mdb_drop.1
|
|
44
|
-
PROGS = $(IPROGS) mtest mtest2 mtest3 mtest4 mtest5
|
|
45
|
-
all: $(ILIBS) $(PROGS)
|
|
46
|
-
|
|
47
|
-
install: $(ILIBS) $(IPROGS) $(IHDRS)
|
|
48
|
-
mkdir -p $(DESTDIR)$(bindir)
|
|
49
|
-
mkdir -p $(DESTDIR)$(libdir)
|
|
50
|
-
mkdir -p $(DESTDIR)$(includedir)
|
|
51
|
-
mkdir -p $(DESTDIR)$(mandir)/man1
|
|
52
|
-
for f in $(IPROGS); do cp $$f $(DESTDIR)$(bindir); done
|
|
53
|
-
for f in $(ILIBS); do cp $$f $(DESTDIR)$(libdir); done
|
|
54
|
-
for f in $(IHDRS); do cp $$f $(DESTDIR)$(includedir); done
|
|
55
|
-
for f in $(IDOCS); do cp $$f $(DESTDIR)$(mandir)/man1; done
|
|
56
|
-
|
|
57
|
-
clean:
|
|
58
|
-
rm -rf $(PROGS) *.[ao] *.[ls]o *~ testdb
|
|
59
|
-
|
|
60
|
-
test: all
|
|
61
|
-
rm -rf testdb && mkdir testdb
|
|
62
|
-
./mtest && ./mdb_stat testdb
|
|
63
|
-
|
|
64
|
-
liblmdb.a: mdb.o midl.o
|
|
65
|
-
$(AR) rs $@ mdb.o midl.o
|
|
66
|
-
|
|
67
|
-
liblmdb$(SOEXT): mdb.lo midl.lo
|
|
68
|
-
# $(CC) $(LDFLAGS) -pthread -shared -Wl,-Bsymbolic -o $@ mdb.o midl.o $(SOLIBS)
|
|
69
|
-
$(CC) $(LDFLAGS) -pthread -shared -o $@ mdb.lo midl.lo $(SOLIBS)
|
|
70
|
-
|
|
71
|
-
mdb_stat: mdb_stat.o liblmdb.a
|
|
72
|
-
mdb_copy: mdb_copy.o liblmdb.a
|
|
73
|
-
mdb_dump: mdb_dump.o liblmdb.a
|
|
74
|
-
mdb_load: mdb_load.o liblmdb.a
|
|
75
|
-
mdb_drop: mdb_drop.o liblmdb.a
|
|
76
|
-
mtest: mtest.o liblmdb.a
|
|
77
|
-
mtest2: mtest2.o liblmdb.a
|
|
78
|
-
mtest3: mtest3.o liblmdb.a
|
|
79
|
-
mtest4: mtest4.o liblmdb.a
|
|
80
|
-
mtest5: mtest5.o liblmdb.a
|
|
81
|
-
mtest6: mtest6.o liblmdb.a
|
|
82
|
-
|
|
83
|
-
mdb.o: mdb.c lmdb.h midl.h
|
|
84
|
-
$(CC) $(CFLAGS) $(CPPFLAGS) -c mdb.c
|
|
85
|
-
|
|
86
|
-
midl.o: midl.c midl.h
|
|
87
|
-
$(CC) $(CFLAGS) $(CPPFLAGS) -c midl.c
|
|
88
|
-
|
|
89
|
-
mdb.lo: mdb.c lmdb.h midl.h
|
|
90
|
-
$(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -c mdb.c -o $@
|
|
91
|
-
|
|
92
|
-
midl.lo: midl.c midl.h
|
|
93
|
-
$(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -c midl.c -o $@
|
|
94
|
-
|
|
95
|
-
%: %.o
|
|
96
|
-
$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
|
|
97
|
-
|
|
98
|
-
%.o: %.c lmdb.h
|
|
99
|
-
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
|
|
100
|
-
|
|
101
|
-
COV_FLAGS=-fprofile-arcs -ftest-coverage
|
|
102
|
-
COV_OBJS=xmdb.o xmidl.o
|
|
103
|
-
|
|
104
|
-
coverage: xmtest
|
|
105
|
-
for i in mtest*.c [0-9]*.c; do j=`basename \$$i .c`; $(MAKE) $$j.o; \
|
|
106
|
-
gcc -o x$$j $$j.o $(COV_OBJS) -pthread $(COV_FLAGS); \
|
|
107
|
-
rm -rf testdb; mkdir testdb; ./x$$j; done
|
|
108
|
-
gcov xmdb.c
|
|
109
|
-
gcov xmidl.c
|
|
110
|
-
|
|
111
|
-
xmtest: mtest.o xmdb.o xmidl.o
|
|
112
|
-
gcc -o xmtest mtest.o xmdb.o xmidl.o -pthread $(COV_FLAGS)
|
|
113
|
-
|
|
114
|
-
xmdb.o: mdb.c lmdb.h midl.h
|
|
115
|
-
$(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -O0 $(COV_FLAGS) -c mdb.c -o $@
|
|
116
|
-
|
|
117
|
-
xmidl.o: midl.c midl.h
|
|
118
|
-
$(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -O0 $(COV_FLAGS) -c midl.c -o $@
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2015-2021 Howard Chu, Symas Corp.
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
|
6
|
-
* modification, are permitted only as authorized by the OpenLDAP
|
|
7
|
-
* Public License.
|
|
8
|
-
*
|
|
9
|
-
* A copy of this license is available in the file LICENSE in the
|
|
10
|
-
* top-level directory of the distribution or, alternatively, at
|
|
11
|
-
* <http://www.OpenLDAP.org/license.html>.
|
|
12
|
-
*/
|
|
13
|
-
/** @page starting Getting Started
|
|
14
|
-
|
|
15
|
-
LMDB is compact, fast, powerful, and robust and implements a simplified
|
|
16
|
-
variant of the BerkeleyDB (BDB) API. (BDB is also very powerful, and verbosely
|
|
17
|
-
documented in its own right.) After reading this page, the main
|
|
18
|
-
\ref mdb documentation should make sense. Thanks to Bert Hubert
|
|
19
|
-
for creating the
|
|
20
|
-
<a href="https://github.com/ahupowerdns/ahutils/blob/master/lmdb-semantics.md">
|
|
21
|
-
initial version</a> of this writeup.
|
|
22
|
-
|
|
23
|
-
Everything starts with an environment, created by #mdb_env_create().
|
|
24
|
-
Once created, this environment must also be opened with #mdb_env_open().
|
|
25
|
-
|
|
26
|
-
#mdb_env_open() gets passed a name which is interpreted as a directory
|
|
27
|
-
path. Note that this directory must exist already, it is not created
|
|
28
|
-
for you. Within that directory, a lock file and a storage file will be
|
|
29
|
-
generated. If you don't want to use a directory, you can pass the
|
|
30
|
-
#MDB_NOSUBDIR option, in which case the path you provided is used
|
|
31
|
-
directly as the data file, and another file with a "-lock" suffix
|
|
32
|
-
added will be used for the lock file.
|
|
33
|
-
|
|
34
|
-
Once the environment is open, a transaction can be created within it
|
|
35
|
-
using #mdb_txn_begin(). Transactions may be read-write or read-only,
|
|
36
|
-
and read-write transactions may be nested. A transaction must only
|
|
37
|
-
be used by one thread at a time. Transactions are always required,
|
|
38
|
-
even for read-only access. The transaction provides a consistent
|
|
39
|
-
view of the data.
|
|
40
|
-
|
|
41
|
-
Once a transaction has been created, a database can be opened within it
|
|
42
|
-
using #mdb_dbi_open(). If only one database will ever be used in the
|
|
43
|
-
environment, a NULL can be passed as the database name. For named
|
|
44
|
-
databases, the #MDB_CREATE flag must be used to create the database
|
|
45
|
-
if it doesn't already exist. Also, #mdb_env_set_maxdbs() must be
|
|
46
|
-
called after #mdb_env_create() and before #mdb_env_open() to set the
|
|
47
|
-
maximum number of named databases you want to support.
|
|
48
|
-
|
|
49
|
-
Note: a single transaction can open multiple databases. Generally
|
|
50
|
-
databases should only be opened once, by the first transaction in
|
|
51
|
-
the process. After the first transaction completes, the database
|
|
52
|
-
handles can freely be used by all subsequent transactions.
|
|
53
|
-
|
|
54
|
-
Within a transaction, #mdb_get() and #mdb_put() can store single
|
|
55
|
-
key/value pairs if that is all you need to do (but see \ref Cursors
|
|
56
|
-
below if you want to do more).
|
|
57
|
-
|
|
58
|
-
A key/value pair is expressed as two #MDB_val structures. This struct
|
|
59
|
-
has two fields, \c mv_size and \c mv_data. The data is a \c void pointer to
|
|
60
|
-
an array of \c mv_size bytes.
|
|
61
|
-
|
|
62
|
-
Because LMDB is very efficient (and usually zero-copy), the data returned
|
|
63
|
-
in an #MDB_val structure may be memory-mapped straight from disk. In
|
|
64
|
-
other words <b>look but do not touch</b> (or free() for that matter).
|
|
65
|
-
Once a transaction is closed, the values can no longer be used, so
|
|
66
|
-
make a copy if you need to keep them after that.
|
|
67
|
-
|
|
68
|
-
@section Cursors Cursors
|
|
69
|
-
|
|
70
|
-
To do more powerful things, we must use a cursor.
|
|
71
|
-
|
|
72
|
-
Within the transaction, a cursor can be created with #mdb_cursor_open().
|
|
73
|
-
With this cursor we can store/retrieve/delete (multiple) values using
|
|
74
|
-
#mdb_cursor_get(), #mdb_cursor_put(), and #mdb_cursor_del().
|
|
75
|
-
|
|
76
|
-
#mdb_cursor_get() positions itself depending on the cursor operation
|
|
77
|
-
requested, and for some operations, on the supplied key. For example,
|
|
78
|
-
to list all key/value pairs in a database, use operation #MDB_FIRST for
|
|
79
|
-
the first call to #mdb_cursor_get(), and #MDB_NEXT on subsequent calls,
|
|
80
|
-
until the end is hit.
|
|
81
|
-
|
|
82
|
-
To retrieve all keys starting from a specified key value, use #MDB_SET.
|
|
83
|
-
For more cursor operations, see the \ref mdb docs.
|
|
84
|
-
|
|
85
|
-
When using #mdb_cursor_put(), either the function will position the
|
|
86
|
-
cursor for you based on the \b key, or you can use operation
|
|
87
|
-
#MDB_CURRENT to use the current position of the cursor. Note that
|
|
88
|
-
\b key must then match the current position's key.
|
|
89
|
-
|
|
90
|
-
@subsection summary Summarizing the Opening
|
|
91
|
-
|
|
92
|
-
So we have a cursor in a transaction which opened a database in an
|
|
93
|
-
environment which is opened from a filesystem after it was
|
|
94
|
-
separately created.
|
|
95
|
-
|
|
96
|
-
Or, we create an environment, open it from a filesystem, create a
|
|
97
|
-
transaction within it, open a database within that transaction,
|
|
98
|
-
and create a cursor within all of the above.
|
|
99
|
-
|
|
100
|
-
Got it?
|
|
101
|
-
|
|
102
|
-
@section thrproc Threads and Processes
|
|
103
|
-
|
|
104
|
-
LMDB uses POSIX locks on files, and these locks have issues if one
|
|
105
|
-
process opens a file multiple times. Because of this, do not
|
|
106
|
-
#mdb_env_open() a file multiple times from a single process. Instead,
|
|
107
|
-
share the LMDB environment that has opened the file across all threads.
|
|
108
|
-
Otherwise, if a single process opens the same environment multiple times,
|
|
109
|
-
closing it once will remove all the locks held on it, and the other
|
|
110
|
-
instances will be vulnerable to corruption from other processes.
|
|
111
|
-
|
|
112
|
-
Also note that a transaction is tied to one thread by default using
|
|
113
|
-
Thread Local Storage. If you want to pass read-only transactions across
|
|
114
|
-
threads, you can use the #MDB_NOTLS option on the environment.
|
|
115
|
-
|
|
116
|
-
@section txns Transactions, Rollbacks, etc.
|
|
117
|
-
|
|
118
|
-
To actually get anything done, a transaction must be committed using
|
|
119
|
-
#mdb_txn_commit(). Alternatively, all of a transaction's operations
|
|
120
|
-
can be discarded using #mdb_txn_abort(). In a read-only transaction,
|
|
121
|
-
any cursors will \b not automatically be freed. In a read-write
|
|
122
|
-
transaction, all cursors will be freed and must not be used again.
|
|
123
|
-
|
|
124
|
-
For read-only transactions, obviously there is nothing to commit to
|
|
125
|
-
storage. The transaction still must eventually be aborted to close
|
|
126
|
-
any database handle(s) opened in it, or committed to keep the
|
|
127
|
-
database handles around for reuse in new transactions.
|
|
128
|
-
|
|
129
|
-
In addition, as long as a transaction is open, a consistent view of
|
|
130
|
-
the database is kept alive, which requires storage. A read-only
|
|
131
|
-
transaction that no longer requires this consistent view should
|
|
132
|
-
be terminated (committed or aborted) when the view is no longer
|
|
133
|
-
needed (but see below for an optimization).
|
|
134
|
-
|
|
135
|
-
There can be multiple simultaneously active read-only transactions
|
|
136
|
-
but only one that can write. Once a single read-write transaction
|
|
137
|
-
is opened, all further attempts to begin one will block until the
|
|
138
|
-
first one is committed or aborted. This has no effect on read-only
|
|
139
|
-
transactions, however, and they may continue to be opened at any time.
|
|
140
|
-
|
|
141
|
-
@section dupkeys Duplicate Keys
|
|
142
|
-
|
|
143
|
-
#mdb_get() and #mdb_put() respectively have no and only some support
|
|
144
|
-
for multiple key/value pairs with identical keys. If there are multiple
|
|
145
|
-
values for a key, #mdb_get() will only return the first value.
|
|
146
|
-
|
|
147
|
-
When multiple values for one key are required, pass the #MDB_DUPSORT
|
|
148
|
-
flag to #mdb_dbi_open(). In an #MDB_DUPSORT database, by default
|
|
149
|
-
#mdb_put() will not replace the value for a key if the key existed
|
|
150
|
-
already. Instead it will add the new value to the key. In addition,
|
|
151
|
-
#mdb_del() will pay attention to the value field too, allowing for
|
|
152
|
-
specific values of a key to be deleted.
|
|
153
|
-
|
|
154
|
-
Finally, additional cursor operations become available for
|
|
155
|
-
traversing through and retrieving duplicate values.
|
|
156
|
-
|
|
157
|
-
@section optim Some Optimization
|
|
158
|
-
|
|
159
|
-
If you frequently begin and abort read-only transactions, as an
|
|
160
|
-
optimization, it is possible to only reset and renew a transaction.
|
|
161
|
-
|
|
162
|
-
#mdb_txn_reset() releases any old copies of data kept around for
|
|
163
|
-
a read-only transaction. To reuse this reset transaction, call
|
|
164
|
-
#mdb_txn_renew() on it. Any cursors in this transaction must also
|
|
165
|
-
be renewed using #mdb_cursor_renew().
|
|
166
|
-
|
|
167
|
-
Note that #mdb_txn_reset() is similar to #mdb_txn_abort() and will
|
|
168
|
-
close any databases you opened within the transaction.
|
|
169
|
-
|
|
170
|
-
To permanently free a transaction, reset or not, use #mdb_txn_abort().
|
|
171
|
-
|
|
172
|
-
@section cleanup Cleaning Up
|
|
173
|
-
|
|
174
|
-
For read-only transactions, any cursors created within it must
|
|
175
|
-
be closed using #mdb_cursor_close().
|
|
176
|
-
|
|
177
|
-
It is very rarely necessary to close a database handle, and in
|
|
178
|
-
general they should just be left open.
|
|
179
|
-
|
|
180
|
-
@section onward The Full API
|
|
181
|
-
|
|
182
|
-
The full \ref mdb documentation lists further details, like how to:
|
|
183
|
-
|
|
184
|
-
\li size a database (the default limits are intentionally small)
|
|
185
|
-
\li drop and clean a database
|
|
186
|
-
\li detect and report errors
|
|
187
|
-
\li optimize (bulk) loading speed
|
|
188
|
-
\li (temporarily) reduce robustness to gain even more speed
|
|
189
|
-
\li gather statistics about the database
|
|
190
|
-
\li define custom sort orders
|
|
191
|
-
|
|
192
|
-
*/
|
|
@@ -1,61 +0,0 @@
|
|
|
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>
|
|
@@ -1,84 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
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>
|
|
@@ -1,135 +0,0 @@
|
|
|
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
|
-
}
|