Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

thorough guide to Locks/Transactions/Isolation Levels in Rails [closed]

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

  • http://guides.rubyonrails.org/active_record_querying.html#locking-records-for-update
  • http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html
  • http://api.rubyonrails.org/classes/ActiveRecord/Locking/Pessimistic.html
  • http://api.rubyonrails.org/classes/ActiveRecord/Transactions.html
  • https://github.com/rails/rails/commit/392eeecc11a291e406db927a18b75f41b2658253 ("Support for specifying transaction isolation level" commit -> Rails 4.0)
  • http://railscasts.com/episodes/59-optimistic-locking-revised
like image 303
odigity Avatar asked Sep 25 '13 17:09

odigity


People also ask

What are the four transaction isolation levels?

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 rails?

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.

What is isolation level in transaction management?

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.


2 Answers

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!

like image 113
Marc Avatar answered Nov 09 '22 22:11

Marc


I found Differences between transactions and locking on Makandropedia a pretty useful starting point to learn the difference between transactions and locks.

like image 33
lulalala Avatar answered Nov 09 '22 23:11

lulalala