PierreQuentel / PyDbLite

A fast, pure Python in-memory database engine
BSD 3-Clause "New" or "Revised" License
104 stars 13 forks source link

Concurrency control feature is totally missing #2

Open Isshwarya opened 7 years ago

Isshwarya commented 7 years ago

The doc says:

another internal field called version is also managed by the database engine. It is a integer which is set to 0 when the record is created, then incremented by 1 each time the record is updated. This is used to detect concurrency control, for instance in a web application where 2 users select the same record and want to update it at the same time

But I don't see it happening. My below code creates a table with one row. This has a column 'counter' which is initially set to 0. Then i create 100 threads to increment the counter column of that row. In the final result, I expect the counter to be set to 100 for that column whereas its not.

Attaching the script. test_pydbliteerr.txt

Isshwarya commented 7 years ago

I think adding a simple lock (threading.lock) before doing the final dictionary update would solve things. At that point, it can check the version and then update.

Isshwarya commented 7 years ago

My application doesn't need this feature, as different threads update different rows. Because there is no lock, the whole table is not locked and so threads could update different portions of dictionary independently. It ensures high speed operations. so lets not make any changes in the code for this ticket.

But doc could be updated to provide these details as currently it gives an impression that the db operations are threadsafe.

bendikro commented 7 years ago

Hi

Feel free to submit a PR with updated docs!