Closed ravensorb closed 6 years ago
Hi @ravensorb,
Exclusive
mode open datafile with no share - only 1 instance of LiteDatabase can exists (file are complete locked). This situation is best option because there is no datafile checks between operations.
Shared
mode support many processes (app domains) open same datafile and you can have multiples LiteDatabase instances across processes. Each operation needs (before execute) check if datafile was changed be another processes. Also, works with FileStream.Lock methods to keep safe in write operations. Maybe in you case you need this case.
Shared
does indeed look promising. Do you have any samples of how you recommend checking for changes if another process updated the data file?
This checking are automatic, made internal. You don't need take care of this. I just comment because this "cost" 1 page read (header page) more than Exclusive mode (also need more Lock control).
the power of that is incredible. 👍 Put the db on high available storage, spin up multiple instances of a webservice, put a loadbalancer in front of it and do some auto scaling magic. From a single node service to a high available multi node auto scaled service.
@mbdavid thanks for the info! This is just what I was looking for....
Hi @ravensorb,
Exclusive
mode open datafile with no share - only 1 instance of LiteDatabase can exists (file are complete locked). This situation is best option because there is no datafile checks between operations.
Shared
mode support many processes (app domains) open same datafile and you can have multiples LiteDatabase instances across processes. Each operation needs (before execute) check if datafile was changed be another processes. Also, works with FileStream.Lock methods to keep safe in write operations. Maybe in you case you need this case.
In current version 5.0.0-beta, there are only 2 modes:
Can you explain what is embedded mode?
Hi @mincasoft,
Exclusive = Embedded
The name changed... and still not official yet. v5 will be released with support for multiple ways to connect to your datafile
Hi @mbdavid,
sorry for re-opening this discussion. I stumbled across this thread, and it seems that Embedded
has been renamed to Direct
.
Is it true that Exclusive
(4.x) = Embedded
(5.0 beta) = Direct
(5.x)?
Thanks
Hi @johannes-schmitt , yes, thats right. Exclusive and Direct (aka Embedded in 5 beta) open file in exclusive-single mode (accept only 1 single process.... but multiple threads!)
I am using LiteDB in shared access mode and I am getting the error : Process cannot be used as it is used by the another process . I am using Connection = shared in connection string . Please help me how can this error be resolved if we are accessing the DB in shared mode . We have 2 .net projects (One is Tests project and other is code ).
Ex: _connectionString = @"Filename=" + filename + ";Password=" + password + ";" + " Connection=Shared";
Can you provide more details on Shared Mode? I am looking to understand if I can have multiple processes (different app domains) access the same database concurrently with LiteDB.