aingle_lmdb/
flags.rs

1use bitflags::bitflags;
2use libc::c_uint;
3
4use crate::ffi::*;
5
6bitflags! {
7    #[doc="Environment options."]
8    #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
9    pub struct EnvironmentFlags: c_uint {
10
11        #[doc="Use a fixed address for the mmap region. This flag must be specified"]
12        #[doc="when creating the environment, and is stored persistently in the environment."]
13        #[doc="If successful, the memory map will always reside at the same virtual address"]
14        #[doc="and pointers used to reference data items in the database will be constant"]
15        #[doc="across multiple invocations. This option may not always work, depending on"]
16        #[doc="how the operating system has allocated memory to shared libraries and other uses."]
17        #[doc="The feature is highly experimental."]
18        const FIXED_MAP = MDB_FIXEDMAP;
19
20        #[doc="By default, LMDB creates its environment in a directory whose pathname is given in"]
21        #[doc="`path`, and creates its data and lock files under that directory. With this option,"]
22        #[doc="`path` is used as-is for the database main data file. The database lock file is the"]
23        #[doc="`path` with `-lock` appended."]
24        const NO_SUB_DIR = MDB_NOSUBDIR;
25
26        #[doc="Use a writeable memory map unless `READ_ONLY` is set. This is faster and uses"]
27        #[doc="fewer mallocs, but loses protection from application bugs like wild pointer writes"]
28        #[doc="and other bad updates into the database. Incompatible with nested transactions."]
29        #[doc="Processes with and without `WRITE_MAP` on the same environment do not cooperate"]
30        #[doc="well."]
31        const WRITE_MAP = MDB_WRITEMAP;
32
33        #[doc="Open the environment in read-only mode. No write operations will be allowed."]
34        #[doc="When opening an environment, LMDB will still modify the lock file - except on"]
35        #[doc="read-only filesystems, where LMDB does not use locks."]
36        const READ_ONLY = MDB_RDONLY;
37
38        #[doc="Flush system buffers to disk only once per transaction, omit the metadata flush."]
39        #[doc="Defer that until the system flushes files to disk, or next non-`READ_ONLY` commit"]
40        #[doc="or `Environment::sync`. This optimization maintains database integrity, but a"]
41        #[doc="system crash may undo the last committed transaction. I.e. it preserves the ACI"]
42        #[doc="(atomicity, consistency, isolation) but not D (durability) database property."]
43        #[doc="\n\nThis flag may be changed at any time using `Environment::set_flags`."]
44        const NO_META_SYNC = MDB_NOMETASYNC;
45
46        #[doc="Don't flush system buffers to disk when committing a transaction. This optimization"]
47        #[doc="means a system crash can corrupt the database or lose the last transactions if"]
48        #[doc="buffers are not yet flushed to disk. The risk is governed by how often the system"]
49        #[doc="flushes dirty buffers to disk and how often `Environment::sync` is called. However,"]
50        #[doc="if the filesystem preserves write order and the `WRITE_MAP` flag is not used,"]
51        #[doc="transactions exhibit ACI (atomicity, consistency, isolation) properties and only"]
52        #[doc="lose D (durability). I.e. database integrity is maintained, but a system"]
53        #[doc="crash may undo the final transactions. Note that (`NO_SYNC | WRITE_MAP`) leaves the"]
54        #[doc="system with no hint for when to write transactions to disk, unless"]
55        #[doc="`Environment::sync` is called. (`MAP_ASYNC | WRITE_MAP`) may be preferable."]
56        #[doc="\n\nThis flag may be changed at any time using `Environment::set_flags`."]
57        const NO_SYNC = MDB_NOSYNC;
58
59        #[doc="When using `WRITE_MAP`, use asynchronous flushes to disk. As with `NO_SYNC`, a"]
60        #[doc="system crash can then corrupt the database or lose the last transactions. Calling"]
61        #[doc="`Environment::sync` ensures on-disk database integrity until next commit."]
62        #[doc="\n\nThis flag may be changed at any time using `Environment::set_flags`."]
63        const MAP_ASYNC = MDB_MAPASYNC;
64
65        #[doc="Don't use thread-local storage. Tie reader locktable slots to transaction objects"]
66        #[doc="instead of to threads. I.e. `RoTransaction::reset` keeps the slot reserved for the"]
67        #[doc="transaction object. A thread may use parallel read-only transactions. A read-only"]
68        #[doc="transaction may span threads if the user synchronizes its use. Applications that"]
69        #[doc="multiplex many the user synchronizes its use. Applications that multiplex many user"]
70        #[doc="threads over individual OS threads need this option. Such an application must also"]
71        #[doc="serialize the write transactions in an OS thread, since LMDB's write locking is"]
72        #[doc="unaware of the user threads."]
73        const NO_TLS = MDB_NOTLS;
74
75        #[doc="Do not do any locking. If concurrent access is anticipated, the caller must manage"]
76        #[doc="all concurrency themself. For proper operation the caller must enforce"]
77        #[doc="single-writer semantics, and must ensure that no readers are using old"]
78        #[doc="transactions while a writer is active. The simplest approach is to use an exclusive"]
79        #[doc="lock so that no readers may be active at all when a writer begins."]
80        const NO_LOCK = MDB_NOLOCK;
81
82        #[doc="Turn off readahead. Most operating systems perform readahead on read requests by"]
83        #[doc="default. This option turns it off if the OS supports it. Turning it off may help"]
84        #[doc="random read performance when the DB is larger than RAM and system RAM is full."]
85        #[doc="The option is not implemented on Windows."]
86        const NO_READAHEAD = MDB_NORDAHEAD;
87
88        #[doc="Do not initialize malloc'd memory before writing to unused spaces in the data file."]
89        #[doc="By default, memory for pages written to the data file is obtained using malloc."]
90        #[doc="While these pages may be reused in subsequent transactions, freshly malloc'd pages"]
91        #[doc="will be initialized to zeroes before use. This avoids persisting leftover data from"]
92        #[doc="other code (that used the heap and subsequently freed the memory) into the data"]
93        #[doc="file. Note that many other system libraries may allocate and free memory from the"]
94        #[doc="heap for arbitrary uses. E.g., stdio may use the heap for file I/O buffers. This"]
95        #[doc="initialization step has a modest performance cost so some applications may want to"]
96        #[doc="disable it using this flag. This option can be a problem for applications which"]
97        #[doc="handle sensitive data like passwords, and it makes memory checkers like Valgrind"]
98        #[doc="noisy. This flag is not needed with `WRITE_MAP`, which writes directly to the mmap"]
99        #[doc="instead of using malloc for pages. The initialization is also skipped if writing"]
100        #[doc="with reserve; the caller is expected to overwrite all of the memory that was"]
101        #[doc="reserved in that case."]
102        #[doc="\n\nThis flag may be changed at any time using `Environment::set_flags`."]
103        const NO_MEM_INIT = MDB_NOMEMINIT;
104    }
105}
106
107bitflags! {
108    #[doc="Database options."]
109    #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
110    pub struct DatabaseFlags: c_uint {
111
112        #[doc="Keys are strings to be compared in reverse order, from the end of the strings"]
113        #[doc="to the beginning. By default, Keys are treated as strings and compared from"]
114        #[doc="beginning to end."]
115        const REVERSE_KEY = MDB_REVERSEKEY;
116
117        #[doc="Duplicate keys may be used in the database. (Or, from another perspective,"]
118        #[doc="keys may have multiple data items, stored in sorted order.) By default"]
119        #[doc="keys must be unique and may have only a single data item."]
120        const DUP_SORT = MDB_DUPSORT;
121
122        #[doc="Keys are binary integers in native byte order. Setting this option requires all"]
123        #[doc="keys to be the same size, typically 32 or 64 bits."]
124        const INTEGER_KEY = MDB_INTEGERKEY;
125
126        #[doc="This flag may only be used in combination with `DUP_SORT`. This option tells"]
127        #[doc="the library that the data items for this database are all the same size, which"]
128        #[doc="allows further optimizations in storage and retrieval. When all data items are"]
129        #[doc="the same size, the `GET_MULTIPLE` and `NEXT_MULTIPLE` cursor operations may be"]
130        #[doc="used to retrieve multiple items at once."]
131        const DUP_FIXED = MDB_DUPFIXED;
132
133        #[doc="This option specifies that duplicate data items are also integers, and"]
134        #[doc="should be sorted as such."]
135        const INTEGER_DUP = MDB_INTEGERDUP;
136
137        #[doc="This option specifies that duplicate data items should be compared as strings"]
138        #[doc="in reverse order."]
139        const REVERSE_DUP = MDB_REVERSEDUP;
140    }
141}
142
143bitflags! {
144    #[doc="Write options."]
145    #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
146    pub struct WriteFlags: c_uint {
147
148        #[doc="Insert the new item only if the key does not already appear in the database."]
149        #[doc="The function will return `LmdbError::KeyExist` if the key already appears in the"]
150        #[doc="database, even if the database supports duplicates (`DUP_SORT`)."]
151        const NO_OVERWRITE = MDB_NOOVERWRITE;
152
153        #[doc="Insert the new item only if it does not already appear in the database."]
154        #[doc="This flag may only be specified if the database was opened with `DUP_SORT`."]
155        #[doc="The function will return `LmdbError::KeyExist` if the item already appears in the"]
156        #[doc="database."]
157        const NO_DUP_DATA = MDB_NODUPDATA;
158
159        #[doc="For `Cursor::put`. Replace the item at the current cursor position. The key"]
160        #[doc="parameter must match the current position. If using sorted duplicates (`DUP_SORT`)"]
161        #[doc="the data item must still sort into the same position. This is intended to be used"]
162        #[doc="when the new data is the same size as the old. Otherwise it will simply perform a"]
163        #[doc="delete of the old record followed by an insert."]
164        const CURRENT = MDB_CURRENT;
165
166        #[doc="Append the given item to the end of the database. No key comparisons are performed."]
167        #[doc="This option allows fast bulk loading when keys are already known to be in the"]
168        #[doc="correct order. Loading unsorted keys with this flag will cause data corruption."]
169        const APPEND = MDB_APPEND;
170
171        #[doc="Same as `APPEND`, but for sorted dup data."]
172        const APPEND_DUP = MDB_APPENDDUP;
173    }
174}