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