new#

Open an environment: the file or directory $path, with options.

Synopsis#

my $env = Peta::LMDB::Env->new($path, %options);

Options#

  • flags - MDB_* environment flags OR’d together, chiefly MDB_NOSUBDIR ($path is the data file itself, with the lock file $path-lock beside it; without it $path is a directory holding data.mdb and lock.mdb), MDB_RDONLY (read only), MDB_NOSYNC, MDB_NOMETASYNC, MDB_MAPASYNC (sync less, risking the last commits on a crash), MDB_NOTLS, MDB_NORDAHEAD, MDB_NOMEMINIT, MDB_WRITEMAP.

  • mode - the permission of files it creates (default 0644).

  • mapsize - the memory map’s size in bytes, the most data the environment can hold (LMDB’s default is 1 MiB).

  • maxdbs - how many named databases open_db may open.

  • maxreaders - how many read transactions may be live at once (default 126).

What you get back#

A Peta::LMDB::Env object. Failures croak: an LMDB error with a Peta::LMDB::Error, an unknown option with Peta::LMDB::Env->new: unknown option 'NAME', a file already open in the process with ... is already open in this process.

Examples#

my $env = Peta::LMDB::Env->new('cache.lmdb', flags => MDB_NOSUBDIR);

A directory environment with named databases:

mkdir 'app.db';
my $env = Peta::LMDB::Env->new('app.db', maxdbs => 8, mapsize => 1 << 32);

Edge cases#

  • The directory form needs the directory to exist; a file it creates.

  • A second environment on a file already open in the process croaks rather than open it: LMDB’s locks would break under two.

See also#

  • begin - starts a transaction

  • close - closes the environment now