Database / Mnesia basics Interview questions
What is the difference between mnesia:read/1 and mnesia:wread/1?
Both fetch a record by key inside a transaction, but they take different lock types up front.
mnesia:read/1 takes a read lock, which is fine for a plain lookup, but if you intend to
immediately write back an updated version of that same record, a read lock can force an extra lock upgrade
step. mnesia:wread/1 takes a write lock right away instead.
mnesia:transaction(fun() -> [P] = mnesia:wread({person, 1}), mnesia:write(P#person{age = P#person.age + 1}) end).
Using wread/1 when you know you're about to write signals your intent up front, which can
reduce the chance of a deadlock between two transactions that both read-then-write the same record
concurrently — each avoids the read-lock-to-write-lock upgrade dance that could otherwise let two
transactions each hold a read lock and wait on each other for the write lock.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
