PyDbLite
PyDbLite copied to clipboard
Concurrency control feature is totally missing
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
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.
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.
Hi
Feel free to submit a PR with updated docs!