PyDbLite icon indicating copy to clipboard operation
PyDbLite copied to clipboard

Concurrency control feature is totally missing

Open Isshwarya opened this issue 8 years ago • 3 comments

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 avatar Jan 19 '17 10:01 Isshwarya

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 avatar Jan 19 '17 12:01 Isshwarya

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.

Isshwarya avatar Jan 24 '17 11:01 Isshwarya

Hi

Feel free to submit a PR with updated docs!

bendikro avatar Feb 26 '17 11:02 bendikro