1

I'm looking at using BaseX as a more flexible database.

How does it handle database concurrency? How does it work in a web app scenario, where two different users could update the same data and effectively get a "dirty read"?

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
Martin Thompson
  • 3,415
  • 10
  • 38
  • 62

1 Answers1

3

How does it work in a web app scenario, where two different users could update the same data and effectively get a "dirty read"?

Be sure: Transactions are isolated from each other, so that updated anomalies cannot occur.

How does it handle database concurrency?

Have a look at the BaseX wiki page about transaction management, where the approach is described in-detail. Disclaimer: I implemented the newer database locking for BaseX during my thesis work, so I'm involved in the project.

BaseX applies several mechanics to prevent colliding transactions. The old process locking (which still can be enabled using the GLOBALLOCK option) simply denies multiple queries within a process, parallel execution could be achieved throughout multiple database instances, while basic isolation was achieved through per-database file system locks (without any guarantees regarding deadlocks, ...).

The newer database locking isolates parallel transactions by applying two phase locking on database level. Thus, two queries accessing multiple databases do run in parallel given they access different databases, otherwise one of them will have to wait (but they do not run at the same time, for sure). A drawback is that as we want to support deadlock free execution, we went for strict two phase locking, which fetches all database locks before execution of the query, but suffers from a penalty as determining which databases will be accessed is rather difficult in a dynamic language as XQuery, often failing with global locks on all databases.

For the future (given time allows, and no schedule is set) some optimizations are in queue, especially relaxing the strictness for two phase locking and the optimistic concurrency control I already evaluated in my thesis that would bring large gains in parallel execution, especially for web application scenarios.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
  • Thanks. So given a scenario where some data is read on 2 separate browsers/ users at the same time - then User 1 updates data in the database on a record - then user 2 updates the same data .. won't User 1's data get overwritten? Is this something that has to be factored in manually? – Martin Thompson Aug 11 '15 at 20:04
  • One query (page request) is one transaction, each transaction is atomic. If a page gets fetched, another users changes something (not reflected in the page yet) and then the changes are written back to the database system, the other user's changes will be overwritten (if you don't apply any further safeguards). This is pretty much the same as with all other database systems when you haven't got transactions spanning multiple page queries. – Jens Erat Aug 11 '15 at 20:17
  • thanks . FYI If you do this in SQL server and you have a timestamp field in a table it will reject the second change if the timestamp doesn't match. – Martin Thompson Aug 11 '15 at 23:29