On 21 Sep 2009, at 17:48, Marnen Laibow-Koser wrote:
> > Frederick Cheung wrote: >> On Sep 21, 4:09�pm, Marnen Laibow-Koser <rails-mailing- >> l...@andreas- >> s.net> wrote: >>> Perhaps it would; I've never used ActiveRecord locking at all, so >>> I'll >>> defer to you here. �However, I tend to think that locking should >>> generally be implemented at the database level, not the application >>> level, which is why I suggested pessimistic here. �Am I missing >>> something? >> >> Well with optimistic locking it is ultimately the database enforcing >> stuff - after all it is the only thing that can. If my memory is >> correct the docs for optimistic locking have a decent explanation of >> how it works. > > If I understand the docs correctly, optimistic locking is *not* > enforced > by the database -- rather, it's up to the app to properly handle > checking and updating the lock_version field. (The value is > *stored* in > the DB, but the DB knows nothing about using it for lock enforcement.) when you do a save with optimistic locking it appends a " where lock_version=expected_version" to the update query, so yes it is up to the app to append that, but the ultimate decision of 'has lock_version changed' will fall to the db. > > Pessimistic locking, by contrast, uses the DB's native locking > mechanisms. This makes it far more airtight than optimistic, I think. > Anyway, optimistic locking seems like reinventing the square wheel. > Why > bother? Because in a case where you expect the lock to almost always succeed it's faster. Fred > >> >> Fred > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > [email protected] > -- > Posted via http://www.ruby-forum.com/. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

