Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple instances of a levelDB database at the same time

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!

like image 419
ezdazuzena Avatar asked Feb 07 '12 14:02

ezdazuzena


2 Answers

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.

like image 153
Kiril Avatar answered Feb 15 '23 02:02

Kiril


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.

like image 38
databasesymlinker Avatar answered Feb 15 '23 03:02

databasesymlinker