Is there a way to access a levelDB database from several programs? Is there some kind of option to open the dababase as read only?
For now, when opening the same database from to programs I get:
/path/to/dir/with/levelDBdatabase/LOCK: Resource temporarily unavailable
Cheers!
Unfortunately, LevelDB is designed that way and it doesn't allow more than a single instance of the database to be open. All of the options are for a single process, but if you have multiple threads then you can get a snapshot and iterate over it in read-only mode (allowing other threads to read/write to the underlying database at the same time).
Do you want to achieve a specific behavior? If so, let us know what it is and we might be able to help.
I was able to do this in linux by having each process make a directory of its own (e.g. $HOME/.leveldb/myprogram_myPID) and then do:
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 leveldb database and multiple instances of the process can do this at the same time without copying the entire database.
It's probably wise to use a snapshot to access the db after doing this to avoid accidentally writing. Also, remember to delete the new directory when the process ends.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With