Multiple instances of a DB level database at the same time.

Is there a way to access the levelDB database from multiple programs? Is there any way to open dababase for read only?

Currently, when opening the same database from programs, I get:

/path/to/dir/with/levelDBdatabase/LOCK: Resource temporarily unavailable 

Hurrah!

+6
source share
3 answers

Unfortunately, LevelDB is designed in this way, and it does not allow you to open more than one database instance. All parameters are intended for one process, but if you have several threads, you can get a snapshot and iterate over it in read-only mode (allowing other threads to read and write to the base database at the same time).

Do you want to achieve a certain behavior? If so, let us know what it is and we can help.

+10
source

I was able to do this on Linux if each process created its own directory (for example, $ HOME / .leveldb / myprogram_myPID), and then run:

 ln -s -t $HOME/.leveldb/myprogram_myPID /path/to/dir/with/levelDBdatabase/* rm $HOME/.leveldb/myprogram_myPID/LOCK touch $HOME/.leveldb/myprogram_myPID/LOCK 

Then $ HOME / .leveldb / myprogram_myPID can be used as a read-only database, and multiple process instances can do this simultaneously without copying the entire database.

It might be wise to use a snapshot to access the db after that, to avoid accidentally writing. Also, be sure to delete the new directory when the process is complete.

+5
source

If you only need read- only access , each process can create a copy of the LevelDB folder :

cp -r /path/to/dir/with/levelDBdatabase /path/to/dir/with/levelDBdatabase-copy1

Then, instead of using the original levelDBdatabase use levelDBdatabase-copy1 .
When the program is completed, the copy can be deleted safely.

+3
source

Source: https://habr.com/ru/post/907852/


All Articles