sidnt / lmdz

0 stars 0 forks source link

lmdb environment #2

Open sidnt opened 4 years ago

sidnt commented 4 years ago

To do anything with LMDB you first have to open an environment. The environment provides the necessary data structures to access a single database-file, so there is always a 1:1 mapping of database-files you access and environments you have opened. ref

an lmdb environment is like the memory area, which an lmdb instance, ie, an lmdb-process operates on. an lmdb environment is like a data structure, which is in complete handle of an lmdb-process. lmdb-environment is like the root/starting handle of the process. it's the first contact, that an lmdb-process, establishes with an lmdb-environment file.

An Env owns a physical on-disk storage file.

Create an LMDB environment handle.

the creation of an lmdb-environment can be parameterized with constraints to be followed in that lmdb-process' behaviour. these are like the top level constraints, that remain consistent, during the entire life of a process, fundamentally altering its behaviour.

For example, one of the constraints is,

.setMapSize(10_485_760)

Putting a hard upper limit on the size of the environment, or iow, for the size of the on disk storage file.

So you instantiate the parameter-values for the environment you want, and then, open the environment on an on disk-file.

There should only ever be one environment open per database-file per process. Usually there is no good reason to close an environment once it’s open, so you can just leave it upon until the process ends. ref

The same path, ie, the same environment, can be concurrently opened and used in a different lmdb-process.

So, can an lmdb-environment become a memory hub for inter-process communication?

but do not open the same path twice in the same process at the same time.

Ideally, open a path, only once per process.

sidnt commented 4 years ago

the next concept comes up, of databases. It's said that

One Env can store many different databases

but what details does that translate to?

Interestingly, an environment creation needs to know at the outset, how many databases we might actually use. Which is a bit weird of an api. How can I calculate beforehand how many databases i might need, and that, without actually knowing what actually is a database abstraction and whether it can be eliminated, so that I can serve all my needs in only one database, and so i'm free of this abstraction.

sidnt commented 4 years ago

before using lmdb in scala, we should understand the abstractions it offers and what could that mean for us, while translating the lmdbjava api to zio.