diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5df7e0c4..f602afee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,22 +3,16 @@ on: [pull_request] name: Cargo test jobs: - check_lmdb: - name: Test the heed project with LMDB + check: + name: Test the heed project runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] include: - os: ubuntu-latest - artifact_name: meilidb-http - asset_name: meilidb-http-linux-amd64 - os: windows-latest - artifact_name: meilidb-http.exe - asset_name: meilidb-http-windows-amd64 - os: macos-latest - artifact_name: meilidb-http-macos-amd64 - asset_name: meilidb-http-macos-amd64 steps: - uses: actions/checkout@v2 @@ -29,39 +23,8 @@ jobs: override: true - name: Run cargo test run: | - cd heed cargo clean - cargo test --features 'lmdb serde-json' --no-default-features - - check_mdbx: - name: Test the heed project with MDBX - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - include: - - os: ubuntu-latest - artifact_name: meilidb-http - asset_name: meilidb-http-linux-amd64 - - os: windows-latest - artifact_name: meilidb-http.exe - asset_name: meilidb-http-windows-amd64 - - os: macos-latest - artifact_name: meilidb-http-macos-amd64 - asset_name: meilidb-http-macos-amd64 - - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - name: Run cargo test - run: | - cd heed - cargo clean - cargo test --features 'mdbx serde-json' --no-default-features + cargo test fmt: name: Ensure the heed project is formatted diff --git a/README.md b/README.md index 3242a1b4..16bdbcf2 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,15 @@ # heed -A fully typed [LMDB]/[MDBX] wrapper with minimum overhead, uses zerocopy internally. +A fully typed [LMDB](https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database) wrapper with minimum overhead, uses zerocopy internally. -[![Build Status](https://dev.azure.com/renaultcle/heed/_apis/build/status/Kerollmops.heed?branchName=master)](https://dev.azure.com/renaultcle/heed/_build/latest?definitionId=1&branchName=master) -[![Dependency Status](https://deps.rs/repo/github/Kerollmops/heed/status.svg)](https://deps.rs/repo/github/Kerollmops/heed) -[![Heed Doc](https://docs.rs/heed/badge.svg)](https://docs.rs/heed) -[![Crates.io](https://img.shields.io/crates/v/heed.svg)](https://crates.io/crates/heed) +[![License](https://img.shields.io/badge/license-MIT-green)](#LICENSE) +[![Crates.io](https://img.shields.io/crates/v/heed)](https://crates.io/crates/heed) +[![Docs](https://docs.rs/heed/badge.svg)](https://docs.rs/heed) +[![dependency status](https://deps.rs/repo/github/meilisearch/heed/status.svg)](https://deps.rs/repo/github/meilisearch/heed) +[![Build](https://github.com/meilisearch/heed/actions/workflows/test.yml/badge.svg)](https://github.com/meilisearch/heed/actions/workflows/test.yml) ![the opposite of heed](https://thesaurus.plus/img/antonyms/153/heed.png) -This library is able to serialize all kind of types, not just bytes slices, even Serde types are supported. - -## Using MDBX instead of LMDB - -Heed can also [be used with MDBX][MDBX], this is a compatible backend, you can activate it by using the `mdbx` feature. When MDBX is used the generated databases cannot be read by using the `lmdb` feature, those two kv-stores are not compatible and vice-versa. - -Notice that some specific features will only be accessible by using the `mdbx` cargo feature. -Environment creation flags depends on the backend you chose. - -To test that heed works with MDBX you can run this command: - -```bash -cargo test --features 'mdbx serde-json' --no-default-features -``` +This library is able to serialize all kind of types, not just bytes slices, even _Serde_ types are supported. ## Example Usage @@ -56,6 +44,3 @@ assert_eq!(ret, Some(5)); ``` You want to see more about all the possibilities? Go check out [the examples](heed/examples/). - -[LMDB]: https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database -[MDBX]: https://github.com/erthink/libmdbx diff --git a/heed/Cargo.toml b/heed/Cargo.toml index cb7e1713..19aabae2 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -15,8 +15,7 @@ byteorder = { version = "1.3.4", default-features = false } heed-traits = { version = "0.7.0", path = "../heed-traits" } heed-types = { version = "0.7.2", path = "../heed-types" } libc = "0.2.80" -lmdb-rkv-sys = { git = "https://github.com/meilisearch/lmdb-rs", optional = true } -mdbx-sys = { version = "0.7.1", optional = true } +lmdb-rkv-sys = { git = "https://github.com/meilisearch/lmdb-rs" } once_cell = "1.5.2" page_size = "0.4.2" serde = { version = "1.0.118", features = ["derive"], optional = true } @@ -33,20 +32,13 @@ url = "2.2.0" [features] # The `serde` feature makes some types serializable, # like the `EnvOpenOptions` struct. -default = ["lmdb", "serde", "serde-bincode", "serde-json"] +default = ["serde", "serde-bincode", "serde-json"] # The NO_TLS flag is automatically set on Env opening and # RoTxn implements the Sync trait. This allow the user to reference # a read-only transaction from multiple threads at the same time. sync-read-txn = [] -# Choose between using the MDBX key-value store or LMDB -# MDBX is a fork of LMDB: https://github.com/erthink/libmdbx -# -# You cannot use both features at the same time, you have to choose! -lmdb = ["lmdb-rkv-sys"] -mdbx = ["mdbx-sys"] - # Enable the serde en/decoders for bincode or serde_json serde-bincode = ["heed-types/serde", "heed-types/bincode"] serde-json = ["heed-types/serde", "heed-types/serde_json"] diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index c2d7264f..684855a0 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -113,122 +113,6 @@ impl PolyDatabase { PolyDatabase { env_ident, dbi } } - /// Retrieve the sequence of a database. - /// - /// This function allows to retrieve the unique positive integer of this database. - /// - /// ``` - /// # use std::fs; - /// # use std::path::Path; - /// # use heed::EnvOpenOptions; - /// use heed::Database; - /// use heed::types::*; - /// - /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; - /// # let env = EnvOpenOptions::new() - /// # .map_size(10 * 1024 * 1024) // 10MB - /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; - /// let db = env.create_poly_database(Some("use-sequence-1"))?; - /// - /// // The sequence starts at zero - /// let rtxn = env.read_txn()?; - /// let ret = db.sequence(&rtxn)?; - /// assert_eq!(ret, 0); - /// rtxn.abort()?; - /// - /// let mut wtxn = env.write_txn()?; - /// # db.clear(&mut wtxn)?; - /// let incr = db.increase_sequence(&mut wtxn, 32)?; - /// assert_eq!(incr, Some(0)); - /// let incr = db.increase_sequence(&mut wtxn, 28)?; - /// assert_eq!(incr, Some(32)); - /// wtxn.commit()?; - /// - /// let rtxn = env.read_txn()?; - /// let ret = db.sequence(&rtxn)?; - /// assert_eq!(ret, 60); - /// - /// # Ok(()) } - /// ``` - #[cfg(all(feature = "mdbx", not(feature = "lmdb")))] - pub fn sequence(&self, txn: &RoTxn) -> Result { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); - - let mut value = mem::MaybeUninit::uninit(); - - let result = unsafe { - mdb_result(ffi::mdbx_dbi_sequence( - txn.txn, - self.dbi, - value.as_mut_ptr(), - 0, // increment must be 0 for read-only transactions - )) - }; - - match result { - Ok(()) => unsafe { Ok(value.assume_init()) }, - Err(e) => Err(e.into()), - } - } - - /// Increment the sequence of a database. - /// - /// This function allows to create a linear sequence of a unique positive integer - /// for this database. Sequence changes become visible outside the current write - /// transaction after it is committed, and discarded on abort. - /// - /// Returns `Some` with the previous value and `None` if increasing the value - /// resulted in an overflow an therefore cannot be executed. - /// - /// ``` - /// # use std::fs; - /// # use std::path::Path; - /// # use heed::EnvOpenOptions; - /// use heed::Database; - /// use heed::types::*; - /// - /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; - /// # let env = EnvOpenOptions::new() - /// # .map_size(10 * 1024 * 1024) // 10MB - /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; - /// let db = env.create_poly_database(Some("use-sequence-2"))?; - /// - /// let mut wtxn = env.write_txn()?; - /// let incr = db.increase_sequence(&mut wtxn, 32)?; - /// assert_eq!(incr, Some(0)); - /// let incr = db.increase_sequence(&mut wtxn, 28)?; - /// assert_eq!(incr, Some(32)); - /// wtxn.commit()?; - /// - /// let rtxn = env.read_txn()?; - /// let ret = db.sequence(&rtxn)?; - /// assert_eq!(ret, 60); - /// - /// # Ok(()) } - /// ``` - #[cfg(all(feature = "mdbx", not(feature = "lmdb")))] - pub fn increase_sequence(&self, txn: &mut RwTxn, increment: u64) -> Result> { - assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); - - use crate::mdb::error::Error; - - let mut value = mem::MaybeUninit::uninit(); - - let result = unsafe { - mdb_result(ffi::mdbx_dbi_sequence(txn.txn.txn, self.dbi, value.as_mut_ptr(), increment)) - }; - - match result { - Ok(()) => unsafe { Ok(Some(value.assume_init())) }, - Err(Error::Other(c)) if c == i32::max_value() => Ok(None), // MDBX_RESULT_TRUE - Err(e) => Err(e.into()), - } - } - /// Retrieves the value associated with a key. /// /// If the key does not exist, then `None` is returned. diff --git a/heed/src/db/uniform.rs b/heed/src/db/uniform.rs index 74f54054..13a44512 100644 --- a/heed/src/db/uniform.rs +++ b/heed/src/db/uniform.rs @@ -124,29 +124,6 @@ impl Database { Database { dyndb: PolyDatabase::new(env_ident, dbi), marker: std::marker::PhantomData } } - /// Retrieve the sequence of a database. - /// - /// This function allows to retrieve the unique positive integer of this database. - /// You can see an example usage on the `PolyDatabase::sequence` method documentation. - #[cfg(all(feature = "mdbx", not(feature = "lmdb")))] - pub fn sequence(&self, txn: &RoTxn) -> Result { - self.dyndb.sequence(txn) - } - - /// Increment the sequence of a database. - /// - /// This function allows to create a linear sequence of a unique positive integer - /// for this database. Sequence changes become visible outside the current write - /// transaction after it is committed, and discarded on abort. - /// You can see an example usage on the `PolyDatabase::increase_sequence` method documentation. - /// - /// Returns `Some` with the previous value and `None` if increasing the value - /// resulted in an overflow an therefore cannot be executed. - #[cfg(all(feature = "mdbx", not(feature = "lmdb")))] - pub fn increase_sequence(&self, txn: &mut RwTxn, increment: u64) -> Result> { - self.dyndb.increase_sequence(txn, increment) - } - /// Retrieves the value associated with a key. /// /// If the key does not exist, then `None` is returned. diff --git a/heed/src/env.rs b/heed/src/env.rs index 0dc4b8c9..878229ac 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -464,20 +464,12 @@ impl Env { Ok(()) } - #[cfg(all(feature = "lmdb", not(feature = "mdbx")))] pub fn force_sync(&self) -> Result<()> { unsafe { mdb_result(ffi::mdb_env_sync(self.0.env, 1))? } Ok(()) } - #[cfg(all(feature = "mdbx", not(feature = "lmdb")))] - pub fn force_sync(&self) -> Result<()> { - unsafe { mdb_result(ffi::mdb_env_sync(self.0.env))? } - - Ok(()) - } - /// Returns the canonicalized path where this env lives. pub fn path(&self) -> &Path { &self.0.path diff --git a/heed/src/mdb/mdbx_error.rs b/heed/src/mdb/mdbx_error.rs index 8a560719..e69de29b 100644 --- a/heed/src/mdb/mdbx_error.rs +++ b/heed/src/mdb/mdbx_error.rs @@ -1,201 +0,0 @@ -use std::error::Error as StdError; -use std::ffi::CStr; -use std::os::raw::c_char; -use std::{fmt, str}; - -use libc::c_int; -use mdbx_sys as ffi; - -/// An LMDB error kind. -#[derive(Debug, Copy, Clone, Eq, PartialEq)] -pub enum Error { - /// key/data pair already exists - KeyExist, - /// key/data pair not found (EOF) - NotFound, - /// Requested page not found - this usually indicates corruption - PageNotfound, - /// Database is corrupted (page was wrong type and so on) - Corrupted, - /// Environment had fatal error (i.e. update of meta page failed and so on) - Panic, - /// DB file version mismatch with libmdbx - VersionMismatch, - /// File is not a valid MDBX file - Invalid, - /// Environment mapsize reached - MapFull, - /// Environment maxdbs reached - DbsFull, - /// Environment maxreaders reached - ReadersFull, - /// Transaction has too many dirty pages, i.e transaction too big - TxnFull, - /// Cursor stack too deep - internal error - CursorFull, - /// Page has not enough space - internal error - PageFull, - /// Database engine was unable to extend mapping, e.g. since address space - /// is unavailable or busy. This can mean: - /// - Database size extended by other process beyond to environment mapsize - /// and engine was unable to extend mapping while starting read transaction. - /// Environment should be reopened to continue. - /// - Engine was unable to extend mapping during write transaction - /// or explicit call of mdbx_env_set_geometry(). - UnableExtendMapSize, - /// Environment or database is not compatible with the requested operation - /// or the specified flags. This can mean: - /// - The operation expects an MDBX_DUPSORT / MDBX_DUPFIXED database. - /// - Opening a named DB when the unnamed DB has MDBX_DUPSORT/MDBX_INTEGERKEY. - /// - Accessing a data record as a database, or vice versa. - /// - The database was dropped and recreated with different flags. - Incompatible, - /// Invalid reuse of reader locktable slot, - /// e.g. read-transaction already run for current thread - BadRslot, - /// Transaction is not valid for requested operation, - /// e.g. had errored and be must aborted, has a child, or is invalid - BadTxn, - /// Invalid size or alignment of key or data for target database, - /// either invalid subDB name - BadValSize, - /// The specified DBI-handle is invalid - /// or changed by another thread/transaction - BadDbi, - /// Unexpected internal error, transaction should be aborted - Problem, - /// Another write transaction is running or environment is already used while - /// opening with MDBX_EXCLUSIVE flag */ - Busy, - /// The specified key has more than one associated value - MultiVal, - /// Bad signature of a runtime object(s), this can mean: - /// - memory corruption or double-free; - /// - ABI version mismatch (rare case); - BadSign, - /// Database should be recovered, but this could NOT be done for now - /// since it opened in read-only mode - WannaRecovery, - /// The given key value is mismatched to the current cursor position - KeyMismatch, - /// Database is too large for current system, - /// e.g. could NOT be mapped into RAM. - TooLarge, - /// A thread has attempted to use a not owned object, - /// e.g. a transaction that started by another thread. - ThreadMismatch, - /// Overlapping read and write transactions for the current thread - TxnOverlapping, - /// Other error. - Other(c_int), -} - -impl Error { - pub fn not_found(&self) -> bool { - *self == Error::NotFound - } - - /// Converts a raw error code to an `Error`. - pub fn from_err_code(err_code: c_int) -> Error { - match err_code { - ffi::MDBX_KEYEXIST => Error::KeyExist, - ffi::MDBX_NOTFOUND => Error::NotFound, - ffi::MDBX_PAGE_NOTFOUND => Error::PageNotfound, - ffi::MDBX_CORRUPTED => Error::Corrupted, - ffi::MDBX_PANIC => Error::Panic, - ffi::MDBX_VERSION_MISMATCH => Error::VersionMismatch, - ffi::MDBX_INVALID => Error::Invalid, - ffi::MDBX_MAP_FULL => Error::MapFull, - ffi::MDBX_DBS_FULL => Error::DbsFull, - ffi::MDBX_READERS_FULL => Error::ReadersFull, - ffi::MDBX_TXN_FULL => Error::TxnFull, - ffi::MDBX_CURSOR_FULL => Error::CursorFull, - ffi::MDBX_PAGE_FULL => Error::PageFull, - ffi::MDBX_UNABLE_EXTEND_MAPSIZE => Error::UnableExtendMapSize, - ffi::MDBX_INCOMPATIBLE => Error::Incompatible, - ffi::MDBX_BAD_RSLOT => Error::BadRslot, - ffi::MDBX_BAD_TXN => Error::BadTxn, - ffi::MDBX_BAD_VALSIZE => Error::BadValSize, - ffi::MDBX_BAD_DBI => Error::BadDbi, - ffi::MDBX_PROBLEM => Error::Problem, - ffi::MDBX_BUSY => Error::Busy, - ffi::MDBX_EMULTIVAL => Error::MultiVal, - ffi::MDBX_EBADSIGN => Error::BadSign, - ffi::MDBX_WANNA_RECOVERY => Error::WannaRecovery, - ffi::MDBX_EKEYMISMATCH => Error::KeyMismatch, - ffi::MDBX_TOO_LARGE => Error::TooLarge, - ffi::MDBX_THREAD_MISMATCH => Error::ThreadMismatch, - ffi::MDBX_TXN_OVERLAPPING => Error::TxnOverlapping, - other => Error::Other(other), - } - } - - /// Converts an `Error` to the raw error code. - #[allow(clippy::trivially_copy_pass_by_ref)] - pub fn to_err_code(&self) -> c_int { - match *self { - Error::KeyExist => ffi::MDBX_KEYEXIST, - Error::NotFound => ffi::MDBX_NOTFOUND, - Error::PageNotfound => ffi::MDBX_PAGE_NOTFOUND, - Error::Corrupted => ffi::MDBX_CORRUPTED, - Error::Panic => ffi::MDBX_PANIC, - Error::VersionMismatch => ffi::MDBX_VERSION_MISMATCH, - Error::Invalid => ffi::MDBX_INVALID, - Error::MapFull => ffi::MDBX_MAP_FULL, - Error::DbsFull => ffi::MDBX_DBS_FULL, - Error::ReadersFull => ffi::MDBX_READERS_FULL, - Error::TxnFull => ffi::MDBX_TXN_FULL, - Error::CursorFull => ffi::MDBX_CURSOR_FULL, - Error::PageFull => ffi::MDBX_PAGE_FULL, - Error::UnableExtendMapSize => ffi::MDBX_UNABLE_EXTEND_MAPSIZE, - Error::Incompatible => ffi::MDBX_INCOMPATIBLE, - Error::BadRslot => ffi::MDBX_BAD_RSLOT, - Error::BadTxn => ffi::MDBX_BAD_TXN, - Error::BadValSize => ffi::MDBX_BAD_VALSIZE, - Error::BadDbi => ffi::MDBX_BAD_DBI, - Error::Problem => ffi::MDBX_PROBLEM, - Error::Busy => ffi::MDBX_BUSY, - Error::MultiVal => ffi::MDBX_EMULTIVAL, - Error::BadSign => ffi::MDBX_EBADSIGN, - Error::WannaRecovery => ffi::MDBX_WANNA_RECOVERY, - Error::KeyMismatch => ffi::MDBX_EKEYMISMATCH, - Error::TooLarge => ffi::MDBX_TOO_LARGE, - Error::ThreadMismatch => ffi::MDBX_THREAD_MISMATCH, - Error::TxnOverlapping => ffi::MDBX_TXN_OVERLAPPING, - Error::Other(err_code) => err_code, - } - } -} - -impl fmt::Display for Error { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - let description = unsafe { - // This is safe since the error messages returned from mdb_strerror are static. - let err: *const c_char = ffi::mdbx_strerror(self.to_err_code()) as *const c_char; - str::from_utf8_unchecked(CStr::from_ptr(err).to_bytes()) - }; - - fmt.write_str(description) - } -} - -impl StdError for Error {} - -pub fn mdb_result(err_code: c_int) -> Result<(), Error> { - if err_code == ffi::MDBX_SUCCESS { - Ok(()) - } else { - Err(Error::from_err_code(err_code)) - } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_description() { - assert_eq!("Permission denied", Error::from_err_code(13).to_string()); - assert_eq!("MDBX_NOTFOUND: No matching key/data pair found", Error::NotFound.to_string()); - } -} diff --git a/heed/src/mdb/mdbx_ffi.rs b/heed/src/mdb/mdbx_ffi.rs index 26b2f046..e69de29b 100644 --- a/heed/src/mdb/mdbx_ffi.rs +++ b/heed/src/mdb/mdbx_ffi.rs @@ -1,35 +0,0 @@ -pub use ffi::{ - mdbx_cursor_close as mdb_cursor_close, mdbx_cursor_del as mdb_cursor_del, - mdbx_cursor_get as mdb_cursor_get, mdbx_cursor_open as mdb_cursor_open, - mdbx_cursor_put as mdb_cursor_put, mdbx_dbi_open as mdb_dbi_open, mdbx_dbi_sequence, - mdbx_del as mdb_del, mdbx_drop as mdb_drop, mdbx_env_close as mdb_env_close, - mdbx_env_copy2fd as mdb_env_copy2fd, mdbx_env_create as mdb_env_create, - mdbx_env_open as mdb_env_open, mdbx_env_set_mapsize as mdb_env_set_mapsize, - mdbx_env_set_maxdbs as mdb_env_set_maxdbs, mdbx_env_set_maxreaders as mdb_env_set_maxreaders, - mdbx_env_sync as mdb_env_sync, mdbx_filehandle_t as mdb_filehandle_t, mdbx_get as mdb_get, - mdbx_put as mdb_put, mdbx_txn_abort as mdb_txn_abort, mdbx_txn_begin as mdb_txn_begin, - mdbx_txn_commit as mdb_txn_commit, MDBX_cursor as MDB_cursor, MDBX_dbi as MDB_dbi, - MDBX_env as MDB_env, MDBX_txn as MDB_txn, MDBX_APPEND as MDB_APPEND, - MDBX_CP_COMPACT as MDB_CP_COMPACT, MDBX_CREATE as MDB_CREATE, MDBX_CURRENT as MDB_CURRENT, - MDBX_RDONLY as MDB_RDONLY, -}; -use mdbx_sys as ffi; - -pub mod cursor_op { - use super::ffi::MDBX_cursor_op; - - pub const MDB_FIRST: MDBX_cursor_op = MDBX_cursor_op::MDBX_FIRST; - pub const MDB_LAST: MDBX_cursor_op = MDBX_cursor_op::MDBX_LAST; - pub const MDB_SET_RANGE: MDBX_cursor_op = MDBX_cursor_op::MDBX_SET_RANGE; - pub const MDB_PREV: MDBX_cursor_op = MDBX_cursor_op::MDBX_PREV; - pub const MDB_NEXT: MDBX_cursor_op = MDBX_cursor_op::MDBX_NEXT; - pub const MDB_GET_CURRENT: MDBX_cursor_op = MDBX_cursor_op::MDBX_GET_CURRENT; -} - -pub unsafe fn into_val(value: &[u8]) -> ffi::MDBX_val { - ffi::MDBX_val { iov_base: value.as_ptr() as *mut libc::c_void, iov_len: value.len() } -} - -pub unsafe fn from_val<'a>(value: ffi::MDBX_val) -> &'a [u8] { - std::slice::from_raw_parts(value.iov_base as *const u8, value.iov_len) -} diff --git a/heed/src/mdb/mdbx_flags.rs b/heed/src/mdb/mdbx_flags.rs deleted file mode 100644 index 807c0180..00000000 --- a/heed/src/mdb/mdbx_flags.rs +++ /dev/null @@ -1,12 +0,0 @@ -// MDBX flags (see https://github.com/erthink/libmdbx/blob/master/mdbx.h for more details). -#[repr(u32)] -pub enum Flags { - MdbNoSubDir = mdbx_sys::MDBX_NOSUBDIR, - MdbRdOnly = mdbx_sys::MDBX_RDONLY, - MdbNoMetaSync = mdbx_sys::MDBX_NOMETASYNC, - MdbWriteMap = mdbx_sys::MDBX_WRITEMAP, - MdbMapAsync = mdbx_sys::MDBX_MAPASYNC, - MdbNoTls = mdbx_sys::MDBX_NOTLS, - MdbNoRdAhead = mdbx_sys::MDBX_NORDAHEAD, - MdbNoMemInit = mdbx_sys::MDBX_NOMEMINIT, -} diff --git a/heed/src/mdb/mod.rs b/heed/src/mdb/mod.rs index df35a669..f73d1623 100644 --- a/heed/src/mdb/mod.rs +++ b/heed/src/mdb/mod.rs @@ -1,33 +1,5 @@ -// MDBX - -#[cfg(feature = "mdbx")] -pub mod mdbx_error; -#[cfg(feature = "mdbx")] -pub use self::mdbx_error as error; - -#[cfg(feature = "mdbx")] -pub mod mdbx_ffi; -#[cfg(feature = "mdbx")] -pub use self::mdbx_ffi as ffi; - -#[cfg(feature = "mdbx")] -pub mod mdbx_flags; -#[cfg(feature = "mdbx")] -pub use self::mdbx_flags as flags; - -// LMDB - -#[cfg(feature = "lmdb")] pub mod lmdb_error; -#[cfg(feature = "lmdb")] -pub use self::lmdb_error as error; - -#[cfg(feature = "lmdb")] pub mod lmdb_ffi; -#[cfg(feature = "lmdb")] -pub use self::lmdb_ffi as ffi; - -#[cfg(feature = "lmdb")] pub mod lmdb_flags; -#[cfg(feature = "lmdb")] -pub use self::lmdb_flags as flags; + +pub use self::{lmdb_error as error, lmdb_ffi as ffi, lmdb_flags as flags}; diff --git a/heed/src/txn.rs b/heed/src/txn.rs index cd111680..b6f9c202 100644 --- a/heed/src/txn.rs +++ b/heed/src/txn.rs @@ -51,22 +51,12 @@ impl Drop for RoTxn<'_, T> { #[cfg(feature = "sync-read-txn")] unsafe impl Sync for RoTxn<'_, T> {} -#[cfg(all(feature = "lmdb", not(feature = "mdbx")))] fn abort_txn(txn: *mut ffi::MDB_txn) -> Result<()> { // Asserts that the transaction hasn't been already committed. assert!(!txn.is_null()); Ok(unsafe { ffi::mdb_txn_abort(txn) }) } -#[cfg(all(feature = "mdbx", not(feature = "lmdb")))] -fn abort_txn(txn: *mut ffi::MDB_txn) -> Result<()> { - // Asserts that the transaction hasn't been already committed. - assert!(!txn.is_null()); - - let ret = unsafe { ffi::mdb_txn_abort(txn) }; - mdb_result(ret).map_err(Into::into) -} - pub struct RwTxn<'e, 'p, T = ()> { pub(crate) txn: RoTxn<'e, T>, _parent: marker::PhantomData<&'p mut ()>,