LMDB::Environment
Inherits LMDB::Disposable / Reference / Object
Class for an LMDB database environment. An environment may contain multiple databases, all residing in the same shared-memory map and underlying disk file. A database is a key-value table.
An environment, and its databases, is usually stored in a directory which contains two files:
data.mdb: all records from all databases of this environment.lock.mdb: state of transactions that may be going on in the environment.
To write to the environment a Transaction must be created. One
simultaneous write transaction is allowed, however there is no limit on the
number of read transactions even when a write transaction exists.
Example:
env = LMDB.new "mydbdir"
db = env.database "mydb"
# ...
env.close
Constructors
Create and opens a new Environment under path with given options.
- max_dbs: sets the maximum number of named databases in the environment.
- mode: the POSIX permissions to set on created files.
- map_size: sets the size of the memory map to be allocated for this environment, in bytes. The size should be a multiple of the OS page size. The default is 10485760 bytes. The size of the memory map is also the maximum size of the database.
Instance methods
Opens and returns the main Database associated with self. Each
environment has an unnamed database.
A database needs to be opened (or created) within a transaction. If a
pending transaction for this environment exists, it will be used for this
purpose. Otherwise, a new ReadOnlyTransaction is created.
If a transaction is created specifically, it will be commited before
the Database is returned. Otherwise, no particular action on the
existing pending transaction is performed.
Opens and yields the main Database associated with self. Each
environment has an unnamed database.
A database needs to be opened (or created) within a transaction. If a
pending transaction for this environment exists, it will be used for this
purpose. Otherwise, a new ReadOnlyTransaction is created.
If a transaction is created specifically, it will be commited when the block goes out of scope. Otherwise, no particular action on the existing pending transaction is performed.
Opens and returns the a named Database associated with self. If
the database is newly created, it will not be available in other
transactions until the transaction that is creating the database commits.
If the transaction creating the database aborts, the database is not
created.
A database needs to be opened (or created) within a transaction. If a
pending transaction for this environment exists, it will be used for this
purpose. Otherwise, a new Transaction is created.
If a transaction is created specifically, it will be commited before
the Database is returned. Otherwise, no particular action on the
existing pending transaction is performed.
Opens and yields the a named Database associated with self. If
the database is newly created, it will not be available in other
transactions until the transaction that is creating the database commits.
If the transaction creating the database aborts, the database is not
created.
A database needs to be opened (or created) within a transaction. If a
pending transaction for this environment exists, it will be used for this
purpose. Otherwise, a new Transaction is created.
If a transaction is created specifically, it will be commited before
the Database is returned. Otherwise, no particular action on the
existing pending transaction is performed.
Opens and returns a named Database associated with self. Create
the database if it does not exist.
Opens and yields the a named Database associated with self. Create
the database if it does not exist.
Copy the database to another database, at the given path. This may be used to backup an existing environment.
If compact flag is set to true, compaction is performed while copying:
free pages are omitted and all pages are sequentially renumbered in output.
This option consumes more CPU and runs more slowly than the default.
Set the memory map size to use for self.
The size should be a multiple of the OS page size. This method may be called if no transactions are active.
Create and yields a transaction for use with the environment.
The transaction commits when the block goes out of scope. It is aborted
if an exception is raised or if an explicit call to Transaction#abort is
made.
Create a transaction for use with the environment.