mbdavid / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.52k stars 1.24k forks source link

Explain Shared Mode? #978

Closed ravensorb closed 6 years ago

ravensorb commented 6 years ago

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.

mbdavid commented 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.

ravensorb commented 6 years ago

Shared does indeed look promising. Do you have any samples of how you recommend checking for changes if another process updated the data file?

mbdavid commented 6 years ago

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).

PascalSenn commented 6 years ago

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.

ravensorb commented 6 years ago

@mbdavid thanks for the info! This is just what I was looking for....

ghost commented 4 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.

In current version 5.0.0-beta, there are only 2 modes:

Can you explain what is embedded mode?

mbdavid commented 4 years ago

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

johannes-schmitt commented 3 years ago

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

mbdavid commented 3 years ago

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!)

ayushigupta1inabb commented 2 years ago

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";