Database / Mnesia intermediate to advanced Interview questions
What is a nested Mnesia transaction and how does it behave differently from a top-level one?
Calling mnesia:transaction/1 from inside code that's already running within another
transaction creates a nested transaction. Rather than being a fully independent transaction, it shares
the outer transaction's locks and only really commits when the outermost transaction itself commits — an
abort of the inner one aborts the whole outer transaction too.
mnesia:transaction(fun() -> mnesia:write(#a{id = 1}), mnesia:transaction(fun() -> %% nested mnesia:write(#b{id = 1}) end), mnesia:write(#c{id = 1}) end).
This differs from what "nested transaction" might suggest in some other databases (an independently committable sub-unit) — in Mnesia, there's really just one logical transaction underneath, and nesting mainly matters for code organization (letting a helper function wrap its own operations in a transaction without caring whether it's already inside one) rather than providing partial-commit semantics.
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...
