Is there a good tutorial/guide/blog post/book chapter/screencast/etc that attempts to comprehensively cover everything having to do with locks, transactions, and isolation levels in ActiveRecord? (preferably relevant to Rails 4.0)
There's a brief section in the guides, and of course some API docs, but it's a really important and (for me) hard-to-understand domain, and it's my first time trying to take data integrity seriously in my Rails app. I'd like to get a good understanding so I can do it properly.
List of Known Resources
InnoDB offers all four transaction isolation levels described by the SQL:1992 standard: READ UNCOMMITTED , READ COMMITTED , REPEATABLE READ , and SERIALIZABLE .
What is pessimistic locking? When one user is editing a record and we maintain an exclusive lock on that record, another user is prevented from modifying this record until the lock is released or the transaction is completed. This explicit locking is known as a pessimistic lock.
Transaction isolation levels are a measure of the extent to which transaction isolation succeeds. In particular, transaction isolation levels are defined by the presence or absence of the following phenomena: Dirty Reads A dirty read occurs when a transaction reads data that has not yet been committed.
I would check out Chapter 5 of The Rails 3 Way for now, particularly Section 5.5 on Database Locking. I would also look at the ActiveRecord::Locking source, ActiveRecord::Transactions source, and the transaction_isolation test case as the code is very readable and if you're going to need some down in the weeds answers, it's there in the code!
I found Differences between transactions and locking on Makandropedia a pretty useful starting point to learn the difference between transactions and locks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With