Interface to 'LMDB'

Key-value store, implemented as a wrapper around 'LMDB'; the "lightning memory-mapped database" < https://symas.com/lmdb/>. 'LMDB' is a transactional key value store that uses a memory map for efficient access. This package wraps the entire 'LMDB' interface, providing objects for transactions and cursors.


Project Status: Active – The project has reached a stable, usable state and is being actively developed. Linux Build Status Windows Build status codecov.io

An R interface to LMDB. LMDB is an embedded transactional key-value store and this package provides R mappings to it. It wraps the entire LMDB interface.

Documentation

The package comes with a vignette that describes the main features of the package and of LMDB - see here for a version online. The package also has reference documentation for all methods. It may be useful to refer to the LMDB documentation along side the reference documentation for some details (but hopefully not too much).

Usage

Everything starts by creating an environment (which lives at a point in the file system), and then using methods of the environment object to interact with the database

env <- thor::mdb_env(tempfile())
env
## <mdb_env>
##   Informational:
##     path()
##     flags()
##     info()
##     stat()
##     maxkeysize()
##     maxreaders()
##   Transactions:
##     begin(db = NULL, write = FALSE, sync = NULL, metasync =  ...
##     with_transaction(fun, db = NULL, write = FALSE)
##   Databases:
##     open_database(key = NULL, reversekey = FALSE, dupsort =  ...
##     drop_database(db, delete = TRUE)
##   Management:
##     sync(force = FALSE)
##     copy(path, compact = FALSE)
##     close()
##     destroy()
##     reader_list()
##     reader_check()
##   Helpers:
##     get(key, missing_is_error = TRUE, as_raw = NULL, db = NULL)
##     put(key, value, dupdata = TRUE, overwrite = TRUE, append ...
##     del(key, value = NULL, db = NULL)
##     exists(key, db = NULL)
##     list(starts_with = NULL, as_raw = FALSE, size = NULL, db ...
##     mget(key, as_raw = NULL, db = NULL)
##     mput(key, value, dupdata = TRUE, overwrite = TRUE, appen ...
##     mdel(key, value = NULL, db = NULL)
env$put("hello", "world")
## NULL
env$exists("hello")
## [1] TRUE
env$get("hello") # world
## [1] "world"
env$del("hello")
## [1] TRUE

LMDB is transactional, and thor exposes this like so:

txn <- env$begin(write = TRUE)
txn
## <mdb_txn>
##   Informational:
##     id()
##     stat()
##   Finish:
##     commit()
##     abort(cache = TRUE)
##   Cursors:
##     cursor()
##   Data:
##     get(key, missing_is_error = TRUE, as_proxy = FALSE, as_r ...
##     put(key, value, dupdata = TRUE, overwrite = TRUE, append ...
##     del(key, value = NULL)
##     exists(key)
##     list(starts_with = NULL, as_raw = FALSE, size = NULL)
##     mget(key, as_proxy = FALSE, as_raw = NULL)
##     mput(key, value, dupdata = TRUE, overwrite = TRUE, appen ...
##     mdel(key, value = NULL)
##     replace(key, value, as_raw = NULL)
##     pop(key, as_raw = NULL)
##   Compare:
##     cmp(a, b)
##     dcmp(a, b)

Only one write transaction is active at a given point in time. There can be an unlimited number of read transactions.

txn$put("key", "value")
env$get("key", missing_is_error = FALSE) # NULL - not committed yet
txn$commit()
env$get("key") # new transactions see the value

There is a cursor interface for advanced features (see the vignette). Both keys and values can be strings or binary value, the latter working well with serialize. For efficient use from R, thor extends the LMDB interface to implement bulk reads, writes and deletes (mget, mput and mdel).

Performance

lldb is an extremely fast database, but this package may be much less fast than the underlying library. In order to make the interface safe to use from R, there is quite a bit of error checking, and the length of time involved in calling methods in R6 objects is orders of magnitude slower than performing an action on an lldb database (this is not R6's fault and primarily caused by the cost of S3 method lookup for $ on an object with a class attribute). The vectorised functions will help here (e.g., mget, mput), so prefer these where practical if speed is a concern.

Installation

devtools::install_github("richfitz/thor", upgrade = FALSE)

License

MIT + file LICENSE © Rich FitzJohn. The package contains included code from lmdb which it itself under the "OpenLDAP Public License" - see inst/LICENSE.lmdb for details

News

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("thor")

1.0.1 by Rich FitzJohn, 7 months ago


https://github.com/richfitz/thor


Report a bug at https://github.com/richfitz/thor/issues


Browse source code at https://github.com/cran/thor


Authors: Rich FitzJohn [aut, cre] , Howard Chu [cph] , Symas Corporation [cph] , Martin Hedenfalk [cph] , The OpenLDAP Foundation [cph]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports R6, storr

Suggests ids, knitr, rmarkdown, testthat


See at CRAN