Better understanding how to work/balance mnesia's transactional/ACID capabilities
Asked Answered
M

1

6

I am still trying to deeply understand what one can do with Mnesia, and answers to these two questions would greatly help.

1) What happens if one process does an atomic transaction with respect to Record X while some other process does a dirty transaction involving that same record. Are the first processes' ACID properties compromised?

2) Is there a way for the same process to hold a non-dirty (mnesia:transaction/1) read-lock on one table's row, while simultaneously doing a dirty operation on another table?

Masurium answered 8/11, 2012 at 22:5 Comment(0)
I
1

Isolation guarantees are lost in a database environment that allows dirty operations, as Mnesia does. So the answer to question 1) is yes, the well-behaved transactional process is potentially compromised by the concurrent dirty operation, and vice versa - a dirty read for example could return "old" or even freshly deleted data, while the danger inherent in dirty writes is obvious.

In your second scenario, the answer is yes for two reasons: only the data object you're reading is locked AND only your local copy at that! Which is generally a fine and useful thing , and allows even concurrent transactions on other data objects (including other tables of course) to take place.

Erlang Mnesia docs, Chapter 4

Impanel answered 10/11, 2012 at 6:18 Comment(4)
With respect to #2, how? I want the same process to have a trx on one table while doing a dirty trx on a second. The transaction is achieved with a function passed to mnesia:transaction/1, so how do I simultaneously have a dirty trx? If I nest them, the dirty trx inherits the locks of the outer, so the dirty grabs locks?Masurium
The second transaction would be happening in the context of another process node addressing your Mnesia server - running concurrently with your first process...Impanel
I'm specifically asking about doing this in the same process , not two parallel processesMasurium
Self-evidently then: NO. If you're talking about a single node context then you're either within a transactional block or not, afaik. If you can provide an example of the scenario you're worried about that would help.Impanel

© 2022 - 2024 — McMap. All rights reserved.